bool.js 841 B

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