diff options
author | Louis Pilfold <louis@lpil.uk> | 2021-07-28 19:00:08 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2021-07-28 19:00:08 +0100 |
commit | 838904656a8b38d32a1ab897b93ab35f8b688118 (patch) | |
tree | 6f1a4a2cf6cae31f7afe8bdd69d216fe44cb3898 /src/gleam_stdlib.js | |
parent | 4b1228b7ebc4a2355678f0eb47afacd842e531b3 (diff) | |
download | gleam_stdlib-838904656a8b38d32a1ab897b93ab35f8b688118.tar.gz gleam_stdlib-838904656a8b38d32a1ab897b93ab35f8b688118.zip |
Bit string JS functions
Diffstat (limited to 'src/gleam_stdlib.js')
-rw-r--r-- | src/gleam_stdlib.js | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/gleam_stdlib.js b/src/gleam_stdlib.js index 89908de..d18cd5e 100644 --- a/src/gleam_stdlib.js +++ b/src/gleam_stdlib.js @@ -107,7 +107,9 @@ export function join(xs) { } export function byte_size(data) { - if (typeof Blob === "function") { + if (data instanceof ArrayBuffer) { + return data.byteLength; + } else if (typeof Blob === "function") { return new Blob([data]).size; } else if (typeof Buffer === "function") { return Buffer.byteLength(data); @@ -158,3 +160,18 @@ export function trim_left(string) { export function trim_right(string) { return string.trimRight(); } + +export function bit_string_from_string(string) { + return new TextEncoder().encode(string).buffer; +} + +export function bit_string_append(first, second) { + let array = new Uint8Array(first.byteLength + second.byteLength); + array.set(new Uint8Array(first), 0); + array.set(new Uint8Array(second), first.byteLength); + return array.buffer; +} + +export function log(term) { + console.log(term); +} |