-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
Schema.js
30 lines (25 loc) · 941 Bytes
/
Schema.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { schemas, tags } from '../tags/index.js'
import { getSchemaTags } from './getSchemaTags.js'
const sortMapEntriesByKey = (a, b) =>
a.key < b.key ? -1 : a.key > b.key ? 1 : 0
const coreKnownTags = {
'tag:yaml.org,2002:binary': tags.binary,
'tag:yaml.org,2002:omap': tags.omap,
'tag:yaml.org,2002:pairs': tags.pairs,
'tag:yaml.org,2002:set': tags.set,
'tag:yaml.org,2002:timestamp': tags.timestamp
}
export class Schema {
constructor({ customTags, merge, resolveKnownTags, schema, sortMapEntries }) {
this.merge = !!merge
this.name = schema
this.knownTags = resolveKnownTags ? coreKnownTags : {}
this.tags = getSchemaTags(schemas, tags, customTags, schema)
// Used by createNode(), to avoid circular dependencies
this.map = tags.map
this.seq = tags.seq
// Used by createMap()
this.sortMapEntries =
sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null
}
}