UNPKG

841 BJavaScriptView Raw
1'use strict';
2
3var Scalar = require('../../nodes/Scalar.js');
4
5function boolStringify({ value, source }, ctx) {
6 const boolObj = value ? trueTag : falseTag;
7 if (source && boolObj.test.test(source))
8 return source;
9 return value ? ctx.options.trueStr : ctx.options.falseStr;
10}
11const trueTag = {
12 identify: value => value === true,
13 default: true,
14 tag: 'tag:yaml.org,2002:bool',
15 test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
16 resolve: () => new Scalar.Scalar(true),
17 stringify: boolStringify
18};
19const falseTag = {
20 identify: value => value === false,
21 default: true,
22 tag: 'tag:yaml.org,2002:bool',
23 test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
24 resolve: () => new Scalar.Scalar(false),
25 stringify: boolStringify
26};
27
28exports.falseTag = falseTag;
29exports.trueTag = trueTag;