@gsknnft/bigint-buffer 1.3.2 → 1.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.
- package/README.md +123 -126
- package/build/Release/bigint_buffer.exp +0 -0
- package/build/Release/bigint_buffer.iobj +0 -0
- package/build/Release/bigint_buffer.ipdb +0 -0
- package/build/Release/bigint_buffer.lib +0 -0
- package/build/Release/bigint_buffer.node +0 -0
- package/build/Release/bigint_buffer.pdb +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.node.recipe +11 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.command.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.read.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/CL.write.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/Cl.items.tlog +2 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/bigint_buffer.lastbuildstate +2 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.command.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.read.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.secondary.1.tlog +5 -0
- package/build/Release/obj/bigint_buffer/bigint_buffer.tlog/link.write.1.tlog +0 -0
- package/build/Release/obj/bigint_buffer/src/bigint-buffer.obj +0 -0
- package/build/Release/obj/bigint_buffer/win_delay_load_hook.obj +0 -0
- package/build/bigint_buffer.vcxproj +148 -0
- package/build/bigint_buffer.vcxproj.filters +67 -0
- package/build/binding.sln +19 -0
- package/build/config.gypi +522 -0
- package/dist/index.cjs +1 -205
- package/dist/index.js +347 -202
- package/dist/index.umd.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/bigint-buffer.test.d.ts +1 -0
- package/dist/types/conversion/index.d.ts +1 -0
- package/dist/types/conversion/src/ts/index.d.ts +168 -0
- package/dist/types/conversion/test/bigintToBase64.test.d.ts +1 -0
- package/dist/types/conversion/test/bigintToBuf.test.d.ts +1 -0
- package/dist/types/conversion/test/bigintToHex.test.d.ts +1 -0
- package/dist/types/conversion/test/bigintToText.test.d.ts +1 -0
- package/dist/types/conversion/test/bufToBigint.test.d.ts +1 -0
- package/dist/types/conversion/test/hexToBigint.test.d.ts +1 -0
- package/dist/types/conversion/test/hexToBuf.test.d.ts +1 -0
- package/dist/types/conversion/test/parseHex.test.d.ts +1 -0
- package/dist/types/conversion/test/setup.test.d.ts +1 -0
- package/dist/types/conversion/test/textToBuf.test.d.ts +1 -0
- package/dist/types/conversion/vite.config.d.ts +2 -0
- package/dist/types/conversion/vitest.config.d.ts +2 -0
- package/dist/types/dist/dist/conversion/conversion/index.d.ts +1 -0
- package/dist/{index.d.ts → types/dist/dist/index.d.ts} +2 -0
- package/dist/types/index.bench.d.ts +1 -0
- package/dist/types/index.d.ts +80 -0
- package/dist/types/index.spec.d.ts +1 -0
- package/package.json +83 -49
- package/src/bigint-buffer.test.ts +11 -0
- package/src/conversion/.github/workflows/build-and-test.yml +116 -0
- package/src/conversion/CODE_OF_CONDUCT.md +134 -0
- 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/index.ts +1 -0
- package/src/conversion/package.json +163 -0
- package/src/conversion/src/docs/index.md +47 -0
- package/src/conversion/src/ts/index.ts +514 -0
- package/src/conversion/test/bigintToBase64.test.ts +37 -0
- package/src/conversion/test/bigintToBuf.test.ts +43 -0
- package/src/conversion/test/bigintToHex.test.ts +52 -0
- package/src/conversion/test/bigintToText.test.ts +30 -0
- package/src/conversion/test/bufToBigint.test.ts +20 -0
- package/src/conversion/test/hexToBigint.test.ts +22 -0
- package/src/conversion/test/hexToBuf.test.ts +39 -0
- package/src/conversion/test/parseHex.test.ts +35 -0
- package/src/conversion/test/setup.test.ts +9 -0
- package/src/conversion/test/textToBuf.test.ts +26 -0
- package/src/conversion/tsconfig.json +57 -0
- package/src/conversion/tsconfig.rollup.json +9 -0
- package/src/conversion/typedoc.json +5 -0
- package/src/conversion/types/bindings.d.t.s +4 -0
- package/src/conversion/vite.config.ts +10 -0
- package/src/conversion/vitest.config.ts +15 -0
- package/src/index.bench.ts +5 -6
- package/src/index.spec.ts +232 -358
- package/src/index.ts +33 -28
- package/.travis.yml +0 -51
- package/PR_TEMPLATE.md +0 -53
- package/dist/node.js +0 -94
- package/karma.conf.js +0 -62
- package/rollup.cjs.config.js +0 -8
- package/rollup.esm.config.js +0 -15
- package/tsconfig.json +0 -20
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as bc from '#pkg';
|
|
2
|
+
import {describe, expect, it} from 'vitest';
|
|
3
|
+
|
|
4
|
+
describe('bigintToText', () => {
|
|
5
|
+
const inputs = [
|
|
6
|
+
'Hello World', 'Apañarse por qué?',
|
|
7
|
+
`Lorem ipsum dolor sit amet, consectetur adipisci tempor incidunt ut labore et dolore magna aliqua veniam, quis nostrud exercitation ullamcorpor s commodo consequat. Duis autem vel eum irrure esse molestiae consequat, vel illum dolore eu fugi et iusto odio dignissim qui blandit praesent luptat exceptur sint occaecat cupiditat non provident, deserunt mollit anim id est laborum et dolor fuga distinct. Nam liber tempor cum soluta nobis elige quod maxim placeat facer possim omnis volupt
|
|
8
|
+
|
|
9
|
+
Lorem ipsum dolor si amet, consectetur adipiscing incidunt ut labore et dolore magna aliquam erat nostrud exercitation ullamcorper suscipit laboris nis duis autem vel eum irure dolor in reprehenderit i, dolore eu fugiat nulla pariatur. At vero eos et accusa praesant luptatum delenit aigue duos dolor et mole provident, simil tempor sunt in culpa qui officia de fuga. Et harumd dereud facilis est er expedit disti eligend optio congue nihil impedit doming id quod assumenda est, omnis dolor repellend. Temporibud
|
|
10
|
+
|
|
11
|
+
Lorem ipsum dolor si amet, consectetur adipiscing incidunt ut labore et dolore magna aliquam erat nostrud exercitation ullamcorper suscipit laboris nis duis autem vel eum irure dolor in reprehenderit i dolore eu fugiat nulla pariatur. At vero eos et accus praesant luptatum delenit aigue duos dolor et mol provident, simil tempor sunt in culpa qui officia de fuga. Et harumd dereud facilis est er expedit disti eligend oprio congue nihil impedit doming id quod assumenda est, omnis dolor repellend. Temporibud`
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
describe('bigintToText((textToBigint(str))) === str ', () => {
|
|
15
|
+
for (const input of inputs) {
|
|
16
|
+
describe(`bigintToText((textToBigint(${input})))`, () => {
|
|
17
|
+
it(`should return ${input}`, () => {
|
|
18
|
+
const ret = bc.bigintToText(bc.textToBigint(input));
|
|
19
|
+
expect(ret).to.equal(input);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('bigintToText(-6n)', () => {
|
|
26
|
+
it('should throw RangeError', () => {
|
|
27
|
+
expect(() => bc.bigintToText(BigInt('-6'))).to.throw(RangeError);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as bc from '#pkg';
|
|
2
|
+
import {describe, expect, it} from 'vitest';
|
|
3
|
+
|
|
4
|
+
describe('bufToBigint', () => {
|
|
5
|
+
const tests = [
|
|
6
|
+
{input: new Uint32Array(2), output: BigInt(0)},
|
|
7
|
+
{input: bc.hexToBuf('ffffffff'), output: BigInt('4294967295')}, {
|
|
8
|
+
input: new Uint16Array(bc.hexToBuf('ffffffff', true)),
|
|
9
|
+
output: BigInt('4294967295')
|
|
10
|
+
}
|
|
11
|
+
];
|
|
12
|
+
for (const test of tests) {
|
|
13
|
+
describe(`bufToBigint(${String(bc.bufToHex(test.input))})`, () => {
|
|
14
|
+
it(`should return ${String(test.output.toString())}`, () => {
|
|
15
|
+
const ret = bc.bufToBigint(test.input);
|
|
16
|
+
expect(ret.toString()).to.equal(test.output.toString());
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as bc from '#pkg';
|
|
2
|
+
import {describe, expect, it} from 'vitest';
|
|
3
|
+
|
|
4
|
+
describe('hexToBigint', () => {
|
|
5
|
+
const inputs = [
|
|
6
|
+
{bi: BigInt(1), hex: '1'}, {bi: BigInt(31), hex: '1F'}, {
|
|
7
|
+
bi: BigInt('12485413541784539569456874935679853424678352483761'),
|
|
8
|
+
hex: '88af94e6b1e99f8bf3b01edb619caaa656A5c75b1'
|
|
9
|
+
}
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
describe('hexToBigint', () => {
|
|
13
|
+
for (const input of inputs) {
|
|
14
|
+
describe(`hexToBigint(${input.hex})`, () => {
|
|
15
|
+
it(`should return ${input.bi}`, () => {
|
|
16
|
+
const ret = bc.hexToBigint(input.hex);
|
|
17
|
+
expect(ret).to.equal(input.bi);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as bc from '#pkg';
|
|
2
|
+
import {describe, expect, it} from 'vitest';
|
|
3
|
+
|
|
4
|
+
describe('hexToBuf', () => {
|
|
5
|
+
const tests = [
|
|
6
|
+
{buf: new Uint8Array([9, 255]), hex: '09ff'},
|
|
7
|
+
{buf: new Uint16Array([5, 256]), hex: '05000001'},
|
|
8
|
+
{buf: new ArrayBuffer(2), hex: '000'},
|
|
9
|
+
{buf: new Uint8Array([1, 1]), hex: '0x101'},
|
|
10
|
+
{buf: new Uint8Array([1, 1, 1]), hex: '10101'}
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
describe('hexToBuf and bufToHex', () => {
|
|
14
|
+
for (const test of tests) {
|
|
15
|
+
describe(`bufToHex([${(new Uint8Array(test.buf)).toString()}])`, () => {
|
|
16
|
+
const byteLength = test.buf.byteLength;
|
|
17
|
+
const expected = bc.parseHex(test.hex, false, byteLength);
|
|
18
|
+
it(`should return ${String(expected)}`, () => {
|
|
19
|
+
const ret = bc.bufToHex(test.buf);
|
|
20
|
+
expect(ret).to.equal(expected);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe(`bufToHex(hexToBuf(${test.hex}))`, () => {
|
|
24
|
+
const byteLength = test.buf.byteLength;
|
|
25
|
+
const expected = bc.parseHex(test.hex, false, byteLength);
|
|
26
|
+
it(`should return ${String(expected)}`, () => {
|
|
27
|
+
const buf = bc.hexToBuf(test.hex);
|
|
28
|
+
const ret = bc.bufToHex(buf);
|
|
29
|
+
expect(ret).to.equal(expected);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe('hexToBuf(\'12412fgt3\')', () => {
|
|
33
|
+
it('should throw RangeError', () => {
|
|
34
|
+
expect(() => bc.hexToBuf('12412fgt3')).to.throw(RangeError);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as bc from '#pkg';
|
|
2
|
+
import {describe, expect, it} from 'vitest';
|
|
3
|
+
|
|
4
|
+
describe('parseHex', () => {
|
|
5
|
+
const vectors = [
|
|
6
|
+
{input: '0x234FE678', output: '234FE678'},
|
|
7
|
+
{input: '234FE687', output: '234FE687'},
|
|
8
|
+
{input: '0x123546146f23A2', output: '123546146f23A2'}
|
|
9
|
+
];
|
|
10
|
+
for (const vector of vectors) {
|
|
11
|
+
it(`parseHex('${vector.input}') should return '${vector.output}'`, () => {
|
|
12
|
+
const ret = bc.parseHex(vector.input);
|
|
13
|
+
expect(ret).to.equal(vector.output);
|
|
14
|
+
});
|
|
15
|
+
it(`parseHex('${vector.input}', true) should return '0x${vector.output}'`,
|
|
16
|
+
() => {
|
|
17
|
+
const ret = bc.parseHex(vector.input, true);
|
|
18
|
+
expect(ret).to.equal('0x' + vector.output);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
it('parseHex(\'adge3\') should throw error', () => {
|
|
22
|
+
expect(() => {
|
|
23
|
+
bc.parseHex('adge3');
|
|
24
|
+
}).to.throw(RangeError);
|
|
25
|
+
});
|
|
26
|
+
it('parseHex(\'1287a3\', undefined, 4) should return \'001287a3\'', () => {
|
|
27
|
+
const ret = bc.parseHex('1287a3', undefined, 4);
|
|
28
|
+
expect(ret).to.equal('001287a3');
|
|
29
|
+
});
|
|
30
|
+
it('parseHex(\'1287542fe21\', true, 4) should throw error', () => {
|
|
31
|
+
expect(() => {
|
|
32
|
+
bc.parseHex('1287542fe21', true, 4);
|
|
33
|
+
}).to.throw(RangeError);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as bc from "#pkg";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
describe("textToBuf", () => {
|
|
5
|
+
const inputs = [
|
|
6
|
+
"Hello World",
|
|
7
|
+
"Apañarse por qué?",
|
|
8
|
+
`Lorem ipsum dolor sit amet, consectetur adipisci tempor incidunt ut labore et dolore magna aliqua veniam, quis nostrud exercitation ullamcorpor s commodo consequat. Duis autem vel eum irrure esse molestiae consequat, vel illum dolore eu fugi et iusto odio dignissim qui blandit praesent luptat exceptur sint occaecat cupiditat non provident, deserunt mollit anim id est laborum et dolor fuga distinct. Nam liber tempor cum soluta nobis elige quod maxim placeat facer possim omnis volupt
|
|
9
|
+
|
|
10
|
+
Lorem ipsum dolor si amet, consectetur adipiscing incidunt ut labore et dolore magna aliquam erat nostrud exercitation ullamcorper suscipit laboris nis duis autem vel eum irure dolor in reprehenderit i, dolore eu fugiat nulla pariatur. At vero eos et accusa praesant luptatum delenit aigue duos dolor et mole provident, simil tempor sunt in culpa qui officia de fuga. Et harumd dereud facilis est er expedit disti eligend optio congue nihil impedit doming id quod assumenda est, omnis dolor repellend. Temporibud
|
|
11
|
+
|
|
12
|
+
Lorem ipsum dolor si amet, consectetur adipiscing incidunt ut labore et dolore magna aliquam erat nostrud exercitation ullamcorper suscipit laboris nis duis autem vel eum irure dolor in reprehenderit i dolore eu fugiat nulla pariatur. At vero eos et accus praesant luptatum delenit aigue duos dolor et mol provident, simil tempor sunt in culpa qui officia de fuga. Et harumd dereud facilis est er expedit disti eligend oprio congue nihil impedit doming id quod assumenda est, omnis dolor repellend. Temporibud`,
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
let returnArrayBuffer = false;
|
|
16
|
+
|
|
17
|
+
for (const input of inputs) {
|
|
18
|
+
describe(`bufToText(textToBuf(${input.substring(0, 8)}...))`, () => {
|
|
19
|
+
it(`should return ${input.substring(0, 8)}...`, () => {
|
|
20
|
+
returnArrayBuffer = returnArrayBuffer ? false : true;
|
|
21
|
+
const ret = bc.bufToText(bc.textToBuf(input, returnArrayBuffer));
|
|
22
|
+
expect(ret).to.equal(input);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": ".",
|
|
5
|
+
"target": "ESNext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', 'ES2023', 'ES2023' or 'ESNEXT'. */
|
|
6
|
+
"module": "NodeNext",
|
|
7
|
+
// "lib": [ "es2020" ], /* Specify library files to be included in the compilation. */
|
|
8
|
+
"allowJs": true, /* Allow javascript files to be compiled. */
|
|
9
|
+
"checkJs": true, /* Report errors in .js files. */
|
|
10
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'react', 'react-jsx', 'react-jsxdev', 'preserve' or 'react-native'. */
|
|
11
|
+
"strict": true,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"removeComments": true,
|
|
14
|
+
"typeRoots": ["../types", "../../node_modules/@types", "node_modules/@types"], /* Additional Checks */
|
|
15
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
16
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
17
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
18
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
19
|
+
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
20
|
+
"tsBuildInfoFile": "build/main.tsbuildinfo",
|
|
21
|
+
"lib": [ "esnext", "dom" ],
|
|
22
|
+
"types": ["node"],
|
|
23
|
+
|
|
24
|
+
/* Module Resolution Options */
|
|
25
|
+
"moduleResolution": "NodeNext", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
26
|
+
"baseUrl": ".", /* Base directory to resolve non-absolute module names. */
|
|
27
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
28
|
+
// "rootDir": ".",
|
|
29
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
30
|
+
// "typeRoots": [ "node_modules/@types", "build/typings" ], /* List of folders to include type definitions from. */
|
|
31
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
32
|
+
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
33
|
+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
34
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
35
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
36
|
+
|
|
37
|
+
/* Experimental Options */
|
|
38
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
39
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
40
|
+
/* Advanced Options */
|
|
41
|
+
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
42
|
+
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
|
43
|
+
"resolveJsonModule": true,
|
|
44
|
+
"paths": {
|
|
45
|
+
"#pkg": ["./src/ts/index.ts"]
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"exclude": [
|
|
49
|
+
"node_modules",
|
|
50
|
+
"build",
|
|
51
|
+
"src/conversion/.dst"
|
|
52
|
+
],
|
|
53
|
+
"include": [
|
|
54
|
+
"src/**/*.ts",
|
|
55
|
+
"test/**/*.ts"
|
|
56
|
+
]
|
|
57
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
globals: true,
|
|
7
|
+
environment: "node",
|
|
8
|
+
include: ["src/conversion/test/**/*.test.ts"],
|
|
9
|
+
},
|
|
10
|
+
resolve: {
|
|
11
|
+
alias: {
|
|
12
|
+
"#pkg": path.resolve(__dirname, "src/ts/index.ts"),
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
package/src/index.bench.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
import
|
|
2
|
+
import benchmark from 'benchmark';
|
|
3
|
+
import BN from 'bn.js';
|
|
3
4
|
|
|
4
5
|
import {toBigIntBE, toBigIntLE, toBufferBE, toBufferLE} from './index';
|
|
5
6
|
|
|
6
|
-
const BN = require('bn.js');
|
|
7
|
-
|
|
8
7
|
|
|
9
8
|
// This file contains the benchmark test suite. It includes the benchmark and
|
|
10
9
|
// some lightweight boilerplate code for running benchmark.js. To
|
|
@@ -106,7 +105,7 @@ suite.add('BE bigint to hex string to buffer (small)', () => {
|
|
|
106
105
|
|
|
107
106
|
const bnSmallValue = new BN('12345678', 10);
|
|
108
107
|
suite.add('BN to buffer (small)', () => {
|
|
109
|
-
return bnSmallValue.
|
|
108
|
+
return bnSmallValue.toArrayLike(Buffer, 'be', 8);
|
|
110
109
|
});
|
|
111
110
|
|
|
112
111
|
suite.add('LE bigint-buffer to buffer (small)', () => {
|
|
@@ -133,7 +132,7 @@ const bnLargeValue = new BN(
|
|
|
133
132
|
'badc0ffee0ddf00dbadc0ffee0ddf00dbadc0ffee0ddf00dbadc0ffee0ddf00dbadc0ffee0ddf00dbadc0ffee0ddf00d',
|
|
134
133
|
16);
|
|
135
134
|
suite.add('BN to buffer (large)', () => {
|
|
136
|
-
return bnLargeValue.
|
|
135
|
+
return bnLargeValue.toArrayLike(Buffer, 'be', 24);
|
|
137
136
|
});
|
|
138
137
|
|
|
139
138
|
suite.add('LE bigint-buffer to buffer (large)', () => {
|
|
@@ -204,4 +203,4 @@ suite.on('cycle', (event: benchmark.Event) => {
|
|
|
204
203
|
});
|
|
205
204
|
|
|
206
205
|
// Runs the test suite
|
|
207
|
-
suite.run();
|
|
206
|
+
suite.run();
|