@bare-ts/lib 0.2.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.
- package/LICENSE +21 -201
- package/dist/codec/data.d.ts +1 -1
- package/dist/codec/data.js +10 -12
- package/dist/codec/float-array.d.ts +9 -9
- package/dist/codec/float-array.js +51 -54
- package/dist/codec/i16-array.d.ts +5 -5
- package/dist/codec/i16-array.js +34 -26
- package/dist/codec/i32-array.d.ts +5 -5
- package/dist/codec/i32-array.js +34 -26
- package/dist/codec/i64-array.d.ts +5 -5
- package/dist/codec/i64-array.js +34 -26
- package/dist/codec/i8-array.d.ts +1 -1
- package/dist/codec/i8-array.js +12 -14
- package/dist/codec/primitive.d.ts +3 -3
- package/dist/codec/primitive.js +231 -167
- package/dist/codec/string.d.ts +1 -1
- package/dist/codec/string.js +45 -31
- package/dist/codec/u16-array.d.ts +5 -5
- package/dist/codec/u16-array.js +34 -26
- package/dist/codec/u32-array.d.ts +5 -5
- package/dist/codec/u32-array.js +34 -26
- package/dist/codec/u64-array.d.ts +5 -5
- package/dist/codec/u64-array.js +34 -26
- package/dist/codec/u8-array.d.ts +7 -1
- package/dist/codec/u8-array.js +22 -17
- package/dist/codec/u8-clamped-array.d.ts +1 -1
- package/dist/codec/u8-clamped-array.js +13 -15
- package/dist/core/bare-error.d.ts +4 -1
- package/dist/core/bare-error.js +4 -8
- package/dist/core/byte-cursor.d.ts +22 -28
- package/dist/core/byte-cursor.js +34 -30
- package/dist/core/config.d.ts +6 -5
- package/dist/core/config.js +18 -23
- package/dist/env/dev.d.ts +1 -0
- package/dist/env/dev.development.d.ts +1 -0
- package/dist/env/dev.development.js +2 -0
- package/dist/env/dev.js +2 -0
- package/dist/env/dev.node.d.ts +1 -0
- package/dist/env/dev.node.js +2 -0
- package/dist/index.cjs +515 -314
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -2
- package/dist/index.js +17 -4
- package/dist/util/assert.d.ts +6 -4
- package/dist/util/assert.js +10 -18
- package/dist/util/constants.d.ts +10 -0
- package/dist/util/constants.js +11 -0
- package/dist/util/validator.d.ts +1 -1
- package/dist/util/validator.js +12 -24
- package/package.json +32 -28
- package/dist/codec/index.d.ts +0 -13
- package/dist/codec/index.js +0 -15
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.js +0 -5
- package/dist/util/assert.cjs +0 -55
- package/dist/util/util.d.ts +0 -1
- package/dist/util/util.js +0 -6
package/dist/codec/i64-array.js
CHANGED
|
@@ -1,43 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
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";
|
|
3
6
|
import { readFixedData } from "./data.js";
|
|
4
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
readI64,
|
|
9
|
+
readUintSafe32,
|
|
10
|
+
writeI64,
|
|
11
|
+
writeUintSafe32
|
|
12
|
+
} from "./primitive.js";
|
|
5
13
|
import { writeU8FixedArray } from "./u8-array.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
12
|
-
|
|
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
|
|
16
|
-
|
|
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
|
-
|
|
23
|
-
function writeI64Array(bc, x) {
|
|
24
|
-
|
|
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
|
|
43
|
+
function writeI64FixedArrayLe(bc, x) {
|
|
30
44
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
31
45
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
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
|
package/dist/codec/i8-array.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ByteCursor } from "../core/
|
|
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;
|
package/dist/codec/i8-array.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
|
|
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,
|
|
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
|
-
|
|
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/
|
|
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,7 +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;
|
|
36
|
-
export declare function readVoid(_dc: ByteCursor): undefined;
|
|
37
|
-
export declare function writeVoid(_dc: ByteCursor, _x: undefined): void;
|