1
0
Fork 0
mirror of https://github.com/dawidd6/action-ansible-playbook.git synced 2024-11-23 09:17:19 +00:00
action-ansible-playbook/node_modules/yaml/dist/nodes/Pair.js

40 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2022-10-21 14:44:44 +00:00
'use strict';
var createNode = require('../doc/createNode.js');
var stringifyPair = require('../stringify/stringifyPair.js');
var addPairToJSMap = require('./addPairToJSMap.js');
2024-01-17 09:08:10 +00:00
var identity = require('./identity.js');
2022-10-21 14:44:44 +00:00
function createPair(key, value, ctx) {
const k = createNode.createNode(key, undefined, ctx);
const v = createNode.createNode(value, undefined, ctx);
return new Pair(k, v);
}
class Pair {
constructor(key, value = null) {
2024-01-17 09:08:10 +00:00
Object.defineProperty(this, identity.NODE_TYPE, { value: identity.PAIR });
2022-10-21 14:44:44 +00:00
this.key = key;
this.value = value;
}
clone(schema) {
let { key, value } = this;
2024-01-17 09:08:10 +00:00
if (identity.isNode(key))
2022-10-21 14:44:44 +00:00
key = key.clone(schema);
2024-01-17 09:08:10 +00:00
if (identity.isNode(value))
2022-10-21 14:44:44 +00:00
value = value.clone(schema);
return new Pair(key, value);
}
toJSON(_, ctx) {
const pair = ctx?.mapAsMap ? new Map() : {};
return addPairToJSMap.addPairToJSMap(ctx, pair, this);
}
toString(ctx, onComment, onChompKeep) {
return ctx?.doc
? stringifyPair.stringifyPair(this, ctx, onComment, onChompKeep)
: JSON.stringify(this);
}
}
exports.Pair = Pair;
exports.createPair = createPair;