bool.js 787 B

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