Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
"/single-byte.node.js",
"/utf16.js",
"/utf16.d.ts",
"/utf16.browser.js",
"/utf16.native.js",
"/utf16.node.js",
"/utf8.js",
Expand Down Expand Up @@ -205,6 +206,7 @@
"types": "./utf16.d.ts",
"node": "./utf16.node.js",
"react-native": "./utf16.native.js",
"browser": "./utf16.browser.js",
"default": "./utf16.js"
},
"./utf8.js": {
Expand All @@ -222,6 +224,7 @@
}
},
"browser": {
"./utf16.js": "./utf16.browser.js",
"./fallback/utf8.auto.js": "./fallback/utf8.auto.browser.js"
},
"react-native": {
Expand Down
10 changes: 7 additions & 3 deletions tests/utf16.noenc.test.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
delete globalThis.TextEncoder
if (!globalThis.Deno) delete globalThis.TextDecoder // Deno path requires it
require('./utf16.test.js')
if (process.env.EXODUS_TEST_IS_BROWSER || globalThis.Deno) {
require('node:test').test.skip('Under browsers and Deno, TextDecoder is required')
} else {
delete globalThis.TextEncoder
delete globalThis.TextDecoder
require('./utf16.test.js')
}
8 changes: 8 additions & 0 deletions utf16.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// We trust browsers to always have correct TextDecoder for utf-16le/utf-16be with ignoreBOM without streaming

import { encodeApi, decodeApiDecoders } from './fallback/utf16.js'

export const utf16fromString = (str, format = 'uint16') => encodeApi(str, false, format)
export const utf16fromStringLoose = (str, format = 'uint16') => encodeApi(str, true, format)
export const utf16toString = (arr, format = 'uint16') => decodeApiDecoders(arr, false, format)
export const utf16toStringLoose = (arr, format = 'uint16') => decodeApiDecoders(arr, true, format)
Loading