Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81149 views
1
'use strict';
2
3
var Type = require('../type');
4
5
var _hasOwnProperty = Object.prototype.hasOwnProperty;
6
var _toString = Object.prototype.toString;
7
8
function resolveYamlOmap(data) {
9
if (null === data) {
10
return true;
11
}
12
13
var objectKeys = [], index, length, pair, pairKey, pairHasKey,
14
object = data;
15
16
for (index = 0, length = object.length; index < length; index += 1) {
17
pair = object[index];
18
pairHasKey = false;
19
20
if ('[object Object]' !== _toString.call(pair)) {
21
return false;
22
}
23
24
for (pairKey in pair) {
25
if (_hasOwnProperty.call(pair, pairKey)) {
26
if (!pairHasKey) {
27
pairHasKey = true;
28
} else {
29
return false;
30
}
31
}
32
}
33
34
if (!pairHasKey) {
35
return false;
36
}
37
38
if (-1 === objectKeys.indexOf(pairKey)) {
39
objectKeys.push(pairKey);
40
} else {
41
return false;
42
}
43
}
44
45
return true;
46
}
47
48
function constructYamlOmap(data) {
49
return null !== data ? data : [];
50
}
51
52
module.exports = new Type('tag:yaml.org,2002:omap', {
53
kind: 'sequence',
54
resolve: resolveYamlOmap,
55
construct: constructYamlOmap
56
});
57
58