usage-board 3.0.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +1 -1
- package/dist/public/_nuxt/{y3weNNd-.js → B6C9KBQ4.js} +2 -2
- package/dist/public/_nuxt/Bv6agYS5.js +119 -0
- package/dist/public/_nuxt/BvRyOET7.js +1 -0
- package/dist/public/_nuxt/CMWftE4h.js +1 -0
- package/dist/public/_nuxt/{Be3rizqy.js → COIbUy5w.js} +1 -1
- package/dist/public/_nuxt/CXLmM1yO.js +25 -0
- package/dist/public/_nuxt/DFqWEFN4.js +1 -0
- package/dist/public/_nuxt/DUoLvn3A.js +6 -0
- package/dist/public/_nuxt/D_W11Quh.js +21 -0
- package/dist/public/_nuxt/DgKrPjze.js +4 -0
- package/dist/public/_nuxt/DkxY2YMp.js +1 -0
- package/dist/public/_nuxt/{7Dy4NLP8.js → DtbPvE6R.js} +24 -24
- package/dist/public/_nuxt/HiqUua3-.js +1 -0
- package/dist/public/_nuxt/builds/latest.json +1 -1
- package/dist/public/_nuxt/builds/meta/6f98f1cb-266c-475e-a249-dad346a55f24.json +1 -0
- package/dist/public/_nuxt/entry.vHfFzkyD.css +1 -0
- package/dist/public/_nuxt/error-404.CFBEg71j.css +1 -0
- package/dist/public/_nuxt/error-500.BqCnH31G.css +1 -0
- package/dist/public/_nuxt/uHQwCIHg.js +1 -0
- package/dist/server/chunks/_/error-500.mjs +2 -20
- package/dist/server/chunks/build/client.precomputed.mjs +1 -1
- package/dist/server/chunks/nitro/nitro.mjs +2303 -3614
- package/dist/server/chunks/routes/api/analysis/agent/session.json.mjs +21 -0
- package/dist/server/chunks/routes/api/analysis/agent/token.json.mjs +24 -0
- package/dist/server/chunks/routes/api/analysis/cache.json.mjs +24 -0
- package/dist/server/chunks/routes/api/analysis/hot-project.json.mjs +24 -0
- package/dist/server/chunks/routes/api/analysis/model.json.mjs +24 -0
- package/dist/server/chunks/routes/api/analysis/overview-cards.json.mjs +24 -0
- package/dist/server/chunks/routes/api/analysis/session.json.mjs +21 -0
- package/dist/server/chunks/routes/api/analysis/token/daily.json.mjs +21 -0
- package/dist/server/chunks/routes/api/analysis/token.json.mjs +24 -0
- package/dist/server/chunks/routes/api/payload.json.mjs +9 -10
- package/dist/server/chunks/routes/api/projects/_project/modules.get.mjs +9 -10
- package/dist/server/chunks/routes/api/projects/catalog.get.mjs +9 -10
- package/dist/server/chunks/routes/renderer.mjs +17 -39183
- package/dist/server/chunks/routes/ws.mjs +9 -10
- package/dist/server/index.mjs +9 -10
- package/dist/server/node_modules/@babel/parser/lib/index.js +14582 -0
- package/dist/server/node_modules/@babel/parser/package.json +50 -0
- package/dist/server/node_modules/@iconify/utils/lib/colors/index.js +292 -0
- package/dist/server/node_modules/@iconify/utils/lib/colors/keywords.js +702 -0
- package/dist/server/node_modules/@iconify/utils/lib/css/common.js +76 -0
- package/dist/server/node_modules/@iconify/utils/lib/css/format.js +40 -0
- package/dist/server/node_modules/@iconify/utils/lib/css/icon.js +52 -0
- package/dist/server/node_modules/@iconify/utils/lib/css/icons.js +133 -0
- package/dist/server/node_modules/@iconify/utils/lib/customisations/bool.js +20 -0
- package/dist/server/node_modules/@iconify/utils/lib/customisations/defaults.js +15 -0
- package/dist/server/node_modules/@iconify/utils/lib/customisations/flip.js +18 -0
- package/dist/server/node_modules/@iconify/utils/lib/customisations/merge.js +18 -0
- package/dist/server/node_modules/@iconify/utils/lib/customisations/rotate.js +31 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/cleanup.js +80 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/convert.js +102 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/data.js +29 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/format.js +60 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/parse.js +50 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/regex/base.js +204 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/regex/create.js +35 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/regex/numbers.js +134 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/regex/similar.js +167 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/regex/tree.js +81 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/replace/find.js +94 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/replace/replace.js +28 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/test/components.js +78 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/test/missing.js +68 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/test/name.js +47 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/test/parse.js +105 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/test/similar.js +38 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/test/tree.js +94 -0
- package/dist/server/node_modules/@iconify/utils/lib/emoji/test/variations.js +64 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon/defaults.js +26 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon/merge.js +18 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon/name.js +58 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon/square.js +34 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon/transformations.js +13 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon-set/convert-info.js +126 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon-set/expand.js +21 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon-set/get-icon.js +27 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon-set/get-icons.js +38 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon-set/minify.js +93 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon-set/parse.js +48 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon-set/tree.js +24 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon-set/validate-basic.js +44 -0
- package/dist/server/node_modules/@iconify/utils/lib/icon-set/validate.js +125 -0
- package/dist/server/node_modules/@iconify/utils/lib/index.js +53 -0
- package/dist/server/node_modules/@iconify/utils/lib/loader/custom.js +32 -0
- package/dist/server/node_modules/@iconify/utils/lib/loader/loader.js +28 -0
- package/dist/server/node_modules/@iconify/utils/lib/loader/modern.js +42 -0
- package/dist/server/node_modules/@iconify/utils/lib/loader/utils.js +63 -0
- package/dist/server/node_modules/@iconify/utils/lib/misc/objects.js +27 -0
- package/dist/server/node_modules/@iconify/utils/lib/misc/strings.js +27 -0
- package/dist/server/node_modules/@iconify/utils/lib/misc/title.js +10 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/build.js +115 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/defs.js +32 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/encode-svg-for-css.js +15 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/html.js +10 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/id.js +42 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/inner-html.js +23 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/parse.js +69 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/pretty.js +55 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/size.js +28 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/trim.js +8 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/url.js +23 -0
- package/dist/server/node_modules/@iconify/utils/lib/svg/viewbox.js +9 -0
- package/dist/server/node_modules/@iconify/utils/package.json +118 -0
- package/dist/server/node_modules/@lonewolfyx/utils/dist/index.mjs +63 -0
- package/dist/server/node_modules/@lonewolfyx/utils/package.json +64 -0
- package/dist/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6763 -0
- package/dist/server/node_modules/@vue/compiler-core/package.json +58 -0
- package/dist/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +689 -0
- package/dist/server/node_modules/@vue/compiler-dom/package.json +57 -0
- package/dist/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1413 -0
- package/dist/server/node_modules/@vue/compiler-ssr/package.json +34 -0
- package/dist/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1877 -0
- package/dist/server/node_modules/@vue/reactivity/package.json +55 -0
- package/dist/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +6856 -0
- package/dist/server/node_modules/@vue/runtime-core/package.json +52 -0
- package/dist/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1796 -0
- package/dist/server/node_modules/@vue/runtime-dom/package.json +60 -0
- package/dist/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +883 -0
- package/dist/server/node_modules/@vue/server-renderer/package.json +55 -0
- package/dist/server/{chunks/_/shared.cjs.prod.mjs → node_modules/@vue/shared/dist/shared.cjs.prod.js} +76 -81
- package/dist/server/node_modules/@vue/shared/package.json +47 -0
- package/dist/server/node_modules/better-sqlite3/build/Release/better_sqlite3.node +0 -0
- package/dist/server/node_modules/better-sqlite3/lib/database.js +90 -0
- package/dist/server/node_modules/better-sqlite3/lib/index.js +3 -0
- package/dist/server/node_modules/better-sqlite3/lib/methods/aggregate.js +43 -0
- package/dist/server/node_modules/better-sqlite3/lib/methods/backup.js +67 -0
- package/dist/server/node_modules/better-sqlite3/lib/methods/function.js +31 -0
- package/dist/server/node_modules/better-sqlite3/lib/methods/inspect.js +7 -0
- package/dist/server/node_modules/better-sqlite3/lib/methods/pragma.js +12 -0
- package/dist/server/node_modules/better-sqlite3/lib/methods/serialize.js +16 -0
- package/dist/server/node_modules/better-sqlite3/lib/methods/table.js +189 -0
- package/dist/server/node_modules/better-sqlite3/lib/methods/transaction.js +78 -0
- package/dist/server/node_modules/better-sqlite3/lib/methods/wrappers.js +54 -0
- package/dist/server/node_modules/better-sqlite3/lib/sqlite-error.js +20 -0
- package/dist/server/node_modules/better-sqlite3/lib/util.js +12 -0
- package/dist/server/node_modules/better-sqlite3/package.json +59 -0
- package/dist/server/node_modules/bindings/bindings.js +221 -0
- package/dist/server/node_modules/bindings/package.json +28 -0
- package/dist/server/node_modules/chokidar/handler.js +632 -0
- package/dist/server/node_modules/chokidar/index.js +822 -0
- package/dist/server/node_modules/chokidar/package.json +63 -0
- package/dist/server/{chunks/_ → node_modules/consola/dist/chunks}/prompt.mjs +2 -1
- package/dist/server/node_modules/consola/dist/core.mjs +512 -0
- package/dist/server/node_modules/consola/dist/index.mjs +651 -0
- package/dist/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
- package/dist/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
- package/dist/server/node_modules/consola/package.json +136 -0
- package/dist/server/node_modules/devalue/index.js +4 -0
- package/dist/server/node_modules/devalue/package.json +40 -0
- package/dist/server/node_modules/devalue/src/base64.js +60 -0
- package/dist/server/node_modules/devalue/src/constants.js +7 -0
- package/dist/server/node_modules/devalue/src/parse.js +268 -0
- package/dist/server/node_modules/devalue/src/stringify.js +335 -0
- package/dist/server/node_modules/devalue/src/uneval.js +552 -0
- package/dist/server/node_modules/devalue/src/utils.js +144 -0
- package/dist/server/node_modules/entities/dist/commonjs/decode-codepoint.js +77 -0
- package/dist/server/node_modules/entities/dist/commonjs/decode.js +568 -0
- package/dist/server/node_modules/entities/dist/commonjs/generated/decode-data-html.js +7 -0
- package/dist/server/node_modules/entities/dist/commonjs/generated/decode-data-xml.js +7 -0
- package/dist/server/node_modules/entities/dist/commonjs/internal/bin-trie-flags.js +21 -0
- package/dist/server/node_modules/entities/dist/commonjs/internal/decode-shared.js +31 -0
- package/dist/server/node_modules/entities/dist/commonjs/package.json +3 -0
- package/dist/server/node_modules/entities/package.json +120 -0
- package/dist/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
- package/dist/server/node_modules/estree-walker/package.json +37 -0
- package/dist/server/node_modules/file-uri-to-path/index.js +66 -0
- package/dist/server/node_modules/file-uri-to-path/package.json +32 -0
- package/dist/server/node_modules/glob/dist/esm/index.min.js +4 -0
- package/dist/server/node_modules/glob/dist/esm/package.json +3 -0
- package/dist/server/node_modules/glob/package.json +98 -0
- package/dist/server/node_modules/hookable/dist/index.mjs +257 -0
- package/dist/server/node_modules/hookable/package.json +53 -0
- package/dist/server/node_modules/md5-typescript/dist/bundles/bundle.umd.js +208 -0
- package/dist/server/node_modules/md5-typescript/package.json +31 -0
- package/dist/server/node_modules/path-type/index.js +42 -0
- package/dist/server/node_modules/path-type/package.json +51 -0
- package/dist/server/node_modules/readdirp/index.js +272 -0
- package/dist/server/node_modules/readdirp/package.json +66 -0
- package/dist/server/node_modules/source-map-js/lib/array-set.js +121 -0
- package/dist/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
- package/dist/server/node_modules/source-map-js/lib/base64.js +67 -0
- package/dist/server/node_modules/source-map-js/lib/binary-search.js +111 -0
- package/dist/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
- package/dist/server/node_modules/source-map-js/lib/quick-sort.js +132 -0
- package/dist/server/node_modules/source-map-js/lib/source-map-consumer.js +1188 -0
- package/dist/server/node_modules/source-map-js/lib/source-map-generator.js +444 -0
- package/dist/server/node_modules/source-map-js/lib/source-node.js +413 -0
- package/dist/server/node_modules/source-map-js/lib/util.js +594 -0
- package/dist/server/node_modules/source-map-js/package.json +71 -0
- package/dist/server/node_modules/source-map-js/source-map.js +8 -0
- package/dist/server/node_modules/ufo/dist/index.mjs +645 -0
- package/dist/server/node_modules/ufo/package.json +48 -0
- package/dist/server/node_modules/unhead/dist/parser.mjs +508 -0
- package/dist/server/node_modules/unhead/dist/plugins.mjs +101 -0
- package/dist/server/node_modules/unhead/dist/server.mjs +180 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.B5FWS6X0.mjs +207 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.BYvz9V1x.mjs +43 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.CbpEuj3y.mjs +71 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.Ct24BOby.mjs +182 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.D4vSFytZ.mjs +236 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.DQc16pHI.mjs +196 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.TxTMM7cM.mjs +166 -0
- package/dist/server/node_modules/unhead/dist/shared/unhead.yem5I2v_.mjs +38 -0
- package/dist/server/node_modules/unhead/dist/utils.mjs +5 -0
- package/dist/server/node_modules/unhead/package.json +105 -0
- package/dist/server/node_modules/vue/dist/vue.cjs.js +80 -0
- package/dist/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
- package/dist/server/node_modules/vue/index.js +7 -0
- package/dist/server/node_modules/vue/index.mjs +1 -0
- package/dist/server/node_modules/vue/package.json +112 -0
- package/dist/server/node_modules/vue/server-renderer/index.mjs +1 -0
- package/dist/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +301 -0
- package/dist/server/node_modules/vue-bundle-renderer/package.json +55 -0
- package/dist/server/package.json +37 -0
- package/package.json +3 -1
- package/dist/public/_nuxt/B-VlGWDb.js +0 -21
- package/dist/public/_nuxt/C0azgqnZ.js +0 -1
- package/dist/public/_nuxt/CMNdiQCa.js +0 -1
- package/dist/public/_nuxt/CPuXQJE_.js +0 -1
- package/dist/public/_nuxt/DenksPSi.js +0 -119
- package/dist/public/_nuxt/Dkya5WaL.js +0 -9
- package/dist/public/_nuxt/HN9OZyaQ.js +0 -25
- package/dist/public/_nuxt/JtK-nXxy.js +0 -1
- package/dist/public/_nuxt/builds/meta/37e8bb21-a086-45bf-93dc-47eeeada7299.json +0 -1
- package/dist/public/_nuxt/entry.r-q4oQC0.css +0 -1
- package/dist/public/_nuxt/error-404.B0EXnOcv.css +0 -1
- package/dist/public/_nuxt/error-500.CnSNZoEG.css +0 -1
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DevalueError,
|
|
3
|
+
enumerable_symbols,
|
|
4
|
+
escaped,
|
|
5
|
+
get_type,
|
|
6
|
+
is_plain_object,
|
|
7
|
+
is_primitive,
|
|
8
|
+
stringify_key,
|
|
9
|
+
stringify_string,
|
|
10
|
+
valid_array_indices
|
|
11
|
+
} from './utils.js';
|
|
12
|
+
|
|
13
|
+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
|
|
14
|
+
const unsafe_chars = /[<\b\f\n\r\t\0\u2028\u2029]/g;
|
|
15
|
+
const reserved =
|
|
16
|
+
/^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Turn a value into the JavaScript that creates an equivalent value
|
|
20
|
+
* @param {any} value
|
|
21
|
+
* @param {(value: any, uneval: (value: any) => string) => string | void} [replacer]
|
|
22
|
+
*/
|
|
23
|
+
export function uneval(value, replacer) {
|
|
24
|
+
const counts = new Map();
|
|
25
|
+
|
|
26
|
+
/** @type {string[]} */
|
|
27
|
+
const keys = [];
|
|
28
|
+
|
|
29
|
+
const custom = new Map();
|
|
30
|
+
|
|
31
|
+
/** @param {any} thing */
|
|
32
|
+
function walk(thing) {
|
|
33
|
+
if (!is_primitive(thing)) {
|
|
34
|
+
if (counts.has(thing)) {
|
|
35
|
+
counts.set(thing, counts.get(thing) + 1);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
counts.set(thing, 1);
|
|
40
|
+
|
|
41
|
+
if (replacer) {
|
|
42
|
+
const str = replacer(thing, (value) => uneval(value, replacer));
|
|
43
|
+
|
|
44
|
+
if (typeof str === 'string') {
|
|
45
|
+
custom.set(thing, str);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (typeof thing === 'function') {
|
|
51
|
+
throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const type = get_type(thing);
|
|
55
|
+
|
|
56
|
+
switch (type) {
|
|
57
|
+
case 'Number':
|
|
58
|
+
case 'BigInt':
|
|
59
|
+
case 'String':
|
|
60
|
+
case 'Boolean':
|
|
61
|
+
case 'Date':
|
|
62
|
+
case 'RegExp':
|
|
63
|
+
case 'URL':
|
|
64
|
+
case 'URLSearchParams':
|
|
65
|
+
return;
|
|
66
|
+
|
|
67
|
+
case 'Array':
|
|
68
|
+
/** @type {any[]} */ (thing).forEach((value, i) => {
|
|
69
|
+
keys.push(`[${i}]`);
|
|
70
|
+
walk(value);
|
|
71
|
+
keys.pop();
|
|
72
|
+
});
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case 'Set':
|
|
76
|
+
Array.from(thing).forEach(walk);
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case 'Map':
|
|
80
|
+
for (const [key, value] of thing) {
|
|
81
|
+
keys.push(`.get(${is_primitive(key) ? stringify_primitive(key) : '...'})`);
|
|
82
|
+
walk(value);
|
|
83
|
+
keys.pop();
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
|
|
87
|
+
case 'Int8Array':
|
|
88
|
+
case 'Uint8Array':
|
|
89
|
+
case 'Uint8ClampedArray':
|
|
90
|
+
case 'Int16Array':
|
|
91
|
+
case 'Uint16Array':
|
|
92
|
+
case 'Float16Array':
|
|
93
|
+
case 'Int32Array':
|
|
94
|
+
case 'Uint32Array':
|
|
95
|
+
case 'Float32Array':
|
|
96
|
+
case 'Float64Array':
|
|
97
|
+
case 'BigInt64Array':
|
|
98
|
+
case 'BigUint64Array':
|
|
99
|
+
case 'DataView':
|
|
100
|
+
walk(thing.buffer);
|
|
101
|
+
return;
|
|
102
|
+
|
|
103
|
+
case 'ArrayBuffer':
|
|
104
|
+
return;
|
|
105
|
+
|
|
106
|
+
case 'Temporal.Duration':
|
|
107
|
+
case 'Temporal.Instant':
|
|
108
|
+
case 'Temporal.PlainDate':
|
|
109
|
+
case 'Temporal.PlainTime':
|
|
110
|
+
case 'Temporal.PlainDateTime':
|
|
111
|
+
case 'Temporal.PlainMonthDay':
|
|
112
|
+
case 'Temporal.PlainYearMonth':
|
|
113
|
+
case 'Temporal.ZonedDateTime':
|
|
114
|
+
return;
|
|
115
|
+
|
|
116
|
+
default:
|
|
117
|
+
if (!is_plain_object(thing)) {
|
|
118
|
+
throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (enumerable_symbols(thing).length > 0) {
|
|
122
|
+
throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (const key of Object.keys(thing)) {
|
|
126
|
+
if (key === '__proto__') {
|
|
127
|
+
throw new DevalueError(
|
|
128
|
+
`Cannot stringify objects with __proto__ keys`,
|
|
129
|
+
keys,
|
|
130
|
+
thing,
|
|
131
|
+
value
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
keys.push(stringify_key(key));
|
|
136
|
+
walk(thing[key]);
|
|
137
|
+
keys.pop();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} else if (typeof thing === 'symbol') {
|
|
141
|
+
throw new DevalueError(`Cannot stringify a Symbol primitive`, keys, thing, value);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
walk(value);
|
|
146
|
+
|
|
147
|
+
const names = new Map();
|
|
148
|
+
|
|
149
|
+
Array.from(counts)
|
|
150
|
+
.filter((entry) => entry[1] > 1)
|
|
151
|
+
.sort((a, b) => b[1] - a[1])
|
|
152
|
+
.forEach((entry, i) => {
|
|
153
|
+
names.set(entry[0], get_name(i));
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param {any} thing
|
|
158
|
+
* @returns {string}
|
|
159
|
+
*/
|
|
160
|
+
function stringify(thing) {
|
|
161
|
+
if (names.has(thing)) {
|
|
162
|
+
return names.get(thing);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (is_primitive(thing)) {
|
|
166
|
+
return stringify_primitive(thing);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (custom.has(thing)) {
|
|
170
|
+
return custom.get(thing);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const type = get_type(thing);
|
|
174
|
+
|
|
175
|
+
switch (type) {
|
|
176
|
+
case 'Number':
|
|
177
|
+
case 'String':
|
|
178
|
+
case 'Boolean':
|
|
179
|
+
case 'BigInt':
|
|
180
|
+
return `Object(${stringify(thing.valueOf())})`;
|
|
181
|
+
|
|
182
|
+
case 'RegExp':
|
|
183
|
+
const { source, flags } = thing;
|
|
184
|
+
return flags
|
|
185
|
+
? `new RegExp(${stringify_string(source)},"${flags}")`
|
|
186
|
+
: `new RegExp(${stringify_string(source)})`;
|
|
187
|
+
|
|
188
|
+
case 'Date':
|
|
189
|
+
return `new Date(${thing.getTime()})`;
|
|
190
|
+
|
|
191
|
+
case 'URL':
|
|
192
|
+
return `new URL(${stringify_string(thing.toString())})`;
|
|
193
|
+
|
|
194
|
+
case 'URLSearchParams':
|
|
195
|
+
return `new URLSearchParams(${stringify_string(thing.toString())})`;
|
|
196
|
+
|
|
197
|
+
case 'Array': {
|
|
198
|
+
// For dense arrays (no holes), we iterate normally.
|
|
199
|
+
// When we encounter the first hole, we call Object.keys
|
|
200
|
+
// to determine the sparseness, then decide between:
|
|
201
|
+
// - Array literal with holes: [,"a",,] (default)
|
|
202
|
+
// - Object.assign: Object.assign(Array(n),{...}) (for very sparse arrays)
|
|
203
|
+
// Only the Object.assign path avoids iterating every slot, which
|
|
204
|
+
// is what protects against the DoS of e.g. `arr[1000000] = 1`.
|
|
205
|
+
let has_holes = false;
|
|
206
|
+
|
|
207
|
+
let result = '[';
|
|
208
|
+
|
|
209
|
+
for (let i = 0; i < thing.length; i += 1) {
|
|
210
|
+
if (i > 0) result += ',';
|
|
211
|
+
|
|
212
|
+
if (Object.hasOwn(thing, i)) {
|
|
213
|
+
result += stringify(thing[i]);
|
|
214
|
+
} else if (!has_holes) {
|
|
215
|
+
// Decide between array literal and Object.assign.
|
|
216
|
+
//
|
|
217
|
+
// Array literal: holes are consecutive commas.
|
|
218
|
+
// For example, [, "a", ,] is written as [,"a",,].
|
|
219
|
+
// Each hole costs 1 char (a comma).
|
|
220
|
+
//
|
|
221
|
+
// Object.assign: populated indices are listed explicitly.
|
|
222
|
+
// For example, [, "a", ,] would be written as
|
|
223
|
+
// Object.assign(Array(3),{1:"a"}). This avoids paying
|
|
224
|
+
// per-hole, but has a large fixed overhead for the
|
|
225
|
+
// "Object.assign(Array(n),{...})" wrapper, and each
|
|
226
|
+
// element costs extra chars for its index and colon.
|
|
227
|
+
//
|
|
228
|
+
// The serialized values are the same size either way, so
|
|
229
|
+
// the choice comes down to the structural overhead:
|
|
230
|
+
//
|
|
231
|
+
// Array literal overhead:
|
|
232
|
+
// 1 char per element or hole (comma separators)
|
|
233
|
+
// + 2 chars for "[" and "]"
|
|
234
|
+
// = L + 2
|
|
235
|
+
//
|
|
236
|
+
// Object.assign overhead:
|
|
237
|
+
// "Object.assign(Array(" — 20 chars
|
|
238
|
+
// + length — d chars
|
|
239
|
+
// + "),{" — 3 chars
|
|
240
|
+
// + for each populated element:
|
|
241
|
+
// index + ":" + "," — (d + 2) chars
|
|
242
|
+
// + "})" — 2 chars
|
|
243
|
+
// = (25 + d) + P * (d + 2)
|
|
244
|
+
//
|
|
245
|
+
// where L is the array length, P is the number of
|
|
246
|
+
// populated elements, and d is the number of digits
|
|
247
|
+
// in L (an upper bound on the digits in any index).
|
|
248
|
+
//
|
|
249
|
+
// Object.assign is cheaper when:
|
|
250
|
+
// (25 + d) + P * (d + 2) < L + 2
|
|
251
|
+
const populated_keys = valid_array_indices(/** @type {any[]} */ (thing));
|
|
252
|
+
const population = populated_keys.length;
|
|
253
|
+
const d = String(thing.length).length;
|
|
254
|
+
|
|
255
|
+
const hole_cost = thing.length + 2;
|
|
256
|
+
const sparse_cost = 25 + d + population * (d + 2);
|
|
257
|
+
|
|
258
|
+
if (hole_cost > sparse_cost) {
|
|
259
|
+
const entries = populated_keys.map((k) => `${k}:${stringify(thing[k])}`).join(',');
|
|
260
|
+
return `Object.assign(Array(${thing.length}),{${entries}})`;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Re-process this index as a hole in the array literal
|
|
264
|
+
has_holes = true;
|
|
265
|
+
i -= 1;
|
|
266
|
+
}
|
|
267
|
+
// else: already decided on array literal, hole is just an empty slot
|
|
268
|
+
// (the comma separator is all we need — no content for this position)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const tail = thing.length === 0 || thing.length - 1 in thing ? '' : ',';
|
|
272
|
+
return result + tail + ']';
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
case 'Set':
|
|
276
|
+
case 'Map':
|
|
277
|
+
return `new ${type}([${Array.from(thing).map(stringify).join(',')}])`;
|
|
278
|
+
|
|
279
|
+
case 'Int8Array':
|
|
280
|
+
case 'Uint8Array':
|
|
281
|
+
case 'Uint8ClampedArray':
|
|
282
|
+
case 'Int16Array':
|
|
283
|
+
case 'Uint16Array':
|
|
284
|
+
case 'Float16Array':
|
|
285
|
+
case 'Int32Array':
|
|
286
|
+
case 'Uint32Array':
|
|
287
|
+
case 'Float32Array':
|
|
288
|
+
case 'Float64Array':
|
|
289
|
+
case 'BigInt64Array':
|
|
290
|
+
case 'BigUint64Array': {
|
|
291
|
+
let str = `new ${type}`;
|
|
292
|
+
|
|
293
|
+
if (!names.has(thing.buffer)) {
|
|
294
|
+
const array = new thing.constructor(thing.buffer);
|
|
295
|
+
str += `([${array}])`;
|
|
296
|
+
} else {
|
|
297
|
+
str += `(${stringify(thing.buffer)})`;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// handle subarrays
|
|
301
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
302
|
+
const start = thing.byteOffset / thing.BYTES_PER_ELEMENT;
|
|
303
|
+
const end = start + thing.length;
|
|
304
|
+
str += `.subarray(${start},${end})`;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return str;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
case 'DataView': {
|
|
311
|
+
let str = `new DataView`;
|
|
312
|
+
|
|
313
|
+
if (!names.has(thing.buffer)) {
|
|
314
|
+
str += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`;
|
|
315
|
+
} else {
|
|
316
|
+
str += `(${stringify(thing.buffer)}`;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// handle subviews
|
|
320
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
321
|
+
str += `,${thing.startOffset},${thing.byteLength}`;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return str + ')';
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
case 'ArrayBuffer': {
|
|
328
|
+
const ui8 = new Uint8Array(thing);
|
|
329
|
+
return `new Uint8Array([${ui8.toString()}]).buffer`;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
case 'Temporal.Duration':
|
|
333
|
+
case 'Temporal.Instant':
|
|
334
|
+
case 'Temporal.PlainDate':
|
|
335
|
+
case 'Temporal.PlainTime':
|
|
336
|
+
case 'Temporal.PlainDateTime':
|
|
337
|
+
case 'Temporal.PlainMonthDay':
|
|
338
|
+
case 'Temporal.PlainYearMonth':
|
|
339
|
+
case 'Temporal.ZonedDateTime':
|
|
340
|
+
return `${type}.from(${stringify_string(thing.toString())})`;
|
|
341
|
+
|
|
342
|
+
default:
|
|
343
|
+
const keys = Object.keys(thing);
|
|
344
|
+
const obj = keys.map((key) => `${safe_key(key)}:${stringify(thing[key])}`).join(',');
|
|
345
|
+
const proto = Object.getPrototypeOf(thing);
|
|
346
|
+
if (proto === null) {
|
|
347
|
+
return keys.length > 0 ? `{${obj},__proto__:null}` : `{__proto__:null}`;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return `{${obj}}`;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const str = stringify(value);
|
|
355
|
+
|
|
356
|
+
if (names.size) {
|
|
357
|
+
/** @type {string[]} */
|
|
358
|
+
const params = [];
|
|
359
|
+
|
|
360
|
+
/** @type {string[]} */
|
|
361
|
+
const statements = [];
|
|
362
|
+
|
|
363
|
+
/** @type {string[]} */
|
|
364
|
+
const values = [];
|
|
365
|
+
|
|
366
|
+
names.forEach((name, thing) => {
|
|
367
|
+
params.push(name);
|
|
368
|
+
|
|
369
|
+
if (custom.has(thing)) {
|
|
370
|
+
values.push(/** @type {string} */ (custom.get(thing)));
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (is_primitive(thing)) {
|
|
375
|
+
values.push(stringify_primitive(thing));
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const type = get_type(thing);
|
|
380
|
+
|
|
381
|
+
switch (type) {
|
|
382
|
+
case 'Number':
|
|
383
|
+
case 'String':
|
|
384
|
+
case 'Boolean':
|
|
385
|
+
case 'BigInt':
|
|
386
|
+
values.push(`Object(${stringify(thing.valueOf())})`);
|
|
387
|
+
break;
|
|
388
|
+
|
|
389
|
+
case 'RegExp':
|
|
390
|
+
const { source, flags } = thing;
|
|
391
|
+
const regexp = flags
|
|
392
|
+
? `new RegExp(${stringify_string(source)},"${flags}")`
|
|
393
|
+
: `new RegExp(${stringify_string(source)})`
|
|
394
|
+
values.push(regexp);
|
|
395
|
+
break;
|
|
396
|
+
|
|
397
|
+
case 'Date':
|
|
398
|
+
values.push(`new Date(${thing.getTime()})`);
|
|
399
|
+
break;
|
|
400
|
+
|
|
401
|
+
case 'URL':
|
|
402
|
+
values.push(`new URL(${stringify_string(thing.toString())})`);
|
|
403
|
+
break;
|
|
404
|
+
|
|
405
|
+
case 'URLSearchParams':
|
|
406
|
+
values.push(`new URLSearchParams(${stringify_string(thing.toString())})`);
|
|
407
|
+
break;
|
|
408
|
+
|
|
409
|
+
case 'Array':
|
|
410
|
+
values.push(`Array(${thing.length})`);
|
|
411
|
+
/** @type {any[]} */ (thing).forEach((v, i) => {
|
|
412
|
+
statements.push(`${name}[${i}]=${stringify(v)}`);
|
|
413
|
+
});
|
|
414
|
+
break;
|
|
415
|
+
|
|
416
|
+
case 'Set':
|
|
417
|
+
values.push(`new Set`);
|
|
418
|
+
statements.push(
|
|
419
|
+
`${name}.${Array.from(thing)
|
|
420
|
+
.map((v) => `add(${stringify(v)})`)
|
|
421
|
+
.join('.')}`
|
|
422
|
+
);
|
|
423
|
+
break;
|
|
424
|
+
|
|
425
|
+
case 'Map':
|
|
426
|
+
values.push(`new Map`);
|
|
427
|
+
statements.push(
|
|
428
|
+
`${name}.${Array.from(thing)
|
|
429
|
+
.map(([k, v]) => `set(${stringify(k)}, ${stringify(v)})`)
|
|
430
|
+
.join('.')}`
|
|
431
|
+
);
|
|
432
|
+
break;
|
|
433
|
+
|
|
434
|
+
case 'Int8Array':
|
|
435
|
+
case 'Uint8Array':
|
|
436
|
+
case 'Uint8ClampedArray':
|
|
437
|
+
case 'Int16Array':
|
|
438
|
+
case 'Uint16Array':
|
|
439
|
+
case 'Float16Array':
|
|
440
|
+
case 'Int32Array':
|
|
441
|
+
case 'Uint32Array':
|
|
442
|
+
case 'Float32Array':
|
|
443
|
+
case 'Float64Array':
|
|
444
|
+
case 'BigInt64Array':
|
|
445
|
+
case 'BigUint64Array': {
|
|
446
|
+
let str = `new ${type}`;
|
|
447
|
+
|
|
448
|
+
if (!names.has(thing.buffer)) {
|
|
449
|
+
const array = new thing.constructor(thing.buffer);
|
|
450
|
+
str += `([${array}])`;
|
|
451
|
+
} else {
|
|
452
|
+
str += `(${stringify(thing.buffer)})`;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// handle subarrays
|
|
456
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
457
|
+
const start = thing.byteOffset / thing.BYTES_PER_ELEMENT;
|
|
458
|
+
const end = start + thing.length;
|
|
459
|
+
str += `.subarray(${start},${end})`;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
values.push(`{}`);
|
|
463
|
+
statements.push(`${name}=${str}`);
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
case 'DataView': {
|
|
468
|
+
let str = `new DataView`;
|
|
469
|
+
|
|
470
|
+
if (!names.has(thing.buffer)) {
|
|
471
|
+
str += `(new Uint8Array([${new Uint8Array(thing.buffer)}]).buffer`;
|
|
472
|
+
} else {
|
|
473
|
+
str += `(${stringify(thing.buffer)}`;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// handle subviews
|
|
477
|
+
if (thing.byteLength !== thing.buffer.byteLength) {
|
|
478
|
+
str += `,${thing.byteOffset},${thing.byteLength}`;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
str += ')';
|
|
482
|
+
|
|
483
|
+
values.push(`{}`);
|
|
484
|
+
statements.push(`${name}=${str}`);
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
case 'ArrayBuffer':
|
|
489
|
+
values.push(`new Uint8Array([${new Uint8Array(thing)}]).buffer`);
|
|
490
|
+
break;
|
|
491
|
+
|
|
492
|
+
default:
|
|
493
|
+
values.push(Object.getPrototypeOf(thing) === null ? 'Object.create(null)' : '{}');
|
|
494
|
+
Object.keys(thing).forEach((key) => {
|
|
495
|
+
statements.push(`${name}${safe_prop(key)}=${stringify(thing[key])}`);
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
statements.push(`return ${str}`);
|
|
501
|
+
|
|
502
|
+
return `(function(${params.join(',')}){${statements.join(';')}}(${values.join(',')}))`;
|
|
503
|
+
} else {
|
|
504
|
+
return str;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** @param {number} num */
|
|
509
|
+
function get_name(num) {
|
|
510
|
+
let name = '';
|
|
511
|
+
|
|
512
|
+
do {
|
|
513
|
+
name = chars[num % chars.length] + name;
|
|
514
|
+
num = ~~(num / chars.length) - 1;
|
|
515
|
+
} while (num >= 0);
|
|
516
|
+
|
|
517
|
+
return reserved.test(name) ? `${name}0` : name;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/** @param {string} c */
|
|
521
|
+
function escape_unsafe_char(c) {
|
|
522
|
+
return escaped[c] || c;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/** @param {string} str */
|
|
526
|
+
function escape_unsafe_chars(str) {
|
|
527
|
+
return str.replace(unsafe_chars, escape_unsafe_char);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/** @param {string} key */
|
|
531
|
+
function safe_key(key) {
|
|
532
|
+
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key) ? key : escape_unsafe_chars(JSON.stringify(key));
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/** @param {string} key */
|
|
536
|
+
function safe_prop(key) {
|
|
537
|
+
return /^[_$a-zA-Z][_$a-zA-Z0-9]*$/.test(key)
|
|
538
|
+
? `.${key}`
|
|
539
|
+
: `[${escape_unsafe_chars(JSON.stringify(key))}]`;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/** @param {any} thing */
|
|
543
|
+
function stringify_primitive(thing) {
|
|
544
|
+
const type = typeof thing;
|
|
545
|
+
if (type === 'string') return stringify_string(thing);
|
|
546
|
+
if (thing === void 0) return 'void 0';
|
|
547
|
+
if (thing === 0 && 1 / thing < 0) return '-0';
|
|
548
|
+
const str = String(thing);
|
|
549
|
+
if (type === 'number') return str.replace(/^(-)?0\./, '$1.');
|
|
550
|
+
if (type === 'bigint') return thing + 'n';
|
|
551
|
+
return str;
|
|
552
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/** @type {Record<string, string>} */
|
|
2
|
+
export const escaped = {
|
|
3
|
+
'<': '\\u003C',
|
|
4
|
+
'\\': '\\\\',
|
|
5
|
+
'\b': '\\b',
|
|
6
|
+
'\f': '\\f',
|
|
7
|
+
'\n': '\\n',
|
|
8
|
+
'\r': '\\r',
|
|
9
|
+
'\t': '\\t',
|
|
10
|
+
'\u2028': '\\u2028',
|
|
11
|
+
'\u2029': '\\u2029'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export class DevalueError extends Error {
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} message
|
|
17
|
+
* @param {string[]} keys
|
|
18
|
+
* @param {any} [value] - The value that failed to be serialized
|
|
19
|
+
* @param {any} [root] - The root value being serialized
|
|
20
|
+
*/
|
|
21
|
+
constructor(message, keys, value, root) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'DevalueError';
|
|
24
|
+
this.path = keys.join('');
|
|
25
|
+
this.value = value;
|
|
26
|
+
this.root = root;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @param {any} thing */
|
|
31
|
+
export function is_primitive(thing) {
|
|
32
|
+
return thing === null || (typeof thing !== 'object' && typeof thing !== 'function');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype)
|
|
36
|
+
.sort()
|
|
37
|
+
.join('\0');
|
|
38
|
+
|
|
39
|
+
/** @param {any} thing */
|
|
40
|
+
export function is_plain_object(thing) {
|
|
41
|
+
const proto = Object.getPrototypeOf(thing);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
proto === Object.prototype ||
|
|
45
|
+
proto === null ||
|
|
46
|
+
Object.getPrototypeOf(proto) === null ||
|
|
47
|
+
Object.getOwnPropertyNames(proto).sort().join('\0') === object_proto_names
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @param {any} thing */
|
|
52
|
+
export function get_type(thing) {
|
|
53
|
+
return Object.prototype.toString.call(thing).slice(8, -1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** @param {string} char */
|
|
57
|
+
function get_escaped_char(char) {
|
|
58
|
+
switch (char) {
|
|
59
|
+
case '"':
|
|
60
|
+
return '\\"';
|
|
61
|
+
case '<':
|
|
62
|
+
return '\\u003C';
|
|
63
|
+
case '\\':
|
|
64
|
+
return '\\\\';
|
|
65
|
+
case '\n':
|
|
66
|
+
return '\\n';
|
|
67
|
+
case '\r':
|
|
68
|
+
return '\\r';
|
|
69
|
+
case '\t':
|
|
70
|
+
return '\\t';
|
|
71
|
+
case '\b':
|
|
72
|
+
return '\\b';
|
|
73
|
+
case '\f':
|
|
74
|
+
return '\\f';
|
|
75
|
+
case '\u2028':
|
|
76
|
+
return '\\u2028';
|
|
77
|
+
case '\u2029':
|
|
78
|
+
return '\\u2029';
|
|
79
|
+
default:
|
|
80
|
+
return char < ' ' ? `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}` : '';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @param {string} str */
|
|
85
|
+
export function stringify_string(str) {
|
|
86
|
+
let result = '';
|
|
87
|
+
let last_pos = 0;
|
|
88
|
+
const len = str.length;
|
|
89
|
+
|
|
90
|
+
for (let i = 0; i < len; i += 1) {
|
|
91
|
+
const char = str[i];
|
|
92
|
+
const replacement = get_escaped_char(char);
|
|
93
|
+
if (replacement) {
|
|
94
|
+
result += str.slice(last_pos, i) + replacement;
|
|
95
|
+
last_pos = i + 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** @param {Record<string | symbol, any>} object */
|
|
103
|
+
export function enumerable_symbols(object) {
|
|
104
|
+
return Object.getOwnPropertySymbols(object).filter(
|
|
105
|
+
(symbol) => Object.getOwnPropertyDescriptor(object, symbol).enumerable
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
|
|
110
|
+
|
|
111
|
+
/** @param {string} key */
|
|
112
|
+
export function stringify_key(key) {
|
|
113
|
+
return is_identifier.test(key) ? '.' + key : '[' + JSON.stringify(key) + ']';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** @param {string} s */
|
|
117
|
+
function is_valid_array_index(s) {
|
|
118
|
+
if (s.length === 0) return false;
|
|
119
|
+
if (s.length > 1 && s.charCodeAt(0) === 48) return false; // leading zero
|
|
120
|
+
for (let i = 0; i < s.length; i++) {
|
|
121
|
+
const c = s.charCodeAt(i);
|
|
122
|
+
if (c < 48 || c > 57) return false;
|
|
123
|
+
}
|
|
124
|
+
// by this point we know it's a string of digits, but it has to be within the range of valid array indices
|
|
125
|
+
const n = +s;
|
|
126
|
+
if (n >= 2 ** 32 - 1) return false;
|
|
127
|
+
if (n < 0) return false;
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Finds the populated indices of an array.
|
|
133
|
+
* @param {unknown[]} array
|
|
134
|
+
*/
|
|
135
|
+
export function valid_array_indices(array) {
|
|
136
|
+
const keys = Object.keys(array);
|
|
137
|
+
for (var i = keys.length - 1; i >= 0; i--) {
|
|
138
|
+
if (is_valid_array_index(keys[i])) {
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
keys.length = i + 1;
|
|
143
|
+
return keys;
|
|
144
|
+
}
|