MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / safeDecode

Function safeDecode

src/pkg/utils/url-utils.ts:17–29  ·  view source on GitHub ↗
(val: string, extra: number)

Source from the content-addressed store, hash-verified

15 PRESERVE_A: 8,
16 } as const;
17 const safeDecode = (val: string, extra: number) => {
18 try {
19 const decodeFn = extra & EXTRA.DECODE_COMP ? decodeURIComponent : decodeURI;
20 let decoded = decodeFn(val);
21 // Re-encode delimiters to prevent breaking the URL structure
22 if (extra & EXTRA.PRESERVE_Q) decoded = decoded.replace(/[=&\s]/g, encodeURIComponent);
23 if (extra & EXTRA.PRESERVE_H) decoded = decoded.replace(/\s/g, encodeURIComponent);
24 if (extra & EXTRA.PRESERVE_A) decoded = decoded.replace(/[=&:@/\\\s]/g, encodeURIComponent);
25 return decoded;
26 } catch {
27 return val;
28 }
29 };
30
31 try {
32 const u = new URL(s, baseUrl);

Callers 1

prettyUrlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected