stringify.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const quote_1 = require("./quote");
  4. const object_1 = require("./object");
  5. const function_1 = require("./function");
  6. /**
  7. * Stringify primitive values.
  8. */
  9. const PRIMITIVE_TYPES = {
  10. string: quote_1.quoteString,
  11. number: (value) => (Object.is(value, -0) ? "-0" : String(value)),
  12. boolean: String,
  13. symbol: (value, space, next) => {
  14. const key = Symbol.keyFor(value);
  15. if (key !== undefined)
  16. return `Symbol.for(${next(key)})`;
  17. // ES2018 `Symbol.description`.
  18. return `Symbol(${next(value.description)})`;
  19. },
  20. bigint: (value, space, next) => {
  21. return `BigInt(${next(String(value))})`;
  22. },
  23. undefined: String,
  24. object: object_1.objectToString,
  25. function: function_1.functionToString
  26. };
  27. /**
  28. * Stringify a value recursively.
  29. */
  30. exports.toString = (value, space, next, key) => {
  31. if (value === null)
  32. return "null";
  33. return PRIMITIVE_TYPES[typeof value](value, space, next, key);
  34. };
  35. //# sourceMappingURL=stringify.js.map