aboutsummaryrefslogtreecommitdiff
path: root/node_modules/yaml/browser/dist/doc/createNode.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-06-04 08:51:01 +0200
committerMinteck <contact@minteck.org>2022-06-04 08:51:01 +0200
commit383285ecd5292bf9a825e05904955b937de84cc9 (patch)
tree0a53b6f02c1604b078044567c03dc1b6c944c8c2 /node_modules/yaml/browser/dist/doc/createNode.js
downloadequestriadb-383285ecd5292bf9a825e05904955b937de84cc9.tar.gz
equestriadb-383285ecd5292bf9a825e05904955b937de84cc9.tar.bz2
equestriadb-383285ecd5292bf9a825e05904955b937de84cc9.zip
Initial commit
Diffstat (limited to 'node_modules/yaml/browser/dist/doc/createNode.js')
-rw-r--r--node_modules/yaml/browser/dist/doc/createNode.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/node_modules/yaml/browser/dist/doc/createNode.js b/node_modules/yaml/browser/dist/doc/createNode.js
new file mode 100644
index 0000000..8ad907d
--- /dev/null
+++ b/node_modules/yaml/browser/dist/doc/createNode.js
@@ -0,0 +1,87 @@
+import { Alias } from '../nodes/Alias.js';
+import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/Node.js';
+import { Scalar } from '../nodes/Scalar.js';
+
+const defaultTagPrefix = 'tag:yaml.org,2002:';
+function findTagObject(value, tagName, tags) {
+ var _a;
+ if (tagName) {
+ const match = tags.filter(t => t.tag === tagName);
+ const tagObj = (_a = match.find(t => !t.format)) !== null && _a !== void 0 ? _a : match[0];
+ if (!tagObj)
+ throw new Error(`Tag ${tagName} not found`);
+ return tagObj;
+ }
+ return tags.find(t => { var _a; return ((_a = t.identify) === null || _a === void 0 ? void 0 : _a.call(t, value)) && !t.format; });
+}
+function createNode(value, tagName, ctx) {
+ var _a, _b;
+ if (isDocument(value))
+ value = value.contents;
+ if (isNode(value))
+ return value;
+ if (isPair(value)) {
+ const map = (_b = (_a = ctx.schema[MAP]).createNode) === null || _b === void 0 ? void 0 : _b.call(_a, ctx.schema, null, ctx);
+ map.items.push(value);
+ return map;
+ }
+ if (value instanceof String ||
+ value instanceof Number ||
+ value instanceof Boolean ||
+ (typeof BigInt === 'function' && value instanceof BigInt) // not supported everywhere
+ ) {
+ // https://tc39.es/ecma262/#sec-serializejsonproperty
+ value = value.valueOf();
+ }
+ const { aliasDuplicateObjects, onAnchor, onTagObj, schema, sourceObjects } = ctx;
+ // Detect duplicate references to the same object & use Alias nodes for all
+ // after first. The `ref` wrapper allows for circular references to resolve.
+ let ref = undefined;
+ if (aliasDuplicateObjects && value && typeof value === 'object') {
+ ref = sourceObjects.get(value);
+ if (ref) {
+ if (!ref.anchor)
+ ref.anchor = onAnchor(value);
+ return new Alias(ref.anchor);
+ }
+ else {
+ ref = { anchor: null, node: null };
+ sourceObjects.set(value, ref);
+ }
+ }
+ if (tagName === null || tagName === void 0 ? void 0 : tagName.startsWith('!!'))
+ tagName = defaultTagPrefix + tagName.slice(2);
+ let tagObj = findTagObject(value, tagName, schema.tags);
+ if (!tagObj) {
+ if (value && typeof value.toJSON === 'function') {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
+ value = value.toJSON();
+ }
+ if (!value || typeof value !== 'object') {
+ const node = new Scalar(value);
+ if (ref)
+ ref.node = node;
+ return node;
+ }
+ tagObj =
+ value instanceof Map
+ ? schema[MAP]
+ : Symbol.iterator in Object(value)
+ ? schema[SEQ]
+ : schema[MAP];
+ }
+ if (onTagObj) {
+ onTagObj(tagObj);
+ delete ctx.onTagObj;
+ }
+ const node = (tagObj === null || tagObj === void 0 ? void 0 : tagObj.createNode)
+ ? tagObj.createNode(ctx.schema, value, ctx)
+ : new Scalar(value);
+ if (tagName)
+ node.tag = tagName;
+ if (ref)
+ ref.node = node;
+ return node;
+}
+
+export { createNode };