source: node_modules/@swagger-api/apidom-core/es/refractor/index.mjs

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

Initial commit

  • Property mode set to 100644
File size: 888 bytes
Line 
1import { dispatchPlugins } from "./plugins/utils/index.mjs";
2import { getNodeType } from "../traversal/visitor.mjs";
3import createToolbox from "./toolbox.mjs";
4const refract = (value, {
5 Type,
6 plugins = []
7}) => {
8 /**
9 * This is where values gets refracted into generic ApiDOM.
10 * We don't allow consumers to hook into this translation.
11 * Though we allow consumers to define their onw plugins on already transformed ApiDOM.
12 */
13 const element = new Type(value);
14
15 /**
16 * Run plugins only when necessary.
17 * Running plugins visitors means extra single traversal === performance hit.
18 */
19 return dispatchPlugins(element, plugins, {
20 toolboxCreator: createToolbox,
21 visitorOptions: {
22 nodeTypeGetter: getNodeType
23 }
24 });
25};
26export const createRefractor = Type => (value, options = {}) => refract(value, {
27 ...options,
28 Type
29});
30export default refract;
Note: See TracBrowser for help on using the repository browser.