Add `stringToArrayBuffer` utility
This way we can avoid an extra dependency.pull/1/head
parent
232e906650
commit
70cdd2b350
@ -0,0 +1,11 @@
|
||||
exports.stringToArrayBuffer = (string) => {
|
||||
if (typeof string !== 'string') {
|
||||
throw new TypeError('`string` must be a string');
|
||||
}
|
||||
|
||||
const array = new Uint8Array(string.length);
|
||||
for (let i = 0; i < string.length; i += 1) {
|
||||
array[i] = string.charCodeAt(i);
|
||||
}
|
||||
return array.buffer;
|
||||
};
|
Loading…
Reference in New Issue