aboutsummaryrefslogtreecommitdiff
path: root/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.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/schema/yaml-1.1/omap.js
downloadequestriadb-383285ecd5292bf9a825e05904955b937de84cc9.tar.gz
equestriadb-383285ecd5292bf9a825e05904955b937de84cc9.tar.bz2
equestriadb-383285ecd5292bf9a825e05904955b937de84cc9.zip
Initial commit
Diffstat (limited to 'node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js')
-rw-r--r--node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js b/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js
new file mode 100644
index 0000000..71e2527
--- /dev/null
+++ b/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js
@@ -0,0 +1,73 @@
+import { YAMLSeq } from '../../nodes/YAMLSeq.js';
+import { toJS } from '../../nodes/toJS.js';
+import { isScalar, isPair } from '../../nodes/Node.js';
+import { YAMLMap } from '../../nodes/YAMLMap.js';
+import { resolvePairs, createPairs } from './pairs.js';
+
+class YAMLOMap extends YAMLSeq {
+ constructor() {
+ super();
+ this.add = YAMLMap.prototype.add.bind(this);
+ this.delete = YAMLMap.prototype.delete.bind(this);
+ this.get = YAMLMap.prototype.get.bind(this);
+ this.has = YAMLMap.prototype.has.bind(this);
+ this.set = YAMLMap.prototype.set.bind(this);
+ this.tag = YAMLOMap.tag;
+ }
+ /**
+ * If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
+ * but TypeScript won't allow widening the signature of a child method.
+ */
+ toJSON(_, ctx) {
+ if (!ctx)
+ return super.toJSON(_);
+ const map = new Map();
+ if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
+ ctx.onCreate(map);
+ for (const pair of this.items) {
+ let key, value;
+ if (isPair(pair)) {
+ key = toJS(pair.key, '', ctx);
+ value = toJS(pair.value, key, ctx);
+ }
+ else {
+ key = toJS(pair, '', ctx);
+ }
+ if (map.has(key))
+ throw new Error('Ordered maps must not include duplicate keys');
+ map.set(key, value);
+ }
+ return map;
+ }
+}
+YAMLOMap.tag = 'tag:yaml.org,2002:omap';
+const omap = {
+ collection: 'seq',
+ identify: value => value instanceof Map,
+ nodeClass: YAMLOMap,
+ default: false,
+ tag: 'tag:yaml.org,2002:omap',
+ resolve(seq, onError) {
+ const pairs = resolvePairs(seq, onError);
+ const seenKeys = [];
+ for (const { key } of pairs.items) {
+ if (isScalar(key)) {
+ if (seenKeys.includes(key.value)) {
+ onError(`Ordered maps must not include duplicate keys: ${key.value}`);
+ }
+ else {
+ seenKeys.push(key.value);
+ }
+ }
+ }
+ return Object.assign(new YAMLOMap(), pairs);
+ },
+ createNode(schema, iterable, ctx) {
+ const pairs = createPairs(schema, iterable, ctx);
+ const omap = new YAMLOMap();
+ omap.items = pairs.items;
+ return omap;
+ }
+};
+
+export { YAMLOMap, omap };