@bare-ts/lib 0.3.0 → 0.4.0

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.
Files changed (56) hide show
  1. package/LICENSE +21 -201
  2. package/dist/codec/data.d.ts +1 -1
  3. package/dist/codec/data.js +10 -12
  4. package/dist/codec/float-array.d.ts +9 -9
  5. package/dist/codec/float-array.js +51 -43
  6. package/dist/codec/i16-array.d.ts +5 -5
  7. package/dist/codec/i16-array.js +34 -26
  8. package/dist/codec/i32-array.d.ts +5 -5
  9. package/dist/codec/i32-array.js +34 -26
  10. package/dist/codec/i64-array.d.ts +5 -5
  11. package/dist/codec/i64-array.js +34 -26
  12. package/dist/codec/i8-array.d.ts +1 -1
  13. package/dist/codec/i8-array.js +12 -14
  14. package/dist/codec/primitive.d.ts +3 -1
  15. package/dist/codec/primitive.js +225 -147
  16. package/dist/codec/string.d.ts +1 -1
  17. package/dist/codec/string.js +45 -31
  18. package/dist/codec/u16-array.d.ts +5 -5
  19. package/dist/codec/u16-array.js +34 -26
  20. package/dist/codec/u32-array.d.ts +5 -5
  21. package/dist/codec/u32-array.js +34 -26
  22. package/dist/codec/u64-array.d.ts +5 -5
  23. package/dist/codec/u64-array.js +34 -26
  24. package/dist/codec/u8-array.d.ts +7 -1
  25. package/dist/codec/u8-array.js +22 -17
  26. package/dist/codec/u8-clamped-array.d.ts +1 -1
  27. package/dist/codec/u8-clamped-array.js +13 -15
  28. package/dist/core/bare-error.d.ts +4 -1
  29. package/dist/core/bare-error.js +4 -8
  30. package/dist/core/byte-cursor.d.ts +22 -28
  31. package/dist/core/byte-cursor.js +33 -29
  32. package/dist/core/config.d.ts +3 -7
  33. package/dist/core/config.js +14 -20
  34. package/dist/env/dev.d.ts +1 -0
  35. package/dist/env/dev.development.d.ts +1 -0
  36. package/dist/env/dev.development.js +2 -0
  37. package/dist/env/dev.js +2 -0
  38. package/dist/env/dev.node.d.ts +1 -0
  39. package/dist/env/dev.node.js +2 -0
  40. package/dist/index.cjs +504 -286
  41. package/dist/index.d.cts +16 -0
  42. package/dist/index.d.ts +16 -2
  43. package/dist/index.js +17 -4
  44. package/dist/util/assert.d.ts +6 -8
  45. package/dist/util/assert.js +10 -13
  46. package/dist/util/constants.d.ts +4 -7
  47. package/dist/util/constants.js +11 -30
  48. package/dist/util/validator.d.ts +1 -1
  49. package/dist/util/validator.js +12 -24
  50. package/package.json +31 -24
  51. package/dist/codec/index.d.ts +0 -13
  52. package/dist/codec/index.js +0 -15
  53. package/dist/core/index.d.ts +0 -3
  54. package/dist/core/index.js +0 -5
  55. package/dist/util/util.d.ts +0 -1
  56. package/dist/util/util.js +0 -6
@@ -1,43 +1,51 @@
1
- // src/codec/i64-array.ts
2
- import { I64_BYTE_COUNT } from "../util/constants.js";
3
- import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/util.js";
1
+ "use strict";
2
+ import { check, reserve } from "../core/byte-cursor.js";
3
+ import { DEV, assert } from "../util/assert.js";
4
+ import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/constants.js";
5
+ import { isU32 } from "../util/validator.js";
4
6
  import { readFixedData } from "./data.js";
5
- import { readI64, readUintSafe, writeI64, writeUintSafe } from "./primitive.js";
7
+ import {
8
+ readI64,
9
+ readUintSafe32,
10
+ writeI64,
11
+ writeUintSafe32
12
+ } from "./primitive.js";
6
13
  import { writeU8FixedArray } from "./u8-array.js";
7
- var readI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI64FixedArrayLE : readI64FixedArrayBE;
8
- function readI64Array(bc) {
9
- return readI64FixedArray(bc, readUintSafe(bc));
14
+ export const readI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI64FixedArrayLe : readI64FixedArrayBe;
15
+ export function readI64Array(bc) {
16
+ return readI64FixedArray(bc, readUintSafe32(bc));
10
17
  }
11
- function readI64FixedArrayLE(bc, len) {
12
- const byteCount = len * I64_BYTE_COUNT;
18
+ function readI64FixedArrayLe(bc, len) {
19
+ if (DEV) {
20
+ assert(isU32(len));
21
+ }
22
+ const byteCount = len * 8;
13
23
  return new BigInt64Array(readFixedData(bc, byteCount));
14
24
  }
15
- function readI64FixedArrayBE(bc, len) {
16
- bc.check(len * I64_BYTE_COUNT);
25
+ function readI64FixedArrayBe(bc, len) {
26
+ if (DEV) {
27
+ assert(isU32(len));
28
+ }
29
+ check(bc, len * 8);
17
30
  const result = new BigInt64Array(len);
18
- for (let i = 0; i < len; i++)
31
+ for (let i = 0; i < len; i++) {
19
32
  result[i] = readI64(bc);
33
+ }
20
34
  return result;
21
35
  }
22
- var writeI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI64FixedArrayLE : writeI64FixedArrayBE;
23
- function writeI64Array(bc, x) {
24
- writeUintSafe(bc, x.length);
36
+ export const writeI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI64FixedArrayLe : writeI64FixedArrayBe;
37
+ export function writeI64Array(bc, x) {
38
+ writeUintSafe32(bc, x.length);
25
39
  if (x.length !== 0) {
26
40
  writeI64FixedArray(bc, x);
27
41
  }
28
42
  }
29
- function writeI64FixedArrayLE(bc, x) {
43
+ function writeI64FixedArrayLe(bc, x) {
30
44
  writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
31
45
  }
32
- function writeI64FixedArrayBE(bc, x) {
33
- bc.reserve(x.length * I64_BYTE_COUNT);
34
- for (let i = 0; i < x.length; i++)
46
+ function writeI64FixedArrayBe(bc, x) {
47
+ reserve(bc, x.length * 8);
48
+ for (let i = 0; i < x.length; i++) {
35
49
  writeI64(bc, x[i]);
50
+ }
36
51
  }
37
- export {
38
- readI64Array,
39
- readI64FixedArray,
40
- writeI64Array,
41
- writeI64FixedArray
42
- };
43
- //# sourceMappingURL=i64-array.js.map
@@ -1,4 +1,4 @@
1
- import type { ByteCursor } from "../core/index.js";
1
+ import type { ByteCursor } from "../core/byte-cursor.js";
2
2
  export declare function readI8Array(bc: ByteCursor): Int8Array;
3
3
  export declare function writeI8Array(bc: ByteCursor, x: Int8Array): void;
4
4
  export declare function readI8FixedArray(bc: ByteCursor, len: number): Int8Array;
@@ -1,24 +1,22 @@
1
- // src/codec/i8-array.ts
1
+ "use strict";
2
+ import { DEV, assert } from "../util/assert.js";
3
+ import { isU32 } from "../util/validator.js";
2
4
  import { readFixedData } from "./data.js";
3
- import { readUintSafe, writeUintSafe } from "./primitive.js";
5
+ import { readUintSafe, writeUintSafe32 } from "./primitive.js";
4
6
  import { writeU8FixedArray } from "./u8-array.js";
5
- function readI8Array(bc) {
7
+ export function readI8Array(bc) {
6
8
  return readI8FixedArray(bc, readUintSafe(bc));
7
9
  }
8
- function writeI8Array(bc, x) {
9
- writeUintSafe(bc, x.length);
10
+ export function writeI8Array(bc, x) {
11
+ writeUintSafe32(bc, x.length);
10
12
  writeI8FixedArray(bc, x);
11
13
  }
12
- function readI8FixedArray(bc, len) {
14
+ export function readI8FixedArray(bc, len) {
15
+ if (DEV) {
16
+ assert(isU32(len));
17
+ }
13
18
  return new Int8Array(readFixedData(bc, len));
14
19
  }
15
- function writeI8FixedArray(bc, x) {
20
+ export function writeI8FixedArray(bc, x) {
16
21
  writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
17
22
  }
18
- export {
19
- readI8Array,
20
- readI8FixedArray,
21
- writeI8Array,
22
- writeI8FixedArray
23
- };
24
- //# sourceMappingURL=i8-array.js.map
@@ -1,4 +1,4 @@
1
- import { type ByteCursor } from "../core/index.js";
1
+ import { type ByteCursor } from "../core/byte-cursor.js";
2
2
  export declare function readBool(bc: ByteCursor): boolean;
3
3
  export declare function writeBool(bc: ByteCursor, x: boolean): void;
4
4
  export declare function readF32(bc: ByteCursor): number;
@@ -31,5 +31,7 @@ export declare function readU64Safe(bc: ByteCursor): number;
31
31
  export declare function writeU64Safe(bc: ByteCursor, x: number): void;
32
32
  export declare function readUint(bc: ByteCursor): bigint;
33
33
  export declare function writeUint(bc: ByteCursor, x: bigint): void;
34
+ export declare function readUintSafe32(bc: ByteCursor): number;
35
+ export declare function writeUintSafe32(bc: ByteCursor, x: number): void;
34
36
  export declare function readUintSafe(bc: ByteCursor): number;
35
37
  export declare function writeUintSafe(bc: ByteCursor, x: number): void;