@gsknnft/bigint-buffer 1.2.0 → 1.3.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/.eslintrc +5 -0
- package/README.md +62 -11
- package/dist/node.js +10 -21
- package/helper/bigint.d.ts +2 -2
- package/okg.md +180 -0
- package/package.json +76 -11
- package/rollup.config.js +14 -11
- package/src/conversion/LICENSE +21 -0
- package/src/conversion/README.md +48 -0
- package/src/conversion/docs/README.md +34 -0
- package/src/conversion/docs/functions/base64ToBigint.md +27 -0
- package/src/conversion/docs/functions/bigintToBase64.md +43 -0
- package/src/conversion/docs/functions/bigintToBuf.md +35 -0
- package/src/conversion/docs/functions/bigintToHex.md +43 -0
- package/src/conversion/docs/functions/bigintToText.md +31 -0
- package/src/conversion/docs/functions/bufToBigint.md +25 -0
- package/src/conversion/docs/functions/bufToHex.md +37 -0
- package/src/conversion/docs/functions/bufToText.md +27 -0
- package/src/conversion/docs/functions/hexToBigint.md +29 -0
- package/src/conversion/docs/functions/hexToBuf.md +37 -0
- package/src/conversion/docs/functions/parseHex.md +45 -0
- package/src/conversion/docs/functions/textToBigint.md +27 -0
- package/src/conversion/docs/functions/textToBuf.md +33 -0
- package/src/conversion/docs/functions/toBigIntBE.md +27 -0
- package/src/conversion/docs/functions/toBigIntLE.md +27 -0
- package/src/conversion/docs/functions/toBufferBE.md +33 -0
- package/src/conversion/docs/functions/toBufferLE.md +33 -0
- package/src/conversion/docs/functions/validateBigIntBuffer.md +15 -0
- package/src/conversion/docs/type-aliases/TypedArray.md +11 -0
- package/src/conversion/docs/variables/isNative.md +11 -0
- package/src/conversion/example.cjs +9 -0
- package/src/conversion/example.esm.js +11 -0
- package/src/conversion/package.json +182 -0
- package/src/conversion/pnpm-lock.yaml +5571 -0
- package/src/conversion/tsconfig.rollup.json +9 -0
- package/src/conversion/typedoc.json +5 -0
- package/src/index.bench.ts +116 -119
- package/src/index.spec.ts +44 -78
- package/src/index.ts +40 -35
- package/src/types/bindings.d.t.s +4 -0
- package/tsconfig.json +5 -2
- package/tsconfig.lint.json +5 -0
- package/vitest.config.ts +10 -0
- package/dist/browser.js +0 -75
package/tsconfig.json
CHANGED
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
"extends": "./node_modules/gts/tsconfig-google.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"composite": true,
|
|
5
|
+
"moduleResolution": "nodenext",
|
|
6
|
+
"module": "NodeNext",
|
|
5
7
|
"rootDir": ".",
|
|
6
8
|
"outDir": "build",
|
|
7
9
|
"target" : "esnext",
|
|
8
10
|
"lib" : [ "esnext" ],
|
|
9
|
-
"sourceMap": true
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"rootDirs": ["src", "src/conversion"],
|
|
13
|
+
"tsBuildInfoFile": "build/main.tsbuildinfo"
|
|
10
14
|
},
|
|
11
15
|
"include": [
|
|
12
16
|
"src/*.ts",
|
|
13
|
-
"src/**/*.ts",
|
|
14
17
|
"test/*.ts",
|
|
15
18
|
"test/**/*.ts"
|
|
16
19
|
],
|
package/vitest.config.ts
ADDED
package/dist/browser.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.isNative = void 0;
|
|
5
|
-
exports.toBigIntLE = toBigIntLE;
|
|
6
|
-
exports.validateBigIntBuffer = validateBigIntBuffer;
|
|
7
|
-
exports.toBigIntBE = toBigIntBE;
|
|
8
|
-
exports.toBufferLE = toBufferLE;
|
|
9
|
-
exports.toBufferBE = toBufferBE;
|
|
10
|
-
exports.isNative = false;
|
|
11
|
-
/**
|
|
12
|
-
* Convert a little-endian buffer into a BigInt.
|
|
13
|
-
* @param buf The little-endian buffer to convert
|
|
14
|
-
* @returns A BigInt with the little-endian representation of buf.
|
|
15
|
-
*/
|
|
16
|
-
function toBigIntLE(buf) {
|
|
17
|
-
{
|
|
18
|
-
const reversed = Buffer.from(buf);
|
|
19
|
-
reversed.reverse();
|
|
20
|
-
const hex = reversed.toString('hex');
|
|
21
|
-
if (hex.length === 0) {
|
|
22
|
-
return BigInt(0);
|
|
23
|
-
}
|
|
24
|
-
return BigInt(`0x${hex}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function validateBigIntBuffer() {
|
|
28
|
-
try {
|
|
29
|
-
const test = toBigIntLE(Buffer.from([0x01, 0x00]));
|
|
30
|
-
return test === BigInt(1);
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Convert a big-endian buffer into a BigInt
|
|
38
|
-
* @param buf The big-endian buffer to convert.
|
|
39
|
-
* @returns A BigInt with the big-endian representation of buf.
|
|
40
|
-
*/
|
|
41
|
-
function toBigIntBE(buf) {
|
|
42
|
-
{
|
|
43
|
-
const hex = buf.toString('hex');
|
|
44
|
-
if (hex.length === 0) {
|
|
45
|
-
return BigInt(0);
|
|
46
|
-
}
|
|
47
|
-
return BigInt(`0x${hex}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Convert a BigInt to a little-endian buffer.
|
|
52
|
-
* @param num The BigInt to convert.
|
|
53
|
-
* @param width The number of bytes that the resulting buffer should be.
|
|
54
|
-
* @returns A little-endian buffer representation of num.
|
|
55
|
-
*/
|
|
56
|
-
function toBufferLE(num, width) {
|
|
57
|
-
{
|
|
58
|
-
const hex = num.toString(16);
|
|
59
|
-
const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
60
|
-
buffer.reverse();
|
|
61
|
-
return buffer;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Convert a BigInt to a big-endian buffer.
|
|
66
|
-
* @param num The BigInt to convert.
|
|
67
|
-
* @param width The number of bytes that the resulting buffer should be.
|
|
68
|
-
* @returns A big-endian buffer representation of num.
|
|
69
|
-
*/
|
|
70
|
-
function toBufferBE(num, width) {
|
|
71
|
-
{
|
|
72
|
-
const hex = num.toString(16);
|
|
73
|
-
return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
74
|
-
}
|
|
75
|
-
}
|