|
| 1 | +// Socket Community Patch: https://socket.dev |
| 2 | +// Date: Thu, 19 Mar 2026 13:31:01 GMT |
| 3 | +// For more information see https://socket.dev/patch/80a838c0-0f14-4eaf-832e-f5e107a9f7db |
| 4 | +// This file includes modifications made by Socket, Inc. on Thu, 19 Mar 2026; these modifications are called the "Patch". In some cases, Socket may be required to make the Patch available to you under specific terms, or may be prohibited from restricting certain rights you may have. For example, the terms of another applicable license may require Socket to make the Patch available under specific terms. In those cases, the Patch is made available to you under the required terms, and Socket does not seek to restrict your rights relative to the Patch where prohibited. In all other cases, the Patch is available to you exclusively under the PolyForm Shield License 1.0.0 (https://polyformproject.org/licenses/shield/1.0.0/). The Patch was distributed by Socket with additional information concerning licensing, attribution, and limitation of liability which may be relevant to you and your use of the Patch. As far as the law allows, the Patch and the software including the patch come as is, without any warranty or condition, and Socket will not be liable to you for any damages arising out of the applicable license terms or the use or nature of the Patch or the software including the patch, under any kind of legal claim. |
| 5 | +// Original License: MIT |
| 6 | + |
| 7 | +self.Flatted = (function (exports) { |
| 8 | + 'use strict'; |
| 9 | + |
| 10 | + function _typeof(o) { |
| 11 | + "@babel/helpers - typeof"; |
| 12 | + |
| 13 | + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { |
| 14 | + return typeof o; |
| 15 | + } : function (o) { |
| 16 | + return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; |
| 17 | + }, _typeof(o); |
| 18 | + } |
| 19 | + |
| 20 | + /// <reference types="../types/index.d.ts" /> |
| 21 | + |
| 22 | + // (c) 2020-present Andrea Giammarchi |
| 23 | + |
| 24 | + var $parse = JSON.parse, |
| 25 | + $stringify = JSON.stringify; |
| 26 | + var keys = Object.keys; |
| 27 | + var Primitive = String; // it could be Number |
| 28 | + var primitive = 'string'; // it could be 'number' |
| 29 | + |
| 30 | + var ignore = {}; |
| 31 | + var object = 'object'; |
| 32 | + var noop = function noop(_, value) { |
| 33 | + return value; |
| 34 | + }; |
| 35 | + var primitives = function primitives(value) { |
| 36 | + return value instanceof Primitive ? Primitive(value) : value; |
| 37 | + }; |
| 38 | + var Primitives = function Primitives(_, value) { |
| 39 | + return _typeof(value) === primitive ? new Primitive(value) : value; |
| 40 | + }; |
| 41 | + var resolver = function resolver(input, lazy, parsed, $) { |
| 42 | + return function (output) { |
| 43 | + for (var ke = keys(output), length = ke.length, y = 0; y < length; y++) { |
| 44 | + var k = ke[y]; |
| 45 | + var value = output[k]; |
| 46 | + if (value instanceof Primitive) { |
| 47 | + var tmp = input[value]; |
| 48 | + if (_typeof(tmp) === object && !parsed.has(tmp)) { |
| 49 | + parsed.add(tmp); |
| 50 | + output[k] = ignore; |
| 51 | + lazy.push({ |
| 52 | + o: output, |
| 53 | + k: k, |
| 54 | + r: tmp |
| 55 | + }); |
| 56 | + } else output[k] = $.call(output, k, tmp); |
| 57 | + } else if (output[k] !== ignore) output[k] = $.call(output, k, value); |
| 58 | + } |
| 59 | + return output; |
| 60 | + }; |
| 61 | + }; |
| 62 | + var set = function set(known, input, value) { |
| 63 | + var index = Primitive(input.push(value) - 1); |
| 64 | + known.set(value, index); |
| 65 | + return index; |
| 66 | + }; |
| 67 | + |
| 68 | + /** |
| 69 | + * Converts a specialized flatted string into a JS value. |
| 70 | + * @param {string} text |
| 71 | + * @param {(this: any, key: string, value: any) => any} [reviver] |
| 72 | + * @returns {any} |
| 73 | + */ |
| 74 | + var parse = function parse(text, reviver) { |
| 75 | + var input = $parse(text, Primitives).map(primitives); |
| 76 | + var $ = reviver || noop; |
| 77 | + var value = input[0]; |
| 78 | + if (_typeof(value) === object && value) { |
| 79 | + var lazy = []; |
| 80 | + var revive = resolver(input, lazy, new Set(), $); |
| 81 | + value = revive(value); |
| 82 | + var i = 0; |
| 83 | + while (i < lazy.length) { |
| 84 | + // it could be a lazy.shift() but that's costly |
| 85 | + var _lazy$i = lazy[i++], |
| 86 | + o = _lazy$i.o, |
| 87 | + k = _lazy$i.k, |
| 88 | + r = _lazy$i.r; |
| 89 | + o[k] = $.call(o, k, revive(r)); |
| 90 | + } |
| 91 | + } |
| 92 | + return $.call({ |
| 93 | + '': value |
| 94 | + }, '', value); |
| 95 | + }; |
| 96 | + |
| 97 | + /** |
| 98 | + * Converts a JS value into a specialized flatted string. |
| 99 | + * @param {any} value |
| 100 | + * @param {((this: any, key: string, value: any) => any) | (string | number)[] | null | undefined} [replacer] |
| 101 | + * @param {string | number | undefined} [space] |
| 102 | + * @returns {string} |
| 103 | + */ |
| 104 | + var stringify = function stringify(value, replacer, space) { |
| 105 | + var $ = replacer && _typeof(replacer) === object ? function (k, v) { |
| 106 | + return k === '' || -1 < replacer.indexOf(k) ? v : void 0; |
| 107 | + } : replacer || noop; |
| 108 | + var known = new Map(); |
| 109 | + var input = []; |
| 110 | + var output = []; |
| 111 | + var i = +set(known, input, $.call({ |
| 112 | + '': value |
| 113 | + }, '', value)); |
| 114 | + var firstRun = !i; |
| 115 | + while (i < input.length) { |
| 116 | + firstRun = true; |
| 117 | + output[i] = $stringify(input[i++], replace, space); |
| 118 | + } |
| 119 | + return '[' + output.join(',') + ']'; |
| 120 | + function replace(key, value) { |
| 121 | + if (firstRun) { |
| 122 | + firstRun = !firstRun; |
| 123 | + return value; |
| 124 | + } |
| 125 | + var after = $.call(this, key, value); |
| 126 | + switch (_typeof(after)) { |
| 127 | + case object: |
| 128 | + if (after === null) return after; |
| 129 | + case primitive: |
| 130 | + return known.get(after) || set(known, input, after); |
| 131 | + } |
| 132 | + return after; |
| 133 | + } |
| 134 | + }; |
| 135 | + |
| 136 | + /** |
| 137 | + * Converts a generic value into a JSON serializable object without losing recursion. |
| 138 | + * @param {any} value |
| 139 | + * @returns {any} |
| 140 | + */ |
| 141 | + var toJSON = function toJSON(value) { |
| 142 | + return $parse(stringify(value)); |
| 143 | + }; |
| 144 | + |
| 145 | + /** |
| 146 | + * Converts a previously serialized object with recursion into a recursive one. |
| 147 | + * @param {any} value |
| 148 | + * @returns {any} |
| 149 | + */ |
| 150 | + var fromJSON = function fromJSON(value) { |
| 151 | + return parse($stringify(value)); |
| 152 | + }; |
| 153 | + |
| 154 | + exports.fromJSON = fromJSON; |
| 155 | + exports.parse = parse; |
| 156 | + exports.stringify = stringify; |
| 157 | + exports.toJSON = toJSON; |
| 158 | + |
| 159 | + return exports; |
| 160 | + |
| 161 | +})({}); |
0 commit comments