Scalar.js 700 B

123456789101112131415161718192021222324
  1. import { SCALAR } from './identity.js';
  2. import { NodeBase } from './Node.js';
  3. import { toJS } from './toJS.js';
  4. const isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object');
  5. class Scalar extends NodeBase {
  6. constructor(value) {
  7. super(SCALAR);
  8. this.value = value;
  9. }
  10. toJSON(arg, ctx) {
  11. return ctx?.keep ? this.value : toJS(this.value, arg, ctx);
  12. }
  13. toString() {
  14. return String(this.value);
  15. }
  16. }
  17. Scalar.BLOCK_FOLDED = 'BLOCK_FOLDED';
  18. Scalar.BLOCK_LITERAL = 'BLOCK_LITERAL';
  19. Scalar.PLAIN = 'PLAIN';
  20. Scalar.QUOTE_DOUBLE = 'QUOTE_DOUBLE';
  21. Scalar.QUOTE_SINGLE = 'QUOTE_SINGLE';
  22. export { Scalar, isScalarValue };