1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.stringify = stringify;
|
7 | exports.parse = parse;
|
8 | exports.normalize = normalize;
|
9 |
|
10 | var fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-stringify"));
|
11 | var UNDEFINED = 'undefined';
|
12 | function stringify(input) {
|
13 | return input === undefined ? UNDEFINED : (0, fast_json_stable_stringify_1.default)(input);
|
14 | }
|
15 |
|
16 | function parse(input) {
|
17 | return input === UNDEFINED ? undefined : JSON.parse(input);
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 | function normalize(input, _a) {
|
23 | var _b = _a === void 0 ? {} : _a, _c = _b.parse, parser = _c === void 0 ? parse : _c;
|
24 | var result;
|
25 | if (normalize.cache.has(input)) {
|
26 | result = normalize.cache.get(input);
|
27 | }
|
28 | else {
|
29 | var data = parser(input);
|
30 | result = stringify(data);
|
31 | if (result === input)
|
32 | result = undefined;
|
33 | normalize.cache.set(input, result);
|
34 | }
|
35 | return result === undefined ? input : result;
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | (function (normalize) {
|
42 | normalize.cache = new Map();
|
43 | })(normalize || (exports.normalize = normalize = {}));
|