@xylabs/arraybuffer 4.4.26 → 4.4.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/index.mjs +5 -2
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/toArrayBuffer.d.ts +2 -2
- package/dist/neutral/toArrayBuffer.d.ts.map +1 -1
- package/dist/neutral/toUint8Array.d.ts +2 -2
- package/dist/neutral/toUint8Array.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/toArrayBuffer.ts +10 -4
- package/src/toUint8Array.ts +4 -4
package/dist/neutral/index.mjs
CHANGED
|
@@ -35,7 +35,10 @@ var stringToUInt8Array = (value, base = 16) => {
|
|
|
35
35
|
};
|
|
36
36
|
function toArrayBuffer(value, padLength, base) {
|
|
37
37
|
if (value === void 0) return void 0;
|
|
38
|
-
|
|
38
|
+
if (typeof value === "bigint" && value < 0) {
|
|
39
|
+
throw new Error(`negative bigint values are not supported: ${typeof value}`);
|
|
40
|
+
}
|
|
41
|
+
let result = typeof value === "string" ? stringToUInt8Array(value, base) : typeof value === "bigint" ? stringToUInt8Array(value.toString(16)) : new Uint8Array(value);
|
|
39
42
|
if (result === void 0) {
|
|
40
43
|
throw new Error(`toArrayBuffer - Unknown type: ${typeof value}`);
|
|
41
44
|
}
|
|
@@ -48,7 +51,7 @@ function toArrayBuffer(value, padLength, base) {
|
|
|
48
51
|
|
|
49
52
|
// src/toUint8Array.ts
|
|
50
53
|
function toUint8Array(value, padLength, base) {
|
|
51
|
-
const arrayBuffer =
|
|
54
|
+
const arrayBuffer = toArrayBuffer(value, padLength, base);
|
|
52
55
|
return arrayBuffer ? new Uint8Array(arrayBuffer) : void 0;
|
|
53
56
|
}
|
|
54
57
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/equalArrayBuffers.ts","../../src/isArrayBuffer.ts","../../src/toArrayBuffer.ts","../../src/toUint8Array.ts"],"sourcesContent":["export const equalArrayBuffers = (a1: ArrayBufferLike, a2: ArrayBufferLike) => {\n const u1 = new Uint8Array(a1)\n const u2 = new Uint8Array(a2)\n if (u1.byteLength !== u2.byteLength) return false\n for (let i = 0; i < u1.byteLength; i++) {\n if (u1[i] !== u2[i]) return false\n }\n return true\n}\n","export const isArrayBuffer = (value: unknown): value is ArrayBuffer => {\n return value instanceof ArrayBuffer\n}\n\nexport const isArrayBufferLike = (value: unknown): value is ArrayBufferLike => {\n return (\n value !== null\n && typeof value === 'object'\n && 'byteLength' in value\n && typeof (value as ArrayBufferLike).byteLength === 'number'\n && 'slice' in value\n && typeof (value as ArrayBufferLike).slice === 'function'\n )\n}\n","import { base16, base58 } from '@scure/base'\nimport { assertEx } from '@xylabs/assert'\n\nconst stringToUInt8Array = (value: string, base = 16): Uint8Array => {\n switch (base) {\n case 16: {\n return base16.decode((value.startsWith('0x') ? value.slice(2) : value).toUpperCase())\n }\n case 58: {\n return base58.decode(value)\n }\n default: {\n throw new Error(`Unsupported base [${base}]`)\n }\n }\n}\n\nexport function toArrayBuffer(value: undefined, padLength?: number, base?: number): undefined\nexport function toArrayBuffer(value: ArrayBufferLike | string, padLength?: number, base?: number): ArrayBufferLike\nexport function toArrayBuffer(value: ArrayBufferLike | string | undefined, padLength?: number, base?: number): ArrayBufferLike | undefined\nexport function toArrayBuffer(value?: ArrayBufferLike | string, padLength?: number, base?: number): ArrayBufferLike | undefined {\n if (value === undefined) return undefined\n\n let result: Uint8Array | undefined\n = typeof value === 'string'
|
|
1
|
+
{"version":3,"sources":["../../src/equalArrayBuffers.ts","../../src/isArrayBuffer.ts","../../src/toArrayBuffer.ts","../../src/toUint8Array.ts"],"sourcesContent":["export const equalArrayBuffers = (a1: ArrayBufferLike, a2: ArrayBufferLike) => {\n const u1 = new Uint8Array(a1)\n const u2 = new Uint8Array(a2)\n if (u1.byteLength !== u2.byteLength) return false\n for (let i = 0; i < u1.byteLength; i++) {\n if (u1[i] !== u2[i]) return false\n }\n return true\n}\n","export const isArrayBuffer = (value: unknown): value is ArrayBuffer => {\n return value instanceof ArrayBuffer\n}\n\nexport const isArrayBufferLike = (value: unknown): value is ArrayBufferLike => {\n return (\n value !== null\n && typeof value === 'object'\n && 'byteLength' in value\n && typeof (value as ArrayBufferLike).byteLength === 'number'\n && 'slice' in value\n && typeof (value as ArrayBufferLike).slice === 'function'\n )\n}\n","import { base16, base58 } from '@scure/base'\nimport { assertEx } from '@xylabs/assert'\n\nconst stringToUInt8Array = (value: string, base = 16): Uint8Array => {\n switch (base) {\n case 16: {\n return base16.decode((value.startsWith('0x') ? value.slice(2) : value).toUpperCase())\n }\n case 58: {\n return base58.decode(value)\n }\n default: {\n throw new Error(`Unsupported base [${base}]`)\n }\n }\n}\n\nexport function toArrayBuffer(value: undefined, padLength?: number, base?: number): undefined\nexport function toArrayBuffer(value: ArrayBufferLike | bigint | string, padLength?: number, base?: number): ArrayBufferLike\nexport function toArrayBuffer(value: ArrayBufferLike | bigint | string | undefined, padLength?: number, base?: number): ArrayBufferLike | undefined\nexport function toArrayBuffer(value?: ArrayBufferLike | bigint | string, padLength?: number, base?: number): ArrayBufferLike | undefined {\n if (value === undefined) return undefined\n\n if (typeof value === 'bigint' && value < 0) {\n throw new Error(`negative bigint values are not supported: ${typeof value}`)\n }\n\n let result: Uint8Array | undefined\n = typeof value === 'string'\n ? stringToUInt8Array(value, base)\n : typeof value === 'bigint' ? stringToUInt8Array(value.toString(16)) : (new Uint8Array(value))\n\n if (result === undefined) {\n throw new Error(`toArrayBuffer - Unknown type: ${typeof value}`)\n }\n\n if (padLength && result.length < padLength) {\n result = new Uint8Array([...new Uint8Array(padLength - result.length), ...result])\n assertEx(result?.length <= padLength, () => 'Resulting length is greater than padLength')\n }\n\n return result.buffer\n}\n","import { toArrayBuffer } from './toArrayBuffer.ts'\n\nexport function toUint8Array(value: undefined, padLength?: number, base?: number): undefined\nexport function toUint8Array(value: ArrayBufferLike | bigint | string, padLength?: number, base?: number): Uint8Array\nexport function toUint8Array(value: ArrayBufferLike | bigint | string | undefined, padLength?: number, base?: number): Uint8Array | undefined\nexport function toUint8Array(value?: ArrayBufferLike | bigint | string, padLength?: number, base?: number): Uint8Array | undefined {\n const arrayBuffer = toArrayBuffer(value, padLength, base)\n return arrayBuffer ? new Uint8Array(arrayBuffer) : undefined\n}\n"],"mappings":";AAAO,IAAM,oBAAoB,CAAC,IAAqB,OAAwB;AAC7E,QAAM,KAAK,IAAI,WAAW,EAAE;AAC5B,QAAM,KAAK,IAAI,WAAW,EAAE;AAC5B,MAAI,GAAG,eAAe,GAAG,WAAY,QAAO;AAC5C,WAAS,IAAI,GAAG,IAAI,GAAG,YAAY,KAAK;AACtC,QAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAG,QAAO;AAAA,EAC9B;AACA,SAAO;AACT;;;ACRO,IAAM,gBAAgB,CAAC,UAAyC;AACrE,SAAO,iBAAiB;AAC1B;AAEO,IAAM,oBAAoB,CAAC,UAA6C;AAC7E,SACE,UAAU,QACP,OAAO,UAAU,YACjB,gBAAgB,SAChB,OAAQ,MAA0B,eAAe,YACjD,WAAW,SACX,OAAQ,MAA0B,UAAU;AAEnD;;;ACbA,SAAS,QAAQ,cAAc;AAC/B,SAAS,gBAAgB;AAEzB,IAAM,qBAAqB,CAAC,OAAe,OAAO,OAAmB;AACnE,UAAQ,MAAM;AAAA,IACZ,KAAK,IAAI;AACP,aAAO,OAAO,QAAQ,MAAM,WAAW,IAAI,IAAI,MAAM,MAAM,CAAC,IAAI,OAAO,YAAY,CAAC;AAAA,IACtF;AAAA,IACA,KAAK,IAAI;AACP,aAAO,OAAO,OAAO,KAAK;AAAA,IAC5B;AAAA,IACA,SAAS;AACP,YAAM,IAAI,MAAM,qBAAqB,IAAI,GAAG;AAAA,IAC9C;AAAA,EACF;AACF;AAKO,SAAS,cAAc,OAA2C,WAAoB,MAA4C;AACvI,MAAI,UAAU,OAAW,QAAO;AAEhC,MAAI,OAAO,UAAU,YAAY,QAAQ,GAAG;AAC1C,UAAM,IAAI,MAAM,6CAA6C,OAAO,KAAK,EAAE;AAAA,EAC7E;AAEA,MAAI,SACA,OAAO,UAAU,WACf,mBAAmB,OAAO,IAAI,IAC9B,OAAO,UAAU,WAAW,mBAAmB,MAAM,SAAS,EAAE,CAAC,IAAK,IAAI,WAAW,KAAK;AAEhG,MAAI,WAAW,QAAW;AACxB,UAAM,IAAI,MAAM,iCAAiC,OAAO,KAAK,EAAE;AAAA,EACjE;AAEA,MAAI,aAAa,OAAO,SAAS,WAAW;AAC1C,aAAS,IAAI,WAAW,CAAC,GAAG,IAAI,WAAW,YAAY,OAAO,MAAM,GAAG,GAAG,MAAM,CAAC;AACjF,aAAS,QAAQ,UAAU,WAAW,MAAM,4CAA4C;AAAA,EAC1F;AAEA,SAAO,OAAO;AAChB;;;ACrCO,SAAS,aAAa,OAA2C,WAAoB,MAAuC;AACjI,QAAM,cAAc,cAAc,OAAO,WAAW,IAAI;AACxD,SAAO,cAAc,IAAI,WAAW,WAAW,IAAI;AACrD;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function toArrayBuffer(value: undefined, padLength?: number, base?: number): undefined;
|
|
2
|
-
export declare function toArrayBuffer(value: ArrayBufferLike | string, padLength?: number, base?: number): ArrayBufferLike;
|
|
3
|
-
export declare function toArrayBuffer(value: ArrayBufferLike | string | undefined, padLength?: number, base?: number): ArrayBufferLike | undefined;
|
|
2
|
+
export declare function toArrayBuffer(value: ArrayBufferLike | bigint | string, padLength?: number, base?: number): ArrayBufferLike;
|
|
3
|
+
export declare function toArrayBuffer(value: ArrayBufferLike | bigint | string | undefined, padLength?: number, base?: number): ArrayBufferLike | undefined;
|
|
4
4
|
//# sourceMappingURL=toArrayBuffer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toArrayBuffer.d.ts","sourceRoot":"","sources":["../../src/toArrayBuffer.ts"],"names":[],"mappings":"AAiBA,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;AAC7F,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"toArrayBuffer.d.ts","sourceRoot":"","sources":["../../src/toArrayBuffer.ts"],"names":[],"mappings":"AAiBA,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;AAC7F,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,GAAG,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,CAAA;AAC3H,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function toUint8Array(value: undefined, padLength?: number, base?: number): undefined;
|
|
2
|
-
export declare function toUint8Array(value: ArrayBufferLike | string, padLength?: number, base?: number): Uint8Array;
|
|
3
|
-
export declare function toUint8Array(value: ArrayBufferLike | string | undefined, padLength?: number, base?: number): Uint8Array | undefined;
|
|
2
|
+
export declare function toUint8Array(value: ArrayBufferLike | bigint | string, padLength?: number, base?: number): Uint8Array;
|
|
3
|
+
export declare function toUint8Array(value: ArrayBufferLike | bigint | string | undefined, padLength?: number, base?: number): Uint8Array | undefined;
|
|
4
4
|
//# sourceMappingURL=toUint8Array.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toUint8Array.d.ts","sourceRoot":"","sources":["../../src/toUint8Array.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;AAC5F,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"toUint8Array.d.ts","sourceRoot":"","sources":["../../src/toUint8Array.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;AAC5F,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,GAAG,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;AACrH,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/arraybuffer",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.28",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"types": "dist/neutral/index.d.ts",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@scure/base": "^1.2.1",
|
|
39
|
-
"@xylabs/assert": "^4.4.
|
|
39
|
+
"@xylabs/assert": "^4.4.28"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@xylabs/ts-scripts-yarn3": "^4.2.
|
|
43
|
-
"@xylabs/tsconfig": "^4.2.
|
|
42
|
+
"@xylabs/ts-scripts-yarn3": "^4.2.6",
|
|
43
|
+
"@xylabs/tsconfig": "^4.2.6",
|
|
44
44
|
"typescript": "^5.7.2",
|
|
45
45
|
"vitest": "^2.1.8"
|
|
46
46
|
},
|
package/src/toArrayBuffer.ts
CHANGED
|
@@ -16,13 +16,19 @@ const stringToUInt8Array = (value: string, base = 16): Uint8Array => {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export function toArrayBuffer(value: undefined, padLength?: number, base?: number): undefined
|
|
19
|
-
export function toArrayBuffer(value: ArrayBufferLike | string, padLength?: number, base?: number): ArrayBufferLike
|
|
20
|
-
export function toArrayBuffer(value: ArrayBufferLike | string | undefined, padLength?: number, base?: number): ArrayBufferLike | undefined
|
|
21
|
-
export function toArrayBuffer(value?: ArrayBufferLike | string, padLength?: number, base?: number): ArrayBufferLike | undefined {
|
|
19
|
+
export function toArrayBuffer(value: ArrayBufferLike | bigint | string, padLength?: number, base?: number): ArrayBufferLike
|
|
20
|
+
export function toArrayBuffer(value: ArrayBufferLike | bigint | string | undefined, padLength?: number, base?: number): ArrayBufferLike | undefined
|
|
21
|
+
export function toArrayBuffer(value?: ArrayBufferLike | bigint | string, padLength?: number, base?: number): ArrayBufferLike | undefined {
|
|
22
22
|
if (value === undefined) return undefined
|
|
23
23
|
|
|
24
|
+
if (typeof value === 'bigint' && value < 0) {
|
|
25
|
+
throw new Error(`negative bigint values are not supported: ${typeof value}`)
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
let result: Uint8Array | undefined
|
|
25
|
-
= typeof value === 'string'
|
|
29
|
+
= typeof value === 'string'
|
|
30
|
+
? stringToUInt8Array(value, base)
|
|
31
|
+
: typeof value === 'bigint' ? stringToUInt8Array(value.toString(16)) : (new Uint8Array(value))
|
|
26
32
|
|
|
27
33
|
if (result === undefined) {
|
|
28
34
|
throw new Error(`toArrayBuffer - Unknown type: ${typeof value}`)
|
package/src/toUint8Array.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { toArrayBuffer } from './toArrayBuffer.ts'
|
|
2
2
|
|
|
3
3
|
export function toUint8Array(value: undefined, padLength?: number, base?: number): undefined
|
|
4
|
-
export function toUint8Array(value: ArrayBufferLike | string, padLength?: number, base?: number): Uint8Array
|
|
5
|
-
export function toUint8Array(value: ArrayBufferLike | string | undefined, padLength?: number, base?: number): Uint8Array | undefined
|
|
6
|
-
export function toUint8Array(value?: ArrayBufferLike | string, padLength?: number, base?: number): Uint8Array | undefined {
|
|
7
|
-
const arrayBuffer =
|
|
4
|
+
export function toUint8Array(value: ArrayBufferLike | bigint | string, padLength?: number, base?: number): Uint8Array
|
|
5
|
+
export function toUint8Array(value: ArrayBufferLike | bigint | string | undefined, padLength?: number, base?: number): Uint8Array | undefined
|
|
6
|
+
export function toUint8Array(value?: ArrayBufferLike | bigint | string, padLength?: number, base?: number): Uint8Array | undefined {
|
|
7
|
+
const arrayBuffer = toArrayBuffer(value, padLength, base)
|
|
8
8
|
return arrayBuffer ? new Uint8Array(arrayBuffer) : undefined
|
|
9
9
|
}
|