source: node_modules/yaml/dist/schema/Schema.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[d24f17c]1'use strict';
2
3var identity = require('../nodes/identity.js');
4var map = require('./common/map.js');
5var seq = require('./common/seq.js');
6var string = require('./common/string.js');
7var tags = require('./tags.js');
8
9const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
10class Schema {
11 constructor({ compat, customTags, merge, resolveKnownTags, schema, sortMapEntries, toStringDefaults }) {
12 this.compat = Array.isArray(compat)
13 ? tags.getTags(compat, 'compat')
14 : compat
15 ? tags.getTags(null, compat)
16 : null;
17 this.merge = !!merge;
18 this.name = (typeof schema === 'string' && schema) || 'core';
19 this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
20 this.tags = tags.getTags(customTags, this.name);
21 this.toStringOptions = toStringDefaults ?? null;
22 Object.defineProperty(this, identity.MAP, { value: map.map });
23 Object.defineProperty(this, identity.SCALAR, { value: string.string });
24 Object.defineProperty(this, identity.SEQ, { value: seq.seq });
25 // Used by createMap()
26 this.sortMapEntries =
27 typeof sortMapEntries === 'function'
28 ? sortMapEntries
29 : sortMapEntries === true
30 ? sortMapEntriesByKey
31 : null;
32 }
33 clone() {
34 const copy = Object.create(Schema.prototype, Object.getOwnPropertyDescriptors(this));
35 copy.tags = this.tags.slice();
36 return copy;
37 }
38}
39
40exports.Schema = Schema;
Note: See TracBrowser for help on using the repository browser.