summaryrefslogtreecommitdiff
path: root/MistyCore/node_modules/yaml/browser/dist/parse/cst-stringify.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/parse/cst-stringify.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/parse/cst-stringify.js')
-rw-r--r--MistyCore/node_modules/yaml/browser/dist/parse/cst-stringify.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/MistyCore/node_modules/yaml/browser/dist/parse/cst-stringify.js b/MistyCore/node_modules/yaml/browser/dist/parse/cst-stringify.js
new file mode 100644
index 0000000..d6ab58c
--- /dev/null
+++ b/MistyCore/node_modules/yaml/browser/dist/parse/cst-stringify.js
@@ -0,0 +1,61 @@
+/**
+ * Stringify a CST document, token, or collection item
+ *
+ * Fair warning: This applies no validation whatsoever, and
+ * simply concatenates the sources in their logical order.
+ */
+const stringify = (cst) => 'type' in cst ? stringifyToken(cst) : stringifyItem(cst);
+function stringifyToken(token) {
+ switch (token.type) {
+ case 'block-scalar': {
+ let res = '';
+ for (const tok of token.props)
+ res += stringifyToken(tok);
+ return res + token.source;
+ }
+ case 'block-map':
+ case 'block-seq': {
+ let res = '';
+ for (const item of token.items)
+ res += stringifyItem(item);
+ return res;
+ }
+ case 'flow-collection': {
+ let res = token.start.source;
+ for (const item of token.items)
+ res += stringifyItem(item);
+ for (const st of token.end)
+ res += st.source;
+ return res;
+ }
+ case 'document': {
+ let res = stringifyItem(token);
+ if (token.end)
+ for (const st of token.end)
+ res += st.source;
+ return res;
+ }
+ default: {
+ let res = token.source;
+ if ('end' in token && token.end)
+ for (const st of token.end)
+ res += st.source;
+ return res;
+ }
+ }
+}
+function stringifyItem({ start, key, sep, value }) {
+ let res = '';
+ for (const st of start)
+ res += st.source;
+ if (key)
+ res += stringifyToken(key);
+ if (sep)
+ for (const st of sep)
+ res += st.source;
+ if (value)
+ res += stringifyToken(value);
+ return res;
+}
+
+export { stringify };