Spaces:
Paused
Paused
Download node_modules/@peculiar/utils/build/esm/encoding/utf16.js from Leon4gr45/augmenttoolkit: direct link, hf CLI and curl.
- Browser
- Download file 712 Bytes
-
https://huggingface.co/spaces/Leon4gr45/augmenttoolkit/resolve/main/node_modules/%40peculiar/utils/build/esm/encoding/utf16.js
- Command line
-
hf download hf://spaces/Leon4gr45/augmenttoolkit/node_modules/@peculiar/utils/build/esm/encoding/utf16.js
-
curl -L -o utf16.js https://huggingface.co/spaces/Leon4gr45/augmenttoolkit/resolve/main/node_modules/%40peculiar/utils/build/esm/encoding/utf16.js
712 Bytes
| import { toArrayBuffer } from "../bytes/index.js"; | |
| export function encode(text, options = {}) { | |
| const result = new ArrayBuffer(text.length * 2); | |
| const view = new DataView(result); | |
| for (let i = 0; i < text.length; i++) { | |
| view.setUint16(i * 2, text.charCodeAt(i), options.littleEndian ?? false); | |
| } | |
| return new Uint8Array(result); | |
| } | |
| export function decode(data, options = {}) { | |
| const buffer = toArrayBuffer(data); | |
| const view = new DataView(buffer); | |
| let result = ""; | |
| for (let i = 0; i < buffer.byteLength; i += 2) { | |
| result += String.fromCharCode(view.getUint16(i, options.littleEndian ?? false)); | |
| } | |
| return result; | |
| } | |
| export const utf16 = { encode, decode }; | |