@exodus/bytes
Advanced tools
+1
-1
@@ -11,3 +11,3 @@ export function assertEmptyRest(rest) { | ||
| export function assertTypedArray(arr) { | ||
| if (arr instanceof TypedArray) return | ||
| if (arr && arr instanceof TypedArray) return | ||
| throw new TypeError('Expected a TypedArray instance') | ||
@@ -14,0 +14,0 @@ } |
+1
-1
@@ -165,3 +165,3 @@ import { assertU8, fromUint8, E_STRING } from './fallback/_utils.js' | ||
| let y = Number(x & _0xffffffffn) | ||
| x >>= 32n | ||
| x >>= _32n | ||
| res[--at] = y & 0xff | ||
@@ -168,0 +168,0 @@ y >>>= 8 |
+1
-0
@@ -77,2 +77,3 @@ import { assertEmptyRest } from './assert.js' | ||
| export function fromBase64any(str, { format = 'uint8', padding = 'both', ...rest } = {}) { | ||
| if (typeof str !== 'string') throw new TypeError(E_STRING) | ||
| const isBase64url = !str.includes('+') && !str.includes('/') // likely to fail fast, as most input is non-url, also double scan is faster than regex | ||
@@ -79,0 +80,0 @@ return fromBase64common(str, isBase64url, padding, format, rest) |
@@ -10,3 +10,4 @@ export * from './platform.js' | ||
| export function assertU8(arg) { | ||
| if (!(arg instanceof Uint8Array)) throw new TypeError('Expected an Uint8Array') | ||
| if (arg && arg instanceof Uint8Array) return | ||
| throw new TypeError('Expected an Uint8Array') | ||
| } | ||
@@ -51,3 +52,5 @@ | ||
| case 'arraybuffer': | ||
| return fromBuffer(arr, 'uint8').buffer | ||
| return arr.buffer.byteLength === arr.byteLength | ||
| ? arr.buffer | ||
| : arr.buffer.slice(arr.byteOffset, arr.byteOffset + arr.byteLength) | ||
| case 'buffer': | ||
@@ -54,0 +57,0 @@ if (arr.constructor !== Buffer) throw new Error('Unexpected') |
+1
-1
@@ -76,3 +76,3 @@ import { E_STRING } from './_utils.js' | ||
| const codes = encodeAscii(str, E_HEX) | ||
| const codes = encodeAscii(str, E_HEX) // aligned | ||
| const codes16 = new Uint16Array(codes.buffer, codes.byteOffset, codes.byteLength / 2) | ||
@@ -79,0 +79,0 @@ let i = 0 |
@@ -143,2 +143,3 @@ import { | ||
| // TextEncoder is slow on Node.js 24 / 25 (was ok on 22) | ||
| // Node.js Buffer.from always returns 8-byte aligned allocations, this is safe for e.g. conversion to Uint32Array | ||
| const codes = nativeBuffer.from(str, 'utf8') // ascii/latin1 coerces, we need to check | ||
@@ -145,0 +146,0 @@ if (codes.length !== str.length) throw new SyntaxError(ERR) // non-ascii |
+1
-1
| { | ||
| "name": "@exodus/bytes", | ||
| "version": "1.15.0", | ||
| "version": "1.15.1", | ||
| "description": "Various operations on Uint8Array data", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
429869
0.07%6605
0.08%