@bare-ts/lib 0.4.0 → 0.5.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.
- package/README.md +7 -8
- package/dist/codec/data.js +1 -1
- package/dist/codec/float-array.d.ts +6 -11
- package/dist/codec/float-array.js +3 -3
- package/dist/codec/i16-array.d.ts +3 -6
- package/dist/codec/i16-array.js +2 -2
- package/dist/codec/i32-array.d.ts +3 -6
- package/dist/codec/i32-array.js +2 -2
- package/dist/codec/i64-array.d.ts +3 -6
- package/dist/codec/i64-array.js +2 -2
- package/dist/codec/i8-array.d.ts +2 -2
- package/dist/codec/i8-array.js +1 -1
- package/dist/codec/primitive.js +3 -3
- package/dist/codec/string.js +1 -1
- package/dist/codec/u16-array.d.ts +3 -6
- package/dist/codec/u16-array.js +2 -2
- package/dist/codec/u32-array.d.ts +3 -6
- package/dist/codec/u32-array.js +2 -2
- package/dist/codec/u64-array.d.ts +3 -6
- package/dist/codec/u64-array.js +2 -2
- package/dist/codec/u8-array.d.ts +2 -2
- package/dist/codec/u8-array.js +2 -2
- package/dist/codec/u8-clamped-array.d.ts +2 -2
- package/dist/codec/u8-clamped-array.js +1 -1
- package/dist/core/byte-cursor.js +1 -1
- package/dist/core/config.d.ts +2 -4
- package/dist/core/config.js +2 -1
- package/dist/index.cjs +53 -50
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
# bare-ts library
|
|
2
2
|
|
|
3
|
-
[![CI status][ci-img]][ci-url]
|
|
4
|
-
[![Coverage percentage][coveralls-img]][coveralls-url]
|
|
5
|
-
[![minified and gzipped size][bundlephobia-img]][bundlephobia-url]
|
|
6
3
|
[![NPM version][npm-img]][npm-url]
|
|
4
|
+
[![minified and gzipped size][bundlephobia-img]][bundlephobia-url]
|
|
5
|
+
[![Coverage percentage][coveralls-img]][coveralls-url]
|
|
7
6
|
|
|
8
7
|
[BARE][bare] (Binary Application Record Encoding) is a schema-based binary format that favors compactness and simplicity.
|
|
9
8
|
[bare-ts/lib](#) provides decoders and encoders for basic BARE types.
|
|
10
9
|
|
|
11
|
-
Please, take a look to [bare-ts/
|
|
10
|
+
Please, take a look to [bare-ts/bare][bare-ts-bare] for more information.
|
|
12
11
|
|
|
13
12
|
Warning: BARE specification is currently a IEF draft.
|
|
14
|
-
The specification is likely to evolve before its final release.
|
|
13
|
+
The specification is likely to evolve before its final release.
|
|
14
|
+
However, most of the changes since the beginning concern the schema language.
|
|
15
|
+
The binary format is fairly stable.
|
|
15
16
|
|
|
16
17
|
[bare]: https://baremessages.org
|
|
17
|
-
[bare-ts-
|
|
18
|
-
[ci-img]: https://img.shields.io/github/workflow/status/bare-ts/lib/CI?label=CI&style=flat-square
|
|
19
|
-
[ci-url]: https://github.com/bare-ts/lib/actions/workflows/ci.yml
|
|
18
|
+
[bare-ts-bare]: https://github.com/bare-ts/bare
|
|
20
19
|
[npm-img]: https://img.shields.io/npm/v/@bare-ts/lib.svg?style=flat-square
|
|
21
20
|
[npm-url]: https://www.npmjs.com/package/@bare-ts/lib
|
|
22
21
|
[coveralls-img]: https://img.shields.io/coveralls/github/bare-ts/lib?style=flat-square
|
package/dist/codec/data.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
-
export declare const readF32FixedArray:
|
|
3
|
-
declare
|
|
4
|
-
export declare
|
|
5
|
-
declare function writeF32FixedArrayLe(bc: ByteCursor, x: Float32Array): void;
|
|
6
|
-
export declare function readF32Array(bc: ByteCursor): Float32Array;
|
|
2
|
+
export declare const readF32FixedArray: (bc: ByteCursor, len: number) => Float32Array<ArrayBuffer>;
|
|
3
|
+
export declare const writeF32FixedArray: (bc: ByteCursor, x: Float32Array) => void;
|
|
4
|
+
export declare function readF32Array(bc: ByteCursor): Float32Array<ArrayBuffer>;
|
|
7
5
|
export declare function writeF32Array(bc: ByteCursor, x: Float32Array): void;
|
|
8
|
-
export declare const readF64FixedArray:
|
|
9
|
-
declare
|
|
10
|
-
export declare
|
|
11
|
-
declare function writeF64FixedArrayLe(bc: ByteCursor, x: Float64Array): void;
|
|
12
|
-
export declare function readF64Array(bc: ByteCursor): Float64Array;
|
|
6
|
+
export declare const readF64FixedArray: (bc: ByteCursor, len: number) => Float64Array<ArrayBuffer>;
|
|
7
|
+
export declare const writeF64FixedArray: (bc: ByteCursor, x: Float64Array) => void;
|
|
8
|
+
export declare function readF64Array(bc: ByteCursor): Float64Array<ArrayBuffer>;
|
|
13
9
|
export declare function writeF64Array(bc: ByteCursor, x: Float64Array): void;
|
|
14
|
-
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
-
import {
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
4
|
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/constants.js";
|
|
5
5
|
import { isU32 } from "../util/validator.js";
|
|
6
6
|
import { readFixedData } from "./data.js";
|
|
@@ -48,7 +48,7 @@ export function readF32Array(bc) {
|
|
|
48
48
|
}
|
|
49
49
|
export function writeF32Array(bc, x) {
|
|
50
50
|
writeUintSafe32(bc, x.length);
|
|
51
|
-
if (x.length
|
|
51
|
+
if (x.length > 0) {
|
|
52
52
|
writeF32FixedArray(bc, x);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -87,7 +87,7 @@ export function readF64Array(bc) {
|
|
|
87
87
|
}
|
|
88
88
|
export function writeF64Array(bc, x) {
|
|
89
89
|
writeUintSafe32(bc, x.length);
|
|
90
|
-
if (x.length
|
|
90
|
+
if (x.length > 0) {
|
|
91
91
|
writeF64FixedArray(bc, x);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
-
export declare const readI16FixedArray:
|
|
3
|
-
export declare function readI16Array(bc: ByteCursor): Int16Array
|
|
4
|
-
declare
|
|
5
|
-
export declare const writeI16FixedArray: typeof writeI16FixedArrayLe;
|
|
2
|
+
export declare const readI16FixedArray: (bc: ByteCursor, len: number) => Int16Array<ArrayBuffer>;
|
|
3
|
+
export declare function readI16Array(bc: ByteCursor): Int16Array<ArrayBuffer>;
|
|
4
|
+
export declare const writeI16FixedArray: (bc: ByteCursor, x: Int16Array) => void;
|
|
6
5
|
export declare function writeI16Array(bc: ByteCursor, x: Int16Array): void;
|
|
7
|
-
declare function writeI16FixedArrayLe(bc: ByteCursor, x: Int16Array): void;
|
|
8
|
-
export {};
|
package/dist/codec/i16-array.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
-
import {
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
4
|
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/constants.js";
|
|
5
5
|
import { isU32 } from "../util/validator.js";
|
|
6
6
|
import { readFixedData } from "./data.js";
|
|
@@ -36,7 +36,7 @@ function readI16FixedArrayBe(bc, len) {
|
|
|
36
36
|
export const writeI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI16FixedArrayLe : writeI16FixedArrayBe;
|
|
37
37
|
export function writeI16Array(bc, x) {
|
|
38
38
|
writeUintSafe32(bc, x.length);
|
|
39
|
-
if (x.length
|
|
39
|
+
if (x.length > 0) {
|
|
40
40
|
writeI16FixedArray(bc, x);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
-
export declare const readI32FixedArray:
|
|
3
|
-
export declare function readI32Array(bc: ByteCursor): Int32Array
|
|
4
|
-
declare
|
|
5
|
-
export declare const writeI32FixedArray: typeof writeI32FixedArrayLe;
|
|
2
|
+
export declare const readI32FixedArray: (bc: ByteCursor, len: number) => Int32Array<ArrayBuffer>;
|
|
3
|
+
export declare function readI32Array(bc: ByteCursor): Int32Array<ArrayBuffer>;
|
|
4
|
+
export declare const writeI32FixedArray: (bc: ByteCursor, x: Int32Array) => void;
|
|
6
5
|
export declare function writeI32Array(bc: ByteCursor, x: Int32Array): void;
|
|
7
|
-
declare function writeI32FixedArrayLe(bc: ByteCursor, x: Int32Array): void;
|
|
8
|
-
export {};
|
package/dist/codec/i32-array.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
-
import {
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
4
|
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/constants.js";
|
|
5
5
|
import { isU32 } from "../util/validator.js";
|
|
6
6
|
import { readFixedData } from "./data.js";
|
|
@@ -36,7 +36,7 @@ function readI32FixedArrayBe(bc, len) {
|
|
|
36
36
|
export const writeI32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI32FixedArrayLe : writeI32FixedArrayBe;
|
|
37
37
|
export function writeI32Array(bc, x) {
|
|
38
38
|
writeUintSafe32(bc, x.length);
|
|
39
|
-
if (x.length
|
|
39
|
+
if (x.length > 0) {
|
|
40
40
|
writeI32FixedArray(bc, x);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
-
export declare const readI64FixedArray:
|
|
3
|
-
export declare function readI64Array(bc: ByteCursor): BigInt64Array
|
|
4
|
-
declare
|
|
5
|
-
export declare const writeI64FixedArray: typeof writeI64FixedArrayLe;
|
|
2
|
+
export declare const readI64FixedArray: (bc: ByteCursor, len: number) => BigInt64Array<ArrayBuffer>;
|
|
3
|
+
export declare function readI64Array(bc: ByteCursor): BigInt64Array<ArrayBuffer>;
|
|
4
|
+
export declare const writeI64FixedArray: (bc: ByteCursor, x: BigInt64Array) => void;
|
|
6
5
|
export declare function writeI64Array(bc: ByteCursor, x: BigInt64Array): void;
|
|
7
|
-
declare function writeI64FixedArrayLe(bc: ByteCursor, x: BigInt64Array): void;
|
|
8
|
-
export {};
|
package/dist/codec/i64-array.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
-
import {
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
4
|
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/constants.js";
|
|
5
5
|
import { isU32 } from "../util/validator.js";
|
|
6
6
|
import { readFixedData } from "./data.js";
|
|
@@ -36,7 +36,7 @@ function readI64FixedArrayBe(bc, len) {
|
|
|
36
36
|
export const writeI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI64FixedArrayLe : writeI64FixedArrayBe;
|
|
37
37
|
export function writeI64Array(bc, x) {
|
|
38
38
|
writeUintSafe32(bc, x.length);
|
|
39
|
-
if (x.length
|
|
39
|
+
if (x.length > 0) {
|
|
40
40
|
writeI64FixedArray(bc, x);
|
|
41
41
|
}
|
|
42
42
|
}
|
package/dist/codec/i8-array.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
-
export declare function readI8Array(bc: ByteCursor): Int8Array
|
|
2
|
+
export declare function readI8Array(bc: ByteCursor): Int8Array<ArrayBuffer>;
|
|
3
3
|
export declare function writeI8Array(bc: ByteCursor, x: Int8Array): void;
|
|
4
|
-
export declare function readI8FixedArray(bc: ByteCursor, len: number): Int8Array
|
|
4
|
+
export declare function readI8FixedArray(bc: ByteCursor, len: number): Int8Array<ArrayBuffer>;
|
|
5
5
|
export declare function writeI8FixedArray(bc: ByteCursor, x: Int8Array): void;
|
package/dist/codec/i8-array.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { assert, DEV } from "../util/assert.js";
|
|
3
3
|
import { isU32 } from "../util/validator.js";
|
|
4
4
|
import { readFixedData } from "./data.js";
|
|
5
5
|
import { readUintSafe, writeUintSafe32 } from "./primitive.js";
|
package/dist/codec/primitive.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { BareError } from "../core/bare-error.js";
|
|
3
3
|
import { check, reserve } from "../core/byte-cursor.js";
|
|
4
|
-
import {
|
|
4
|
+
import { assert, DEV } from "../util/assert.js";
|
|
5
5
|
import {
|
|
6
6
|
INT_SAFE_MAX_BYTE_COUNT,
|
|
7
7
|
NON_CANONICAL_REPRESENTATION,
|
|
@@ -26,7 +26,7 @@ export function readBool(bc) {
|
|
|
26
26
|
bc.offset--;
|
|
27
27
|
throw new BareError(bc.offset, "a bool must be equal to 0 or 1");
|
|
28
28
|
}
|
|
29
|
-
return val
|
|
29
|
+
return val > 0;
|
|
30
30
|
}
|
|
31
31
|
export function writeBool(bc, x) {
|
|
32
32
|
writeU8(bc, x ? 1 : 0);
|
|
@@ -323,7 +323,7 @@ function writeTruncatedUint(bc, x) {
|
|
|
323
323
|
let tmp = Number(BigInt.asUintN(7 * 7, x));
|
|
324
324
|
let rest = Number(x >> BigInt(7 * 7));
|
|
325
325
|
let byteCount = 0;
|
|
326
|
-
while (tmp >= 128 || rest
|
|
326
|
+
while (tmp >= 128 || rest > 0) {
|
|
327
327
|
writeU8(bc, 128 | tmp & 127);
|
|
328
328
|
tmp = Math.floor(tmp / /* 2**7 */
|
|
329
329
|
128);
|
package/dist/codec/string.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { BareError } from "../core/bare-error.js";
|
|
3
3
|
import { check, reserve } from "../core/byte-cursor.js";
|
|
4
|
-
import {
|
|
4
|
+
import { assert, DEV } from "../util/assert.js";
|
|
5
5
|
import {
|
|
6
6
|
INVALID_UTF8_STRING,
|
|
7
7
|
TEXT_DECODER_THRESHOLD,
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
-
export declare const readU16FixedArray:
|
|
3
|
-
export declare function readU16Array(bc: ByteCursor): Uint16Array
|
|
4
|
-
declare
|
|
5
|
-
export declare const writeU16FixedArray: typeof writeU16FixedArrayLe;
|
|
2
|
+
export declare const readU16FixedArray: (bc: ByteCursor, len: number) => Uint16Array<ArrayBuffer>;
|
|
3
|
+
export declare function readU16Array(bc: ByteCursor): Uint16Array<ArrayBuffer>;
|
|
4
|
+
export declare const writeU16FixedArray: (bc: ByteCursor, x: Uint16Array) => void;
|
|
6
5
|
export declare function writeU16Array(bc: ByteCursor, x: Uint16Array): void;
|
|
7
|
-
declare function writeU16FixedArrayLe(bc: ByteCursor, x: Uint16Array): void;
|
|
8
|
-
export {};
|
package/dist/codec/u16-array.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
-
import {
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
4
|
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/constants.js";
|
|
5
5
|
import { isU32 } from "../util/validator.js";
|
|
6
6
|
import { readFixedData } from "./data.js";
|
|
@@ -36,7 +36,7 @@ function readU16FixedArrayBe(bc, len) {
|
|
|
36
36
|
export const writeU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU16FixedArrayLe : writeU16FixedArrayBe;
|
|
37
37
|
export function writeU16Array(bc, x) {
|
|
38
38
|
writeUintSafe32(bc, x.length);
|
|
39
|
-
if (x.length
|
|
39
|
+
if (x.length > 0) {
|
|
40
40
|
writeU16FixedArray(bc, x);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
-
export declare const readU32FixedArray:
|
|
3
|
-
export declare function readU32Array(bc: ByteCursor): Uint32Array
|
|
4
|
-
declare
|
|
5
|
-
export declare const writeU32FixedArray: typeof writeU32FixedArrayLe;
|
|
2
|
+
export declare const readU32FixedArray: (bc: ByteCursor, len: number) => Uint32Array<ArrayBuffer>;
|
|
3
|
+
export declare function readU32Array(bc: ByteCursor): Uint32Array<ArrayBuffer>;
|
|
4
|
+
export declare const writeU32FixedArray: (bc: ByteCursor, x: Uint32Array) => void;
|
|
6
5
|
export declare function writeU32Array(bc: ByteCursor, x: Uint32Array): void;
|
|
7
|
-
declare function writeU32FixedArrayLe(bc: ByteCursor, x: Uint32Array): void;
|
|
8
|
-
export {};
|
package/dist/codec/u32-array.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
-
import {
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
4
|
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/constants.js";
|
|
5
5
|
import { isU32 } from "../util/validator.js";
|
|
6
6
|
import { readFixedData } from "./data.js";
|
|
@@ -36,7 +36,7 @@ function readU32FixedArrayBe(bc, len) {
|
|
|
36
36
|
export const writeU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU32FixedArrayLe : writeU32FixedArrayBe;
|
|
37
37
|
export function writeU32Array(bc, x) {
|
|
38
38
|
writeUintSafe32(bc, x.length);
|
|
39
|
-
if (x.length
|
|
39
|
+
if (x.length > 0) {
|
|
40
40
|
writeU32FixedArray(bc, x);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
-
export declare const readU64FixedArray:
|
|
3
|
-
export declare function readU64Array(bc: ByteCursor): BigUint64Array
|
|
4
|
-
declare
|
|
5
|
-
export declare const writeU64FixedArray: typeof writeU64FixedArrayLe;
|
|
2
|
+
export declare const readU64FixedArray: (bc: ByteCursor, len: number) => BigUint64Array<ArrayBuffer>;
|
|
3
|
+
export declare function readU64Array(bc: ByteCursor): BigUint64Array<ArrayBuffer>;
|
|
4
|
+
export declare const writeU64FixedArray: (bc: ByteCursor, x: BigUint64Array) => void;
|
|
6
5
|
export declare function writeU64Array(bc: ByteCursor, x: BigUint64Array): void;
|
|
7
|
-
declare function writeU64FixedArrayLe(bc: ByteCursor, x: BigUint64Array): void;
|
|
8
|
-
export {};
|
package/dist/codec/u64-array.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
-
import {
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
4
|
import { IS_LITTLE_ENDIAN_PLATFORM } from "../util/constants.js";
|
|
5
5
|
import { isU32 } from "../util/validator.js";
|
|
6
6
|
import { readFixedData } from "./data.js";
|
|
@@ -36,7 +36,7 @@ function readU64FixedArrayBe(bc, len) {
|
|
|
36
36
|
export const writeU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU64FixedArrayLe : writeU64FixedArrayBe;
|
|
37
37
|
export function writeU64Array(bc, x) {
|
|
38
38
|
writeUintSafe32(bc, x.length);
|
|
39
|
-
if (x.length
|
|
39
|
+
if (x.length > 0) {
|
|
40
40
|
writeU64FixedArray(bc, x);
|
|
41
41
|
}
|
|
42
42
|
}
|
package/dist/codec/u8-array.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
-
export declare function readU8Array(bc: ByteCursor): Uint8Array
|
|
2
|
+
export declare function readU8Array(bc: ByteCursor): Uint8Array<ArrayBuffer>;
|
|
3
3
|
export declare function writeU8Array(bc: ByteCursor, x: Uint8Array): void;
|
|
4
|
-
export declare function readU8FixedArray(bc: ByteCursor, len: number): Uint8Array
|
|
4
|
+
export declare function readU8FixedArray(bc: ByteCursor, len: number): Uint8Array<ArrayBuffer>;
|
|
5
5
|
export declare function writeU8FixedArray(bc: ByteCursor, x: Uint8Array): void;
|
|
6
6
|
/**
|
|
7
7
|
* Advance `bc` by `len` bytes and return a view of the read bytes.
|
package/dist/codec/u8-array.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { check, reserve } from "../core/byte-cursor.js";
|
|
3
|
-
import {
|
|
3
|
+
import { assert, DEV } from "../util/assert.js";
|
|
4
4
|
import { isU32 } from "../util/validator.js";
|
|
5
5
|
import { readUintSafe32, writeUintSafe32 } from "./primitive.js";
|
|
6
6
|
export function readU8Array(bc) {
|
|
@@ -15,7 +15,7 @@ export function readU8FixedArray(bc, len) {
|
|
|
15
15
|
}
|
|
16
16
|
export function writeU8FixedArray(bc, x) {
|
|
17
17
|
const len = x.length;
|
|
18
|
-
if (len
|
|
18
|
+
if (len > 0) {
|
|
19
19
|
reserve(bc, len);
|
|
20
20
|
bc.bytes.set(x, bc.offset);
|
|
21
21
|
bc.offset += len;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ByteCursor } from "../core/byte-cursor.js";
|
|
2
|
-
export declare function readU8ClampedArray(bc: ByteCursor): Uint8ClampedArray
|
|
2
|
+
export declare function readU8ClampedArray(bc: ByteCursor): Uint8ClampedArray<ArrayBuffer>;
|
|
3
3
|
export declare function writeU8ClampedArray(bc: ByteCursor, x: Uint8ClampedArray): void;
|
|
4
|
-
export declare function readU8ClampedFixedArray(bc: ByteCursor, len: number): Uint8ClampedArray
|
|
4
|
+
export declare function readU8ClampedFixedArray(bc: ByteCursor, len: number): Uint8ClampedArray<ArrayBuffer>;
|
|
5
5
|
export declare function writeU8ClampedFixedArray(bc: ByteCursor, x: Uint8ClampedArray): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { assert, DEV } from "../util/assert.js";
|
|
3
3
|
import { isU32 } from "../util/validator.js";
|
|
4
4
|
import { readFixedData } from "./data.js";
|
|
5
5
|
import { readUintSafe32, writeUintSafe32 } from "./primitive.js";
|
package/dist/core/byte-cursor.js
CHANGED
package/dist/core/config.d.ts
CHANGED
|
@@ -2,7 +2,5 @@ export type Config = {
|
|
|
2
2
|
readonly initialBufferLength: number;
|
|
3
3
|
readonly maxBufferLength: number;
|
|
4
4
|
};
|
|
5
|
-
export declare function Config({ initialBufferLength, maxBufferLength, }:
|
|
6
|
-
|
|
7
|
-
maxBufferLength?: number | undefined;
|
|
8
|
-
}): Config;
|
|
5
|
+
export declare function Config({ initialBufferLength, maxBufferLength, }: Partial<Config>): Config;
|
|
6
|
+
export declare const DEFAULT_CONFIG: Config;
|
package/dist/core/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
2
|
+
import { assert, DEV } from "../util/assert.js";
|
|
3
3
|
import { TOO_LARGE_NUMBER } from "../util/constants.js";
|
|
4
4
|
import { isU32 } from "../util/validator.js";
|
|
5
5
|
export function Config({
|
|
@@ -19,3 +19,4 @@ export function Config({
|
|
|
19
19
|
maxBufferLength
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
export const DEFAULT_CONFIG = /* @__PURE__ */ Config({});
|
package/dist/index.cjs
CHANGED
|
@@ -18,11 +18,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
BareError: () => BareError,
|
|
24
24
|
ByteCursor: () => ByteCursor,
|
|
25
25
|
Config: () => Config,
|
|
26
|
+
DEFAULT_CONFIG: () => DEFAULT_CONFIG,
|
|
26
27
|
check: () => check,
|
|
27
28
|
readBool: () => readBool,
|
|
28
29
|
readData: () => readData,
|
|
@@ -115,7 +116,7 @@ __export(src_exports, {
|
|
|
115
116
|
writeUintSafe: () => writeUintSafe,
|
|
116
117
|
writeUintSafe32: () => writeUintSafe32
|
|
117
118
|
});
|
|
118
|
-
module.exports = __toCommonJS(
|
|
119
|
+
module.exports = __toCommonJS(index_exports);
|
|
119
120
|
|
|
120
121
|
// dist/env/dev.node.js
|
|
121
122
|
var DEV = process.env.NODE_ENV === "development";
|
|
@@ -240,7 +241,7 @@ function readBool(bc) {
|
|
|
240
241
|
bc.offset--;
|
|
241
242
|
throw new BareError(bc.offset, "a bool must be equal to 0 or 1");
|
|
242
243
|
}
|
|
243
|
-
return val
|
|
244
|
+
return val > 0;
|
|
244
245
|
}
|
|
245
246
|
function writeBool(bc, x) {
|
|
246
247
|
writeU8(bc, x ? 1 : 0);
|
|
@@ -537,7 +538,7 @@ function writeTruncatedUint(bc, x) {
|
|
|
537
538
|
let tmp = Number(BigInt.asUintN(7 * 7, x));
|
|
538
539
|
let rest = Number(x >> BigInt(7 * 7));
|
|
539
540
|
let byteCount = 0;
|
|
540
|
-
while (tmp >= 128 || rest
|
|
541
|
+
while (tmp >= 128 || rest > 0) {
|
|
541
542
|
writeU8(bc, 128 | tmp & 127);
|
|
542
543
|
tmp = Math.floor(tmp / /* 2**7 */
|
|
543
544
|
128);
|
|
@@ -649,7 +650,7 @@ function readU8FixedArray(bc, len) {
|
|
|
649
650
|
}
|
|
650
651
|
function writeU8FixedArray(bc, x) {
|
|
651
652
|
const len = x.length;
|
|
652
|
-
if (len
|
|
653
|
+
if (len > 0) {
|
|
653
654
|
reserve(bc, len);
|
|
654
655
|
bc.bytes.set(x, bc.offset);
|
|
655
656
|
bc.offset += len;
|
|
@@ -718,7 +719,7 @@ function readF32Array(bc) {
|
|
|
718
719
|
}
|
|
719
720
|
function writeF32Array(bc, x) {
|
|
720
721
|
writeUintSafe32(bc, x.length);
|
|
721
|
-
if (x.length
|
|
722
|
+
if (x.length > 0) {
|
|
722
723
|
writeF32FixedArray(bc, x);
|
|
723
724
|
}
|
|
724
725
|
}
|
|
@@ -757,11 +758,29 @@ function readF64Array(bc) {
|
|
|
757
758
|
}
|
|
758
759
|
function writeF64Array(bc, x) {
|
|
759
760
|
writeUintSafe32(bc, x.length);
|
|
760
|
-
if (x.length
|
|
761
|
+
if (x.length > 0) {
|
|
761
762
|
writeF64FixedArray(bc, x);
|
|
762
763
|
}
|
|
763
764
|
}
|
|
764
765
|
|
|
766
|
+
// src/codec/i8-array.ts
|
|
767
|
+
function readI8Array(bc) {
|
|
768
|
+
return readI8FixedArray(bc, readUintSafe(bc));
|
|
769
|
+
}
|
|
770
|
+
function writeI8Array(bc, x) {
|
|
771
|
+
writeUintSafe32(bc, x.length);
|
|
772
|
+
writeI8FixedArray(bc, x);
|
|
773
|
+
}
|
|
774
|
+
function readI8FixedArray(bc, len) {
|
|
775
|
+
if (DEV) {
|
|
776
|
+
assert(isU32(len));
|
|
777
|
+
}
|
|
778
|
+
return new Int8Array(readFixedData(bc, len));
|
|
779
|
+
}
|
|
780
|
+
function writeI8FixedArray(bc, x) {
|
|
781
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
782
|
+
}
|
|
783
|
+
|
|
765
784
|
// src/codec/i16-array.ts
|
|
766
785
|
var readI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI16FixedArrayLe : readI16FixedArrayBe;
|
|
767
786
|
function readI16Array(bc) {
|
|
@@ -788,7 +807,7 @@ function readI16FixedArrayBe(bc, len) {
|
|
|
788
807
|
var writeI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI16FixedArrayLe : writeI16FixedArrayBe;
|
|
789
808
|
function writeI16Array(bc, x) {
|
|
790
809
|
writeUintSafe32(bc, x.length);
|
|
791
|
-
if (x.length
|
|
810
|
+
if (x.length > 0) {
|
|
792
811
|
writeI16FixedArray(bc, x);
|
|
793
812
|
}
|
|
794
813
|
}
|
|
@@ -828,7 +847,7 @@ function readI32FixedArrayBe(bc, len) {
|
|
|
828
847
|
var writeI32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI32FixedArrayLe : writeI32FixedArrayBe;
|
|
829
848
|
function writeI32Array(bc, x) {
|
|
830
849
|
writeUintSafe32(bc, x.length);
|
|
831
|
-
if (x.length
|
|
850
|
+
if (x.length > 0) {
|
|
832
851
|
writeI32FixedArray(bc, x);
|
|
833
852
|
}
|
|
834
853
|
}
|
|
@@ -868,7 +887,7 @@ function readI64FixedArrayBe(bc, len) {
|
|
|
868
887
|
var writeI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI64FixedArrayLe : writeI64FixedArrayBe;
|
|
869
888
|
function writeI64Array(bc, x) {
|
|
870
889
|
writeUintSafe32(bc, x.length);
|
|
871
|
-
if (x.length
|
|
890
|
+
if (x.length > 0) {
|
|
872
891
|
writeI64FixedArray(bc, x);
|
|
873
892
|
}
|
|
874
893
|
}
|
|
@@ -882,24 +901,6 @@ function writeI64FixedArrayBe(bc, x) {
|
|
|
882
901
|
}
|
|
883
902
|
}
|
|
884
903
|
|
|
885
|
-
// src/codec/i8-array.ts
|
|
886
|
-
function readI8Array(bc) {
|
|
887
|
-
return readI8FixedArray(bc, readUintSafe(bc));
|
|
888
|
-
}
|
|
889
|
-
function writeI8Array(bc, x) {
|
|
890
|
-
writeUintSafe32(bc, x.length);
|
|
891
|
-
writeI8FixedArray(bc, x);
|
|
892
|
-
}
|
|
893
|
-
function readI8FixedArray(bc, len) {
|
|
894
|
-
if (DEV) {
|
|
895
|
-
assert(isU32(len));
|
|
896
|
-
}
|
|
897
|
-
return new Int8Array(readFixedData(bc, len));
|
|
898
|
-
}
|
|
899
|
-
function writeI8FixedArray(bc, x) {
|
|
900
|
-
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
901
|
-
}
|
|
902
|
-
|
|
903
904
|
// src/codec/string.ts
|
|
904
905
|
function readString(bc) {
|
|
905
906
|
return readFixedString(bc, readUintSafe32(bc));
|
|
@@ -1030,6 +1031,24 @@ function utf8ByteLength(s) {
|
|
|
1030
1031
|
var UTF8_DECODER = /* @__PURE__ */ new TextDecoder("utf-8", { fatal: true });
|
|
1031
1032
|
var UTF8_ENCODER = /* @__PURE__ */ new TextEncoder();
|
|
1032
1033
|
|
|
1034
|
+
// src/codec/u8-clamped-array.ts
|
|
1035
|
+
function readU8ClampedArray(bc) {
|
|
1036
|
+
return readU8ClampedFixedArray(bc, readUintSafe32(bc));
|
|
1037
|
+
}
|
|
1038
|
+
function writeU8ClampedArray(bc, x) {
|
|
1039
|
+
writeUintSafe32(bc, x.length);
|
|
1040
|
+
writeU8ClampedFixedArray(bc, x);
|
|
1041
|
+
}
|
|
1042
|
+
function readU8ClampedFixedArray(bc, len) {
|
|
1043
|
+
if (DEV) {
|
|
1044
|
+
assert(isU32(len));
|
|
1045
|
+
}
|
|
1046
|
+
return new Uint8ClampedArray(readFixedData(bc, len));
|
|
1047
|
+
}
|
|
1048
|
+
function writeU8ClampedFixedArray(bc, x) {
|
|
1049
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1033
1052
|
// src/codec/u16-array.ts
|
|
1034
1053
|
var readU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU16FixedArrayLe : readU16FixedArrayBe;
|
|
1035
1054
|
function readU16Array(bc) {
|
|
@@ -1056,7 +1075,7 @@ function readU16FixedArrayBe(bc, len) {
|
|
|
1056
1075
|
var writeU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU16FixedArrayLe : writeU16FixedArrayBe;
|
|
1057
1076
|
function writeU16Array(bc, x) {
|
|
1058
1077
|
writeUintSafe32(bc, x.length);
|
|
1059
|
-
if (x.length
|
|
1078
|
+
if (x.length > 0) {
|
|
1060
1079
|
writeU16FixedArray(bc, x);
|
|
1061
1080
|
}
|
|
1062
1081
|
}
|
|
@@ -1096,7 +1115,7 @@ function readU32FixedArrayBe(bc, len) {
|
|
|
1096
1115
|
var writeU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU32FixedArrayLe : writeU32FixedArrayBe;
|
|
1097
1116
|
function writeU32Array(bc, x) {
|
|
1098
1117
|
writeUintSafe32(bc, x.length);
|
|
1099
|
-
if (x.length
|
|
1118
|
+
if (x.length > 0) {
|
|
1100
1119
|
writeU32FixedArray(bc, x);
|
|
1101
1120
|
}
|
|
1102
1121
|
}
|
|
@@ -1136,7 +1155,7 @@ function readU64FixedArrayBe(bc, len) {
|
|
|
1136
1155
|
var writeU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU64FixedArrayLe : writeU64FixedArrayBe;
|
|
1137
1156
|
function writeU64Array(bc, x) {
|
|
1138
1157
|
writeUintSafe32(bc, x.length);
|
|
1139
|
-
if (x.length
|
|
1158
|
+
if (x.length > 0) {
|
|
1140
1159
|
writeU64FixedArray(bc, x);
|
|
1141
1160
|
}
|
|
1142
1161
|
}
|
|
@@ -1150,24 +1169,6 @@ function writeU64FixedArrayBe(bc, x) {
|
|
|
1150
1169
|
}
|
|
1151
1170
|
}
|
|
1152
1171
|
|
|
1153
|
-
// src/codec/u8-clamped-array.ts
|
|
1154
|
-
function readU8ClampedArray(bc) {
|
|
1155
|
-
return readU8ClampedFixedArray(bc, readUintSafe32(bc));
|
|
1156
|
-
}
|
|
1157
|
-
function writeU8ClampedArray(bc, x) {
|
|
1158
|
-
writeUintSafe32(bc, x.length);
|
|
1159
|
-
writeU8ClampedFixedArray(bc, x);
|
|
1160
|
-
}
|
|
1161
|
-
function readU8ClampedFixedArray(bc, len) {
|
|
1162
|
-
if (DEV) {
|
|
1163
|
-
assert(isU32(len));
|
|
1164
|
-
}
|
|
1165
|
-
return new Uint8ClampedArray(readFixedData(bc, len));
|
|
1166
|
-
}
|
|
1167
|
-
function writeU8ClampedFixedArray(bc, x) {
|
|
1168
|
-
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
1172
|
// src/core/config.ts
|
|
1172
1173
|
function Config({
|
|
1173
1174
|
initialBufferLength = 1024,
|
|
@@ -1186,11 +1187,13 @@ function Config({
|
|
|
1186
1187
|
maxBufferLength
|
|
1187
1188
|
};
|
|
1188
1189
|
}
|
|
1190
|
+
var DEFAULT_CONFIG = /* @__PURE__ */ Config({});
|
|
1189
1191
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1190
1192
|
0 && (module.exports = {
|
|
1191
1193
|
BareError,
|
|
1192
1194
|
ByteCursor,
|
|
1193
1195
|
Config,
|
|
1196
|
+
DEFAULT_CONFIG,
|
|
1194
1197
|
check,
|
|
1195
1198
|
readBool,
|
|
1196
1199
|
readData,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export * from "./codec/data.js";
|
|
2
2
|
export * from "./codec/float-array.js";
|
|
3
|
+
export * from "./codec/i8-array.js";
|
|
3
4
|
export * from "./codec/i16-array.js";
|
|
4
5
|
export * from "./codec/i32-array.js";
|
|
5
6
|
export * from "./codec/i64-array.js";
|
|
6
|
-
export * from "./codec/i8-array.js";
|
|
7
7
|
export * from "./codec/primitive.js";
|
|
8
8
|
export * from "./codec/string.js";
|
|
9
|
+
export * from "./codec/u8-array.js";
|
|
10
|
+
export * from "./codec/u8-clamped-array.js";
|
|
9
11
|
export * from "./codec/u16-array.js";
|
|
10
12
|
export * from "./codec/u32-array.js";
|
|
11
13
|
export * from "./codec/u64-array.js";
|
|
12
|
-
export * from "./codec/u8-array.js";
|
|
13
|
-
export * from "./codec/u8-clamped-array.js";
|
|
14
14
|
export * from "./core/bare-error.js";
|
|
15
15
|
export * from "./core/byte-cursor.js";
|
|
16
16
|
export * from "./core/config.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export * from "./codec/data.js";
|
|
2
2
|
export * from "./codec/float-array.js";
|
|
3
|
+
export * from "./codec/i8-array.js";
|
|
3
4
|
export * from "./codec/i16-array.js";
|
|
4
5
|
export * from "./codec/i32-array.js";
|
|
5
6
|
export * from "./codec/i64-array.js";
|
|
6
|
-
export * from "./codec/i8-array.js";
|
|
7
7
|
export * from "./codec/primitive.js";
|
|
8
8
|
export * from "./codec/string.js";
|
|
9
|
+
export * from "./codec/u8-array.js";
|
|
10
|
+
export * from "./codec/u8-clamped-array.js";
|
|
9
11
|
export * from "./codec/u16-array.js";
|
|
10
12
|
export * from "./codec/u32-array.js";
|
|
11
13
|
export * from "./codec/u64-array.js";
|
|
12
|
-
export * from "./codec/u8-array.js";
|
|
13
|
-
export * from "./codec/u8-clamped-array.js";
|
|
14
14
|
export * from "./core/bare-error.js";
|
|
15
15
|
export * from "./core/byte-cursor.js";
|
|
16
16
|
export * from "./core/config.js";
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
export * from "./codec/data.js";
|
|
3
3
|
export * from "./codec/float-array.js";
|
|
4
|
+
export * from "./codec/i8-array.js";
|
|
4
5
|
export * from "./codec/i16-array.js";
|
|
5
6
|
export * from "./codec/i32-array.js";
|
|
6
7
|
export * from "./codec/i64-array.js";
|
|
7
|
-
export * from "./codec/i8-array.js";
|
|
8
8
|
export * from "./codec/primitive.js";
|
|
9
9
|
export * from "./codec/string.js";
|
|
10
|
+
export * from "./codec/u8-array.js";
|
|
11
|
+
export * from "./codec/u8-clamped-array.js";
|
|
10
12
|
export * from "./codec/u16-array.js";
|
|
11
13
|
export * from "./codec/u32-array.js";
|
|
12
14
|
export * from "./codec/u64-array.js";
|
|
13
|
-
export * from "./codec/u8-array.js";
|
|
14
|
-
export * from "./codec/u8-clamped-array.js";
|
|
15
15
|
export * from "./core/bare-error.js";
|
|
16
16
|
export * from "./core/byte-cursor.js";
|
|
17
17
|
export * from "./core/config.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bare-ts/lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "TypeScript library for BARE, a compact and simple binary-serialization format",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bare",
|
|
@@ -24,17 +24,16 @@
|
|
|
24
24
|
"node": "^14.18.0 || >=16.0.0"
|
|
25
25
|
},
|
|
26
26
|
"type": "module",
|
|
27
|
-
"module": "./dist/index.js",
|
|
28
|
-
"main": "./dist/index.cjs",
|
|
29
27
|
"exports": {
|
|
30
28
|
"./package.json": "./package.json",
|
|
31
29
|
".": {
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"module-sync": "./dist/index.js",
|
|
32
32
|
"require": {
|
|
33
33
|
"types": "./dist/index.d.cts",
|
|
34
34
|
"default": "./dist/index.cjs"
|
|
35
35
|
},
|
|
36
36
|
"types": "./dist/index.d.ts",
|
|
37
|
-
"module": "./dist/index.js",
|
|
38
37
|
"default": "./dist/index.js"
|
|
39
38
|
}
|
|
40
39
|
},
|
|
@@ -66,10 +65,10 @@
|
|
|
66
65
|
"version": "sh ./scripts/version.sh"
|
|
67
66
|
},
|
|
68
67
|
"devDependencies": {
|
|
69
|
-
"
|
|
68
|
+
"@biomejs/biome": "2.3.4",
|
|
69
|
+
"esbuild": "0.27.0",
|
|
70
70
|
"oletus": "4.0.0",
|
|
71
|
-
"
|
|
72
|
-
"typescript": "5.1.3",
|
|
71
|
+
"typescript": "5.9.3",
|
|
73
72
|
"validate-commit-message": "3.2.0"
|
|
74
73
|
}
|
|
75
74
|
}
|