source: node_modules/@swagger-api/apidom-core/es/transformers/from.mjs

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 16 months ago

Initial commit

  • Property mode set to 100644
File size: 893 bytes
Line 
1import { has } from 'ramda';
2import { isPlainObject, isString } from 'ramda-adjunct';
3import defaultNamespaceInstance from "../namespace.mjs";
4/**
5 * Transforms data to an Element from a particular namespace.
6 *
7 * The name of the function was originally `from`,
8 * but it was renamed to `fromFn` to avoid issues with Parcel.js:
9 *
10 * - https://github.com/parcel-bundler/parcel/issues/9473
11 * - https://github.com/swagger-api/swagger-ui/issues/9466#issuecomment-1881053410
12 */
13const fromFn = (data, namespace = defaultNamespaceInstance) => {
14 if (isString(data)) {
15 // JSON serialized refract
16 try {
17 return namespace.fromRefract(JSON.parse(data));
18 } catch {
19 // noop
20 }
21 }
22 if (isPlainObject(data) && has('element', data)) {
23 // refract javascript structure
24 return namespace.fromRefract(data);
25 }
26 return namespace.toElement(data);
27};
28export default fromFn;
Note: See TracBrowser for help on using the repository browser.