aboutsummaryrefslogtreecommitdiff
path: root/node_modules/js-yaml/lib/js-yaml/type/omap.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/js-yaml/lib/js-yaml/type/omap.js')
-rw-r--r--node_modules/js-yaml/lib/js-yaml/type/omap.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/node_modules/js-yaml/lib/js-yaml/type/omap.js b/node_modules/js-yaml/lib/js-yaml/type/omap.js
new file mode 100644
index 0000000..b2b5323
--- /dev/null
+++ b/node_modules/js-yaml/lib/js-yaml/type/omap.js
@@ -0,0 +1,44 @@
+'use strict';
+
+var Type = require('../type');
+
+var _hasOwnProperty = Object.prototype.hasOwnProperty;
+var _toString = Object.prototype.toString;
+
+function resolveYamlOmap(data) {
+ if (data === null) return true;
+
+ var objectKeys = [], index, length, pair, pairKey, pairHasKey,
+ object = data;
+
+ for (index = 0, length = object.length; index < length; index += 1) {
+ pair = object[index];
+ pairHasKey = false;
+
+ if (_toString.call(pair) !== '[object Object]') return false;
+
+ for (pairKey in pair) {
+ if (_hasOwnProperty.call(pair, pairKey)) {
+ if (!pairHasKey) pairHasKey = true;
+ else return false;
+ }
+ }
+
+ if (!pairHasKey) return false;
+
+ if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
+ else return false;
+ }
+
+ return true;
+}
+
+function constructYamlOmap(data) {
+ return data !== null ? data : [];
+}
+
+module.exports = new Type('tag:yaml.org,2002:omap', {
+ kind: 'sequence',
+ resolve: resolveYamlOmap,
+ construct: constructYamlOmap
+});