summaryrefslogtreecommitdiff
path: root/MistyCore/node_modules/yaml/browser/dist/doc/createNode.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-11-28 17:31:34 +0100
committerMinteck <contact@minteck.org>2022-11-28 17:31:34 +0100
commit7923aa8942b55884320ef2428417e3ee4b121613 (patch)
tree7993632f2898b1998f25b11ce40a8d2eb3d44730 /MistyCore/node_modules/yaml/browser/dist/doc/createNode.js
downloadmistyos-og-mane.tar.gz
mistyos-og-mane.tar.bz2
mistyos-og-mane.zip
Initial commitHEADmane
Diffstat (limited to 'MistyCore/node_modules/yaml/browser/dist/doc/createNode.js')
-rw-r--r--MistyCore/node_modules/yaml/browser/dist/doc/createNode.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/MistyCore/node_modules/yaml/browser/dist/doc/createNode.js b/MistyCore/node_modules/yaml/browser/dist/doc/createNode.js
new file mode 100644
index 0000000..52ca122
--- /dev/null
+++ b/MistyCore/node_modules/yaml/browser/dist/doc/createNode.js
@@ -0,0 +1,85 @@
+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) {
+ if (tagName) {
+ const match = tags.filter(t => t.tag === tagName);
+ const tagObj = match.find(t => !t.format) ?? match[0];
+ if (!tagObj)
+ throw new Error(`Tag ${tagName} not found`);
+ return tagObj;
+ }
+ return tags.find(t => t.identify?.(value) && !t.format);
+}
+function createNode(value, tagName, ctx) {
+ if (isDocument(value))
+ value = value.contents;
+ if (isNode(value))
+ return value;
+ if (isPair(value)) {
+ const map = ctx.schema[MAP].createNode?.(ctx.schema, null, ctx);
+ map.items.push(value);
+ return map;
+ }
+ if (value instanceof String ||
+ value instanceof Number ||
+ value instanceof Boolean ||
+ (typeof BigInt !== 'undefined' && 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?.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?.createNode
+ ? tagObj.createNode(ctx.schema, value, ctx)
+ : new Scalar(value);
+ if (tagName)
+ node.tag = tagName;
+ if (ref)
+ ref.node = node;
+ return node;
+}
+
+export { createNode };