MCPcopy Create free account
hub / github.com/melonjs/melonJS / decodeCSV

Function decodeCSV

packages/melonjs/src/utils/decode.ts:40–70  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

38 * @returns Decoded data
39 */
40export function decodeCSV(input: string): number[] {
41 const trimmed = input.trim();
42
43 // count commas to pre-allocate (avoids array resizing)
44 let count = 1;
45 for (let i = 0, len = trimmed.length; i < len; i++) {
46 if (trimmed.charCodeAt(i) === 44 /* comma */) {
47 count++;
48 }
49 }
50
51 const result = new Array<number>(count);
52 let idx = 0;
53 let start = 0;
54
55 for (let i = 0, len = trimmed.length; i <= len; i++) {
56 const ch = i < len ? trimmed.charCodeAt(i) : 44; // treat end-of-string as comma
57 // skip newlines (10 = \n, 13 = \r)
58 if (ch === 10 || ch === 13) {
59 continue;
60 }
61 if (ch === 44 /* comma */) {
62 result[idx++] = +trimmed.slice(start, i);
63 start = i + 1;
64 }
65 }
66
67 // trim trailing empty entries from trailing commas
68 result.length = idx;
69 return result;
70}
71
72/**
73 * Decode a base64 encoded string into a byte array

Callers 1

decodeFunction · 0.85

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected