MCPcopy Create free account
hub / github.com/FxEmbed/FxEmbed / decodeSnowcode

Function decodeSnowcode

src/helpers/snowcode.ts:19–35  ·  view source on GitHub ↗
(numStr: string)

Source from the content-addressed store, hash-verified

17};
18
19export const decodeSnowcode = (numStr: string) => {
20 const str = numStr.match(/\d+/)?.join('') ?? '';
21 if (str.length % 2 !== 0) {
22 throw new Error('Invalid encoded string length.');
23 }
24 let result = '';
25 for (let i = 0; i < str.length; i += 2) {
26 const codeStr = str.slice(i, i + 2);
27 const index = parseInt(codeStr, 10);
28 if (index < 0 || index >= allowedChars.length) {
29 throw new Error('Invalid code: ' + codeStr);
30 }
31 result += allowedChars[index];
32 }
33 const resultStr = `{${result}}`;
34 return JSON.parse(resultStr);
35};

Callers 1

handleActivityFunction · 0.90

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected