MCPcopy Create free account
hub / github.com/Snapchat/Valdi / decode

Function decode

src/valdi_modules/src/valdi/source_map/src/VLQ.ts:14–49  ·  view source on GitHub ↗
(string: string)

Source from the content-addressed store, hash-verified

12});
13
14export function decode(string: string): number[] {
15 const result: number[] = [];
16 let shift = 0;
17 let value = 0;
18
19 for (let i = 0; i < string.length; i += 1) {
20 let integer = charToInteger[string[i]];
21
22 if (integer === undefined) {
23 throw new Error('Invalid character (' + string[i] + ')');
24 }
25
26 const hasContinuationBit = integer & 32;
27
28 integer &= 31;
29 value += integer << shift;
30
31 if (hasContinuationBit) {
32 shift += 5;
33 } else {
34 const shouldNegate = value & 1;
35 value >>>= 1;
36
37 if (shouldNegate) {
38 result.push(value === 0 ? -0x80000000 : -value);
39 } else {
40 result.push(value);
41 }
42
43 // reset
44 value = shift = 0;
45 }
46 }
47
48 return result;
49}
50
51export function encode(value: number | number[]): string {
52 let result: string;

Callers 5

parseMethod · 0.90
decodeFromJSONMethod · 0.85
toJSFunction · 0.85
toJSForGCFunction · 0.85
asCallbackObjectMethod · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected