@speclynx/apidom-core 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/package.json +6 -7
  3. package/src/fields/fixed-fields.cjs +47 -0
  4. package/src/fields/fixed-fields.mjs +43 -0
  5. package/src/fields/fixed-fields.ts +61 -0
  6. package/src/fields/index.cjs +8 -0
  7. package/src/fields/index.mjs +1 -0
  8. package/src/fields/index.ts +2 -0
  9. package/src/identity/errors/ElementIdentityError.cjs +22 -0
  10. package/src/identity/errors/ElementIdentityError.mjs +19 -0
  11. package/src/identity/errors/ElementIdentityError.ts +26 -0
  12. package/src/identity/index.cjs +64 -0
  13. package/src/identity/index.mjs +58 -0
  14. package/src/identity/index.ts +64 -0
  15. package/src/index.cjs +48 -0
  16. package/src/index.mjs +41 -0
  17. package/src/index.ts +81 -0
  18. package/src/media-types.cjs +21 -0
  19. package/src/media-types.mjs +18 -0
  20. package/src/media-types.ts +24 -0
  21. package/src/merge/deepmerge.cjs +165 -0
  22. package/src/merge/deepmerge.mjs +149 -0
  23. package/src/merge/deepmerge.ts +274 -0
  24. package/src/merge/merge-left.cjs +16 -0
  25. package/src/merge/merge-left.mjs +11 -0
  26. package/src/merge/merge-left.ts +14 -0
  27. package/src/merge/merge-right.cjs +35 -0
  28. package/src/merge/merge-right.mjs +29 -0
  29. package/src/merge/merge-right.ts +42 -0
  30. package/src/namespace.cjs +10 -0
  31. package/src/namespace.mjs +7 -0
  32. package/src/namespace.ts +8 -0
  33. package/src/refractor/plugins/dispatcher/index.cjs +64 -0
  34. package/src/refractor/plugins/dispatcher/index.mjs +54 -0
  35. package/src/refractor/plugins/dispatcher/index.ts +102 -0
  36. package/src/refractor/plugins/element-identity.cjs +31 -0
  37. package/src/refractor/plugins/element-identity.mjs +26 -0
  38. package/src/refractor/plugins/element-identity.ts +31 -0
  39. package/src/refractor/plugins/semantic-element-identity.cjs +33 -0
  40. package/src/refractor/plugins/semantic-element-identity.mjs +29 -0
  41. package/src/refractor/plugins/semantic-element-identity.ts +32 -0
  42. package/src/refractor/toolbox.cjs +47 -0
  43. package/src/refractor/toolbox.mjs +41 -0
  44. package/src/refractor/toolbox.ts +88 -0
  45. package/src/specification.cjs +63 -0
  46. package/src/specification.mjs +59 -0
  47. package/src/specification.ts +68 -0
  48. package/src/transcluder/Transcluder.cjs +111 -0
  49. package/src/transcluder/Transcluder.mjs +107 -0
  50. package/src/transcluder/Transcluder.ts +147 -0
  51. package/src/transcluder/index.cjs +19 -0
  52. package/src/transcluder/index.mjs +13 -0
  53. package/src/transcluder/index.ts +15 -0
  54. package/src/transformers/dehydrate.cjs +15 -0
  55. package/src/transformers/dehydrate.mjs +10 -0
  56. package/src/transformers/dehydrate.ts +14 -0
  57. package/src/transformers/from.cjs +34 -0
  58. package/src/transformers/from.mjs +29 -0
  59. package/src/transformers/from.ts +34 -0
  60. package/src/transformers/serializers/json.cjs +75 -0
  61. package/src/transformers/serializers/json.mjs +70 -0
  62. package/src/transformers/serializers/json.ts +107 -0
  63. package/src/transformers/serializers/value.cjs +50 -0
  64. package/src/transformers/serializers/value.mjs +47 -0
  65. package/src/transformers/serializers/value.ts +70 -0
  66. package/src/transformers/serializers/yaml-1-2.cjs +142 -0
  67. package/src/transformers/serializers/yaml-1-2.mjs +137 -0
  68. package/src/transformers/serializers/yaml-1-2.ts +205 -0
  69. package/src/transformers/sexprs.cjs +31 -0
  70. package/src/transformers/sexprs.mjs +28 -0
  71. package/src/transformers/sexprs.ts +30 -0
  72. package/src/transformers/to-string.cjs +16 -0
  73. package/src/transformers/to-string.mjs +11 -0
  74. package/src/transformers/to-string.ts +15 -0
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.default = void 0;
6
+ var _yaml = require("yaml");
7
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
8
+ var _value = _interopRequireDefault(require("./value.cjs"));
9
+ const getStyle = element => {
10
+ return element.style?.yaml ?? {};
11
+ };
12
+
13
+ // map our scalarStyle strings to YAML library Scalar.Type constants
14
+ const scalarStyleMap = {
15
+ Plain: _yaml.Scalar.PLAIN,
16
+ SingleQuoted: _yaml.Scalar.QUOTE_SINGLE,
17
+ DoubleQuoted: _yaml.Scalar.QUOTE_DOUBLE,
18
+ Literal: _yaml.Scalar.BLOCK_LITERAL,
19
+ Folded: _yaml.Scalar.BLOCK_FOLDED
20
+ };
21
+
22
+ // the YAML library prefixes comments with '#' only (no space), so we add ' ' to get '# comment'
23
+ const applyComments = (node, style) => {
24
+ if (style.comment) node.comment = ` ${style.comment}`;
25
+ if (style.commentBefore) node.commentBefore = ` ${style.commentBefore}`;
26
+ };
27
+
28
+ /**
29
+ * @public
30
+ */
31
+
32
+ /**
33
+ * Converts an ApiDOM element tree to YAML library AST nodes,
34
+ * preserving style information from `element.style.yaml`.
35
+ */
36
+ const toYAMLNode = (element, visited) => {
37
+ if (!(0, _apidomDatamodel.isElement)(element)) return element;
38
+
39
+ // cycle detection
40
+ if (visited.has(element)) return undefined;
41
+ visited.add(element);
42
+ const style = getStyle(element);
43
+ if ((0, _apidomDatamodel.isObjectElement)(element)) {
44
+ const map = new _yaml.YAMLMap();
45
+ map.flow = style.styleGroup === 'Flow';
46
+ applyComments(map, style);
47
+ element.forEach((value, key, member) => {
48
+ const memberStyle = (0, _apidomDatamodel.isMemberElement)(member) ? getStyle(member) : {};
49
+ const keyNode = toYAMLNode(key, visited);
50
+ const valueNode = toYAMLNode(value, visited);
51
+ const pair = new _yaml.Pair(keyNode, valueNode);
52
+ if (memberStyle.commentBefore && (0, _yaml.isNode)(keyNode)) {
53
+ keyNode.commentBefore = ` ${memberStyle.commentBefore}`;
54
+ }
55
+ if (memberStyle.comment && (0, _yaml.isNode)(valueNode)) {
56
+ valueNode.comment = ` ${memberStyle.comment}`;
57
+ }
58
+ map.items.push(pair);
59
+ });
60
+ return map;
61
+ }
62
+ if ((0, _apidomDatamodel.isArrayElement)(element)) {
63
+ const seq = new _yaml.YAMLSeq();
64
+ seq.flow = style.styleGroup === 'Flow';
65
+ applyComments(seq, style);
66
+ element.forEach(item => {
67
+ seq.items.push(toYAMLNode(item, visited));
68
+ });
69
+ return seq;
70
+ }
71
+ if ((0, _apidomDatamodel.isRefElement)(element)) {
72
+ return new _yaml.Scalar(String((0, _value.default)(element)));
73
+ }
74
+ if ((0, _apidomDatamodel.isLinkElement)(element)) {
75
+ return new _yaml.Scalar((0, _apidomDatamodel.isStringElement)(element.href) ? (0, _value.default)(element.href) : '');
76
+ }
77
+
78
+ // scalar element (string, number, boolean, null)
79
+ const scalarType = style.scalarStyle ? scalarStyleMap[style.scalarStyle] : undefined;
80
+ const scalar = new _yaml.Scalar((0, _value.default)(element));
81
+ if (scalarType) {
82
+ scalar.type = scalarType;
83
+ }
84
+
85
+ // use rawContent to infer YAML library format hints for plain scalars that resolved to numbers;
86
+ // only applies to Plain style — quoted scalars are always strings in YAML.
87
+ // note: the YAML library may normalize the representation (e.g. 1.0e10 -> 1e+10, 0x1A -> 0x1a)
88
+ // while preserving the format category (exponential, hex, octal, fractional digits)
89
+ if (style.rawContent && style.scalarStyle === 'Plain' && typeof scalar.value === 'number') {
90
+ if (/[eE]/.test(style.rawContent)) {
91
+ scalar.format = 'EXP';
92
+ } else if (/^0x/i.test(style.rawContent)) {
93
+ scalar.format = 'HEX';
94
+ } else if (/^0o/i.test(style.rawContent)) {
95
+ scalar.format = 'OCT';
96
+ }
97
+ const dotMatch = style.rawContent.match(/\.(\d+)/);
98
+ if (dotMatch) {
99
+ scalar.minFractionDigits = dotMatch[1].length;
100
+ }
101
+ }
102
+ applyComments(scalar, style);
103
+ return scalar;
104
+ };
105
+
106
+ /**
107
+ * @public
108
+ */
109
+ const serializer = (element, {
110
+ directive = false,
111
+ preserveStyle = false,
112
+ aliasDuplicateObjects = false,
113
+ ...options
114
+ } = {}) => {
115
+ const allOptions = {
116
+ aliasDuplicateObjects,
117
+ ...options
118
+ };
119
+ if (preserveStyle) {
120
+ const style = getStyle(element);
121
+ if (options.indent === undefined && typeof style.indent === 'number') {
122
+ allOptions.indent = style.indent;
123
+ }
124
+ if (typeof style.flowCollectionPadding === 'boolean') {
125
+ allOptions.flowCollectionPadding = style.flowCollectionPadding;
126
+ }
127
+ const rootNode = toYAMLNode(element, new WeakSet());
128
+ const doc = new _yaml.Document(undefined, allOptions);
129
+ doc.contents = rootNode;
130
+ if (directive) {
131
+ doc.directives.yaml.explicit = true;
132
+ }
133
+ return doc.toString(allOptions);
134
+ }
135
+ if (directive) {
136
+ const doc = new _yaml.Document((0, _value.default)(element), allOptions);
137
+ doc.directives.yaml.explicit = true;
138
+ return doc.toString(allOptions);
139
+ }
140
+ return (0, _yaml.stringify)((0, _value.default)(element), allOptions);
141
+ };
142
+ var _default = exports.default = serializer;
@@ -0,0 +1,137 @@
1
+ import { Document, stringify, isNode, Scalar, YAMLMap, YAMLSeq, Pair } from 'yaml';
2
+ import { isElement, isObjectElement, isArrayElement, isRefElement, isLinkElement, isStringElement, isMemberElement } from '@speclynx/apidom-datamodel';
3
+ import toValue from "./value.mjs";
4
+ const getStyle = element => {
5
+ return element.style?.yaml ?? {};
6
+ };
7
+
8
+ // map our scalarStyle strings to YAML library Scalar.Type constants
9
+ const scalarStyleMap = {
10
+ Plain: Scalar.PLAIN,
11
+ SingleQuoted: Scalar.QUOTE_SINGLE,
12
+ DoubleQuoted: Scalar.QUOTE_DOUBLE,
13
+ Literal: Scalar.BLOCK_LITERAL,
14
+ Folded: Scalar.BLOCK_FOLDED
15
+ };
16
+
17
+ // the YAML library prefixes comments with '#' only (no space), so we add ' ' to get '# comment'
18
+ const applyComments = (node, style) => {
19
+ if (style.comment) node.comment = ` ${style.comment}`;
20
+ if (style.commentBefore) node.commentBefore = ` ${style.commentBefore}`;
21
+ };
22
+
23
+ /**
24
+ * @public
25
+ */
26
+
27
+ /**
28
+ * Converts an ApiDOM element tree to YAML library AST nodes,
29
+ * preserving style information from `element.style.yaml`.
30
+ */
31
+ const toYAMLNode = (element, visited) => {
32
+ if (!isElement(element)) return element;
33
+
34
+ // cycle detection
35
+ if (visited.has(element)) return undefined;
36
+ visited.add(element);
37
+ const style = getStyle(element);
38
+ if (isObjectElement(element)) {
39
+ const map = new YAMLMap();
40
+ map.flow = style.styleGroup === 'Flow';
41
+ applyComments(map, style);
42
+ element.forEach((value, key, member) => {
43
+ const memberStyle = isMemberElement(member) ? getStyle(member) : {};
44
+ const keyNode = toYAMLNode(key, visited);
45
+ const valueNode = toYAMLNode(value, visited);
46
+ const pair = new Pair(keyNode, valueNode);
47
+ if (memberStyle.commentBefore && isNode(keyNode)) {
48
+ keyNode.commentBefore = ` ${memberStyle.commentBefore}`;
49
+ }
50
+ if (memberStyle.comment && isNode(valueNode)) {
51
+ valueNode.comment = ` ${memberStyle.comment}`;
52
+ }
53
+ map.items.push(pair);
54
+ });
55
+ return map;
56
+ }
57
+ if (isArrayElement(element)) {
58
+ const seq = new YAMLSeq();
59
+ seq.flow = style.styleGroup === 'Flow';
60
+ applyComments(seq, style);
61
+ element.forEach(item => {
62
+ seq.items.push(toYAMLNode(item, visited));
63
+ });
64
+ return seq;
65
+ }
66
+ if (isRefElement(element)) {
67
+ return new Scalar(String(toValue(element)));
68
+ }
69
+ if (isLinkElement(element)) {
70
+ return new Scalar(isStringElement(element.href) ? toValue(element.href) : '');
71
+ }
72
+
73
+ // scalar element (string, number, boolean, null)
74
+ const scalarType = style.scalarStyle ? scalarStyleMap[style.scalarStyle] : undefined;
75
+ const scalar = new Scalar(toValue(element));
76
+ if (scalarType) {
77
+ scalar.type = scalarType;
78
+ }
79
+
80
+ // use rawContent to infer YAML library format hints for plain scalars that resolved to numbers;
81
+ // only applies to Plain style — quoted scalars are always strings in YAML.
82
+ // note: the YAML library may normalize the representation (e.g. 1.0e10 -> 1e+10, 0x1A -> 0x1a)
83
+ // while preserving the format category (exponential, hex, octal, fractional digits)
84
+ if (style.rawContent && style.scalarStyle === 'Plain' && typeof scalar.value === 'number') {
85
+ if (/[eE]/.test(style.rawContent)) {
86
+ scalar.format = 'EXP';
87
+ } else if (/^0x/i.test(style.rawContent)) {
88
+ scalar.format = 'HEX';
89
+ } else if (/^0o/i.test(style.rawContent)) {
90
+ scalar.format = 'OCT';
91
+ }
92
+ const dotMatch = style.rawContent.match(/\.(\d+)/);
93
+ if (dotMatch) {
94
+ scalar.minFractionDigits = dotMatch[1].length;
95
+ }
96
+ }
97
+ applyComments(scalar, style);
98
+ return scalar;
99
+ };
100
+
101
+ /**
102
+ * @public
103
+ */
104
+ const serializer = (element, {
105
+ directive = false,
106
+ preserveStyle = false,
107
+ aliasDuplicateObjects = false,
108
+ ...options
109
+ } = {}) => {
110
+ const allOptions = {
111
+ aliasDuplicateObjects,
112
+ ...options
113
+ };
114
+ if (preserveStyle) {
115
+ const style = getStyle(element);
116
+ if (options.indent === undefined && typeof style.indent === 'number') {
117
+ allOptions.indent = style.indent;
118
+ }
119
+ if (typeof style.flowCollectionPadding === 'boolean') {
120
+ allOptions.flowCollectionPadding = style.flowCollectionPadding;
121
+ }
122
+ const rootNode = toYAMLNode(element, new WeakSet());
123
+ const doc = new Document(undefined, allOptions);
124
+ doc.contents = rootNode;
125
+ if (directive) {
126
+ doc.directives.yaml.explicit = true;
127
+ }
128
+ return doc.toString(allOptions);
129
+ }
130
+ if (directive) {
131
+ const doc = new Document(toValue(element), allOptions);
132
+ doc.directives.yaml.explicit = true;
133
+ return doc.toString(allOptions);
134
+ }
135
+ return stringify(toValue(element), allOptions);
136
+ };
137
+ export default serializer;
@@ -0,0 +1,205 @@
1
+ import {
2
+ Document,
3
+ stringify,
4
+ isNode,
5
+ Scalar,
6
+ YAMLMap,
7
+ YAMLSeq,
8
+ Pair,
9
+ type Node as YAMLNode,
10
+ type CreateNodeOptions,
11
+ type DocumentOptions,
12
+ type SchemaOptions,
13
+ type ToStringOptions,
14
+ } from 'yaml';
15
+ import {
16
+ Element,
17
+ isElement,
18
+ isObjectElement,
19
+ isArrayElement,
20
+ isRefElement,
21
+ isLinkElement,
22
+ isStringElement,
23
+ isMemberElement,
24
+ } from '@speclynx/apidom-datamodel';
25
+
26
+ import toValue from './value.ts';
27
+
28
+ interface YAMLElementStyle {
29
+ scalarStyle?: string;
30
+ styleGroup?: string;
31
+ rawContent?: string;
32
+ indent?: number;
33
+ flowCollectionPadding?: boolean;
34
+ comment?: string;
35
+ commentBefore?: string;
36
+ }
37
+
38
+ const getStyle = (element: Element): YAMLElementStyle => {
39
+ return (element.style?.yaml ?? {}) as YAMLElementStyle;
40
+ };
41
+
42
+ // map our scalarStyle strings to YAML library Scalar.Type constants
43
+ const scalarStyleMap: Record<string, Scalar.Type> = {
44
+ Plain: Scalar.PLAIN,
45
+ SingleQuoted: Scalar.QUOTE_SINGLE,
46
+ DoubleQuoted: Scalar.QUOTE_DOUBLE,
47
+ Literal: Scalar.BLOCK_LITERAL,
48
+ Folded: Scalar.BLOCK_FOLDED,
49
+ };
50
+
51
+ // the YAML library prefixes comments with '#' only (no space), so we add ' ' to get '# comment'
52
+ const applyComments = (node: YAMLNode, style: YAMLElementStyle): void => {
53
+ if (style.comment) node.comment = ` ${style.comment}`;
54
+ if (style.commentBefore) node.commentBefore = ` ${style.commentBefore}`;
55
+ };
56
+
57
+ /**
58
+ * @public
59
+ */
60
+ export interface YAMLSerializerOptions
61
+ extends
62
+ DocumentOptions,
63
+ Pick<CreateNodeOptions, 'aliasDuplicateObjects'>,
64
+ Pick<SchemaOptions, 'sortMapEntries'>,
65
+ ToStringOptions {
66
+ /** Include %YAML directive and document marker */
67
+ directive?: boolean;
68
+ /** Preserve original formatting styles from `element.style.yaml` */
69
+ preserveStyle?: boolean;
70
+ /** Padding inside flow collections (e.g. `{ a: 1 }` vs `{a: 1}`) */
71
+ flowCollectionPadding?: boolean;
72
+ }
73
+
74
+ /**
75
+ * Converts an ApiDOM element tree to YAML library AST nodes,
76
+ * preserving style information from `element.style.yaml`.
77
+ */
78
+ const toYAMLNode = (element: unknown, visited: WeakSet<object>): unknown => {
79
+ if (!isElement(element)) return element;
80
+
81
+ // cycle detection
82
+ if (visited.has(element as object)) return undefined;
83
+ visited.add(element as object);
84
+
85
+ const style = getStyle(element);
86
+
87
+ if (isObjectElement(element)) {
88
+ const map = new YAMLMap();
89
+ map.flow = style.styleGroup === 'Flow';
90
+ applyComments(map, style);
91
+
92
+ element.forEach((value, key, member) => {
93
+ const memberStyle = isMemberElement(member) ? getStyle(member) : {};
94
+ const keyNode = toYAMLNode(key, visited);
95
+ const valueNode = toYAMLNode(value, visited);
96
+ const pair = new Pair(keyNode, valueNode);
97
+
98
+ if (memberStyle.commentBefore && isNode(keyNode)) {
99
+ keyNode.commentBefore = ` ${memberStyle.commentBefore}`;
100
+ }
101
+ if (memberStyle.comment && isNode(valueNode)) {
102
+ valueNode.comment = ` ${memberStyle.comment}`;
103
+ }
104
+
105
+ map.items.push(pair);
106
+ });
107
+
108
+ return map;
109
+ }
110
+
111
+ if (isArrayElement(element)) {
112
+ const seq = new YAMLSeq();
113
+ seq.flow = style.styleGroup === 'Flow';
114
+ applyComments(seq, style);
115
+
116
+ element.forEach((item) => {
117
+ seq.items.push(toYAMLNode(item, visited));
118
+ });
119
+
120
+ return seq;
121
+ }
122
+
123
+ if (isRefElement(element)) {
124
+ return new Scalar(String(toValue(element)));
125
+ }
126
+
127
+ if (isLinkElement(element)) {
128
+ return new Scalar(isStringElement(element.href) ? toValue(element.href) : '');
129
+ }
130
+
131
+ // scalar element (string, number, boolean, null)
132
+ const scalarType = style.scalarStyle ? scalarStyleMap[style.scalarStyle] : undefined;
133
+
134
+ const scalar = new Scalar(toValue(element));
135
+ if (scalarType) {
136
+ scalar.type = scalarType;
137
+ }
138
+
139
+ // use rawContent to infer YAML library format hints for plain scalars that resolved to numbers;
140
+ // only applies to Plain style — quoted scalars are always strings in YAML.
141
+ // note: the YAML library may normalize the representation (e.g. 1.0e10 -> 1e+10, 0x1A -> 0x1a)
142
+ // while preserving the format category (exponential, hex, octal, fractional digits)
143
+ if (style.rawContent && style.scalarStyle === 'Plain' && typeof scalar.value === 'number') {
144
+ if (/[eE]/.test(style.rawContent)) {
145
+ scalar.format = 'EXP';
146
+ } else if (/^0x/i.test(style.rawContent)) {
147
+ scalar.format = 'HEX';
148
+ } else if (/^0o/i.test(style.rawContent)) {
149
+ scalar.format = 'OCT';
150
+ }
151
+ const dotMatch = style.rawContent.match(/\.(\d+)/);
152
+ if (dotMatch) {
153
+ scalar.minFractionDigits = dotMatch[1].length;
154
+ }
155
+ }
156
+
157
+ applyComments(scalar, style);
158
+
159
+ return scalar;
160
+ };
161
+
162
+ /**
163
+ * @public
164
+ */
165
+ const serializer = (
166
+ element: Element,
167
+ {
168
+ directive = false,
169
+ preserveStyle = false,
170
+ aliasDuplicateObjects = false,
171
+ ...options
172
+ }: YAMLSerializerOptions = {},
173
+ ): string => {
174
+ const allOptions: YAMLSerializerOptions = { aliasDuplicateObjects, ...options };
175
+
176
+ if (preserveStyle) {
177
+ const style = getStyle(element);
178
+ if (options.indent === undefined && typeof style.indent === 'number') {
179
+ allOptions.indent = style.indent;
180
+ }
181
+ if (typeof style.flowCollectionPadding === 'boolean') {
182
+ allOptions.flowCollectionPadding = style.flowCollectionPadding;
183
+ }
184
+
185
+ const rootNode = toYAMLNode(element, new WeakSet());
186
+ const doc = new Document(undefined, allOptions);
187
+ doc.contents = rootNode as YAMLNode;
188
+
189
+ if (directive) {
190
+ doc.directives!.yaml.explicit = true;
191
+ }
192
+
193
+ return doc.toString(allOptions);
194
+ }
195
+
196
+ if (directive) {
197
+ const doc = new Document(toValue(element), allOptions);
198
+ doc.directives!.yaml.explicit = true;
199
+ return doc.toString(allOptions);
200
+ }
201
+
202
+ return stringify(toValue(element), allOptions);
203
+ };
204
+
205
+ export default serializer;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _apidomTraverse = require("@speclynx/apidom-traverse");
6
+ /**
7
+ * Transforms ApiDOM into S-expressions (Symbolic Expressions).
8
+ * @public
9
+ */
10
+ const sexprs = element => {
11
+ let result = '';
12
+ let nestingLevel = 0;
13
+ (0, _apidomTraverse.traverse)(element, {
14
+ enter(path) {
15
+ const {
16
+ element: elementName
17
+ } = path.node;
18
+ const capitalizedElementName = elementName.charAt(0).toUpperCase() + elementName.slice(1);
19
+ const indent = ' '.repeat(nestingLevel);
20
+ result += nestingLevel > 0 ? '\n' : '';
21
+ result += `${indent}(${capitalizedElementName}Element`;
22
+ nestingLevel += 1;
23
+ },
24
+ leave() {
25
+ nestingLevel -= 1;
26
+ result += ')';
27
+ }
28
+ });
29
+ return result;
30
+ };
31
+ var _default = exports.default = sexprs;
@@ -0,0 +1,28 @@
1
+ import { traverse } from '@speclynx/apidom-traverse';
2
+
3
+ /**
4
+ * Transforms ApiDOM into S-expressions (Symbolic Expressions).
5
+ * @public
6
+ */
7
+ const sexprs = element => {
8
+ let result = '';
9
+ let nestingLevel = 0;
10
+ traverse(element, {
11
+ enter(path) {
12
+ const {
13
+ element: elementName
14
+ } = path.node;
15
+ const capitalizedElementName = elementName.charAt(0).toUpperCase() + elementName.slice(1);
16
+ const indent = ' '.repeat(nestingLevel);
17
+ result += nestingLevel > 0 ? '\n' : '';
18
+ result += `${indent}(${capitalizedElementName}Element`;
19
+ nestingLevel += 1;
20
+ },
21
+ leave() {
22
+ nestingLevel -= 1;
23
+ result += ')';
24
+ }
25
+ });
26
+ return result;
27
+ };
28
+ export default sexprs;
@@ -0,0 +1,30 @@
1
+ import { Element } from '@speclynx/apidom-datamodel';
2
+ import { traverse, type Path } from '@speclynx/apidom-traverse';
3
+
4
+ /**
5
+ * Transforms ApiDOM into S-expressions (Symbolic Expressions).
6
+ * @public
7
+ */
8
+ const sexprs = (element: Element): string => {
9
+ let result = '';
10
+ let nestingLevel = 0;
11
+
12
+ traverse(element, {
13
+ enter(path: Path<Element>) {
14
+ const { element: elementName } = path.node;
15
+ const capitalizedElementName = elementName.charAt(0).toUpperCase() + elementName.slice(1);
16
+ const indent = ' '.repeat(nestingLevel);
17
+ result += nestingLevel > 0 ? '\n' : '';
18
+ result += `${indent}(${capitalizedElementName}Element`;
19
+ nestingLevel += 1;
20
+ },
21
+ leave() {
22
+ nestingLevel -= 1;
23
+ result += ')';
24
+ },
25
+ });
26
+
27
+ return result;
28
+ };
29
+
30
+ export default sexprs;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.default = void 0;
6
+ var _namespace = _interopRequireDefault(require("../namespace.cjs"));
7
+ var _dehydrate = _interopRequireDefault(require("./dehydrate.cjs"));
8
+ /**
9
+ * Create a refracted string representation of an Element.
10
+ * @public
11
+ */
12
+ const toString = (element, namespace = _namespace.default) => {
13
+ const refractStructure = (0, _dehydrate.default)(element, namespace);
14
+ return JSON.stringify(refractStructure);
15
+ };
16
+ var _default = exports.default = toString;
@@ -0,0 +1,11 @@
1
+ import defaultNamespace from "../namespace.mjs";
2
+ import dehydrate from "./dehydrate.mjs";
3
+ /**
4
+ * Create a refracted string representation of an Element.
5
+ * @public
6
+ */
7
+ const toString = (element, namespace = defaultNamespace) => {
8
+ const refractStructure = dehydrate(element, namespace);
9
+ return JSON.stringify(refractStructure);
10
+ };
11
+ export default toString;
@@ -0,0 +1,15 @@
1
+ import { Element, Namespace } from '@speclynx/apidom-datamodel';
2
+
3
+ import defaultNamespace from '../namespace.ts';
4
+ import dehydrate from './dehydrate.ts';
5
+
6
+ /**
7
+ * Create a refracted string representation of an Element.
8
+ * @public
9
+ */
10
+ const toString = (element: Element, namespace: Namespace = defaultNamespace): string => {
11
+ const refractStructure = dehydrate(element, namespace);
12
+ return JSON.stringify(refractStructure);
13
+ };
14
+
15
+ export default toString;