json.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var stableStringify = require("fast-json-stable-stringify");
  4. var UNDEFINED = 'undefined';
  5. function stringify(input) {
  6. return input === undefined ? UNDEFINED : stableStringify(input);
  7. }
  8. exports.stringify = stringify;
  9. function parse(input) {
  10. return input === UNDEFINED ? undefined : JSON.parse(input);
  11. }
  12. exports.parse = parse;
  13. function normalize(input, _a) {
  14. var _b = (_a === void 0 ? {} : _a).parse, parser = _b === void 0 ? parse : _b;
  15. var result;
  16. if (normalize.cache.has(input)) {
  17. result = normalize.cache.get(input);
  18. }
  19. else {
  20. var data = parser(input);
  21. result = stringify(data);
  22. if (result === input)
  23. result = undefined;
  24. normalize.cache.set(input, result);
  25. }
  26. return result === undefined ? input : result;
  27. }
  28. exports.normalize = normalize;
  29. (function (normalize) {
  30. normalize.cache = new Map();
  31. })(normalize = exports.normalize || (exports.normalize = {}));