aboutsummaryrefslogtreecommitdiff
path: root/node_modules/js-yaml/lib/js-yaml/type/pairs.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/js-yaml/lib/js-yaml/type/pairs.js')
-rw-r--r--node_modules/js-yaml/lib/js-yaml/type/pairs.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/node_modules/js-yaml/lib/js-yaml/type/pairs.js b/node_modules/js-yaml/lib/js-yaml/type/pairs.js
new file mode 100644
index 0000000..74b5240
--- /dev/null
+++ b/node_modules/js-yaml/lib/js-yaml/type/pairs.js
@@ -0,0 +1,53 @@
+'use strict';
+
+var Type = require('../type');
+
+var _toString = Object.prototype.toString;
+
+function resolveYamlPairs(data) {
+ if (data === null) return true;
+
+ var index, length, pair, keys, result,
+ object = data;
+
+ result = new Array(object.length);
+
+ for (index = 0, length = object.length; index < length; index += 1) {
+ pair = object[index];
+
+ if (_toString.call(pair) !== '[object Object]') return false;
+
+ keys = Object.keys(pair);
+
+ if (keys.length !== 1) return false;
+
+ result[index] = [ keys[0], pair[keys[0]] ];
+ }
+
+ return true;
+}
+
+function constructYamlPairs(data) {
+ if (data === null) return [];
+
+ var index, length, pair, keys, result,
+ object = data;
+
+ result = new Array(object.length);
+
+ for (index = 0, length = object.length; index < length; index += 1) {
+ pair = object[index];
+
+ keys = Object.keys(pair);
+
+ result[index] = [ keys[0], pair[keys[0]] ];
+ }
+
+ return result;
+}
+
+module.exports = new Type('tag:yaml.org,2002:pairs', {
+ kind: 'sequence',
+ resolve: resolveYamlPairs,
+ construct: constructYamlPairs
+});