bool.js 635 B

123456789101112131415161718192021
  1. 'use strict';
  2. var Scalar = require('../../nodes/Scalar.js');
  3. const boolTag = {
  4. identify: value => typeof value === 'boolean',
  5. default: true,
  6. tag: 'tag:yaml.org,2002:bool',
  7. test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
  8. resolve: str => new Scalar.Scalar(str[0] === 't' || str[0] === 'T'),
  9. stringify({ source, value }, ctx) {
  10. if (source && boolTag.test.test(source)) {
  11. const sv = source[0] === 't' || source[0] === 'T';
  12. if (value === sv)
  13. return source;
  14. }
  15. return value ? ctx.options.trueStr : ctx.options.falseStr;
  16. }
  17. };
  18. exports.boolTag = boolTag;