@xylabs/arraybuffer 4.4.1 → 4.4.2

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/equalArrayBuffers.ts","../../src/isArrayBuffer.ts","../../src/toArrayBuffer.ts","../../src/toUint8Array.ts"],"sourcesContent":["export const equalArrayBuffers = (a1: ArrayBuffer, a2: ArrayBuffer) => {\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 stringToArrayBuffer = (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: ArrayBuffer | string, padLength?: number, base?: number): ArrayBufferLike\nexport function toArrayBuffer(value: ArrayBuffer | string | undefined, padLength?: number, base?: number): ArrayBufferLike | undefined\nexport function toArrayBuffer(value?: ArrayBuffer | string, padLength?: number, base?: number): ArrayBufferLike | undefined {\n if (value === undefined) return undefined\n\n let result: Uint8Array | undefined\n = typeof value === 'string' ? stringToArrayBuffer(value, base) : (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: ArrayBuffer | string, padLength?: number, base?: number): Uint8Array\nexport function toUint8Array(value: ArrayBuffer | string | undefined, padLength?: number, base?: number): Uint8Array | undefined\nexport function toUint8Array(value?: ArrayBuffer | string, padLength?: number, base?: number): Uint8Array | undefined {\n const arrayBuffer = typeof value === 'string' ? toArrayBuffer(value, padLength, base) : value\n return arrayBuffer ? new Uint8Array(arrayBuffer) : undefined\n}\n"],"mappings":";AAAO,IAAM,oBAAoB,CAAC,IAAiB,OAAoB;AACrE,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,sBAAsB,CAAC,OAAe,OAAO,OAAmB;AACpE,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,OAA8B,WAAoB,MAA4C;AAC1H,MAAI,UAAU,OAAW,QAAO;AAEhC,MAAI,SACA,OAAO,UAAU,WAAW,oBAAoB,OAAO,IAAI,IAAK,IAAI,WAAW,KAAK;AAExF,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;;;AC/BO,SAAS,aAAa,OAA8B,WAAoB,MAAuC;AACpH,QAAM,cAAc,OAAO,UAAU,WAAW,cAAc,OAAO,WAAW,IAAI,IAAI;AACxF,SAAO,cAAc,IAAI,WAAW,WAAW,IAAI;AACrD;","names":[]}
1
+ {"version":3,"sources":["../../src/equalArrayBuffers.ts","../../src/isArrayBuffer.ts","../../src/toArrayBuffer.ts","../../src/toUint8Array.ts"],"sourcesContent":["export const equalArrayBuffers = (a1: ArrayBuffer, a2: ArrayBuffer) => {\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 stringToArrayBuffer = (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: ArrayBuffer | string, padLength?: number, base?: number): ArrayBufferLike\nexport function toArrayBuffer(value: ArrayBuffer | string | undefined, padLength?: number, base?: number): ArrayBufferLike | undefined\nexport function toArrayBuffer(value?: ArrayBuffer | string, padLength?: number, base?: number): ArrayBufferLike | undefined {\n if (value === undefined) return undefined\n\n let result: Uint8Array | undefined\n = typeof value === 'string' ? stringToArrayBuffer(value, base) : (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 | string, padLength?: number, base?: number): Uint8Array\nexport function toUint8Array(value: ArrayBufferLike | string | undefined, padLength?: number, base?: number): Uint8Array | undefined\nexport function toUint8Array(value?: ArrayBufferLike | string, padLength?: number, base?: number): Uint8Array | undefined {\n const arrayBuffer = typeof value === 'string' ? toArrayBuffer(value, padLength, base) : value\n return arrayBuffer ? new Uint8Array(arrayBuffer) : undefined\n}\n"],"mappings":";AAAO,IAAM,oBAAoB,CAAC,IAAiB,OAAoB;AACrE,QAAM,KAAK,IAAI,WAAW,EAA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4CAA4C;AAAA,EAC1F;AAEA,SAAO,OAAO;AAChB;;;AC/BO,SAAS,aAAa,OAAkC,WAAoB,MAAuC;AACxH,QAAM,cAAc,OAAO,UAAU,WAAW,cAAc,OAAO,WAAW,IAAI,IAAI;AACxF,SAAO,cAAc,IAAI,WAAW,WAAW,IAAI;AACrD;","names":[]}
@@ -1,4 +1,4 @@
1
1
  export declare function toUint8Array(value: undefined, padLength?: number, base?: number): undefined;
2
- export declare function toUint8Array(value: ArrayBuffer | string, padLength?: number, base?: number): Uint8Array;
3
- export declare function toUint8Array(value: ArrayBuffer | string | undefined, padLength?: number, base?: number): Uint8Array | 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;
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,WAAW,GAAG,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;AACxG,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,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,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;AAC5G,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,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.1",
3
+ "version": "4.4.2",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "xylabs",
@@ -36,7 +36,7 @@
36
36
  "types": "dist/neutral/index.d.ts",
37
37
  "dependencies": {
38
38
  "@scure/base": "^1.2.1",
39
- "@xylabs/assert": "^4.4.1"
39
+ "@xylabs/assert": "^4.4.2"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@xylabs/ts-scripts-yarn3": "^4.2.4",
@@ -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: ArrayBuffer | string, padLength?: number, base?: number): Uint8Array
5
- export function toUint8Array(value: ArrayBuffer | string | undefined, padLength?: number, base?: number): Uint8Array | undefined
6
- export function toUint8Array(value?: ArrayBuffer | string, padLength?: number, base?: number): Uint8Array | 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
7
  const arrayBuffer = typeof value === 'string' ? toArrayBuffer(value, padLength, base) : value
8
8
  return arrayBuffer ? new Uint8Array(arrayBuffer) : undefined
9
9
  }