1const types = [ 2 ts({ 3 is: (val) => val === void 0, 4 match: (str) => str === "!undefined", 5 serialize: () => "!undefined", 6 deserialize: () => void 0 7 }), 8 ts({ 9 is: (val) => val === Infinity, 10 match: (str) => str === "!Infinity", 11 serialize: () => "!Infinity", 12 deserialize: () => Infinity 13 }), 14 ts({ 15 is: (val) => val === -Infinity, 16 match: (str) => str === "!-Infinity", 17 serialize: () => "!-Infinity", 18 deserialize: () => -Infinity 19 }), 20 ts({ 21 is: (val) => typeof val === "number" && isNaN(val), 22 match: (str) => str === "!NaN", 23 serialize: () => "!NaN", 24 deserialize: () => NaN 25 }), 26 ts({ 27 is: (val) => val instanceof Date, 28 match: (str) => str.startsWith("!Date:"), 29 serialize: (val) => "!Date:" + val.toISOString(), 30 deserialize: (str) => new Date(str.slice("!Date:".length)) 31 }), 32 ts({ 33 is: (val) => typeof val === "bigint", 34 match: (str) => str.startsWith("!BigInt:"), 35 serialize: (val) => "!BigInt:" + val.toString(), 36 deserialize: (str) => { 37 if (typeof BigInt === "undefined") { 38 throw new Error("Your JavaScript environement does not support BigInt. Consider adding a polyfill."); 39 } 40 return BigInt(str.slice("!BigInt:".length)); 41 } 42 }), 43 ts({ 44 is: (val) => val instanceof RegExp, 45 match: (str) => str.startsWith("!RegExp:"),
46 serialize: (val) => "!RegExp:" + val.toString(), 47 deserialize: (str) => { 48 str = str.slice("!RegExp:".length); 49 const args = str.match(/\/(.*)\/(.*)?/); 50 const pattern = args[1]; 51 const flags = args[2]; 52 return new RegExp(pattern, flags); 53 } 54 }), 55 ts({ 56 is: (val) => val instanceof Map, 57 match: (str) => str.startsWith("!Map:"), 58 serialize: (val, serializer) => "!Map:" + serializer(Array.from(val.entries())), 59 deserialize: (str, deserializer) => new Map(deserializer(str.slice("!Map:".length))) 60 }), 61 ts({ 62 is: (val) => val instanceof Set, 63 match: (str) => str.startsWith("!Set:"), 64 serialize: (val, serializer) => "!Set:" + serializer(Array.from(val.values())), 65 deserialize: (str, deserializer) => new Set(deserializer(str.slice("!Set:".length))) 66 }), 67 // Avoid collisions with the special strings defined above 68 ts({ 69 is: (val) => typeof val === "string" && val.startsWith("!"), 70 match: (str) => str.startsWith("!"), 71 serialize: (val) => "!" + val, 72 deserialize: (str) => str.slice(1) 73 }) 74]; 75function ts(t) { 76 return t; 77} 78function parse(str) { 79 const value = JSON.parse(str); 80 return parseTransform(value); 81} 82function parseTransform(value) { 83 if (typeof value === "string") { 84 return reviver(value); 85 } 86 if ( 87 // Also matches arrays 88 typeof value === "object" && value !== null 89 ) { 90 Object.entries(value).forEach(([key, val]) => { 91 value[key] = parseTransform(val); 92 }); 93 } 94 return value; 95} 96function reviver(value) { 97 for (const { match, deserialize } of types) { 98 if (match(value)) { 99 return deserialize(value, parse); 100 } 101 } 102 return value; 103} 104export { 105 parse as a, 106 parseTransform as p 107};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.