UNPKG

buffer-string-to-array

Version:

Convert Nodejs Buffer.toString() output to an array.

22 lines (21 loc) 548 B
// Revisit because performance tests show that toString().split(",") is actuall marginally faster across the whole board exports.convert = function(_string){ temp = ''; array = []; for (c of _string) { if (c == ",") { array.push(Number(temp)); temp = ''; } else { if (temp.length == 0) { temp = c; } else { temp = temp + c; } } } if (temp.length > 0){ array.push(Number(temp)); } return array; }