@gsknnft/bigint-buffer 1.3.1 → 1.4.1

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.
@@ -0,0 +1,80 @@
1
+ import * as conversionUtils from "./conversion/src/ts/index";
2
+ export { conversionUtils };
3
+ export declare let isNative: boolean;
4
+ /**
5
+ * Convert a little-endian buffer into a BigInt.
6
+ * @param buf The little-endian buffer to convert
7
+ * @returns A BigInt with the little-endian representation of buf.
8
+ */
9
+ export declare function toBigIntLE(buf: Buffer): bigint;
10
+ export declare function validateBigIntBuffer(): boolean;
11
+ /**
12
+ * Convert a big-endian buffer into a BigInt
13
+ * @param buf The big-endian buffer to convert.
14
+ * @returns A BigInt with the big-endian representation of buf.
15
+ */
16
+ export declare function toBigIntBE(buf: Buffer): bigint;
17
+ /**
18
+ * Convert a BigInt to a little-endian buffer.
19
+ * @param num The BigInt to convert.
20
+ * @param width The number of bytes that the resulting buffer should be.
21
+ * @returns A little-endian buffer representation of num.
22
+ */
23
+ export declare function toBufferLE(num: bigint, width: number): Buffer;
24
+ /**
25
+ * Convert a BigInt to a big-endian buffer.
26
+ * @param num The BigInt to convert.
27
+ * @param width The number of bytes that the resulting buffer should be.
28
+ * @returns A big-endian buffer representation of num.
29
+ */
30
+ export declare function toBufferBE(num: bigint, width: number): Buffer;
31
+ /**
32
+ * Convert a bigint to a Buffer with automatic sizing.
33
+ * Uses big-endian encoding and calculates the minimum buffer size needed.
34
+ * @param num The bigint to convert
35
+ * @returns A big-endian Buffer representation
36
+ */
37
+ export declare function bigintToBuf(num: bigint): Buffer;
38
+ /**
39
+ * Convert a Buffer to a bigint.
40
+ * Assumes big-endian encoding.
41
+ * @param buf The buffer to convert
42
+ * @returns A bigint representation of the buffer
43
+ */
44
+ export declare function bufToBigint(buf: Buffer): bigint;
45
+ /**
46
+ * Convert a bigint to a hexadecimal string.
47
+ * @param num The bigint to convert
48
+ * @returns A hexadecimal string (without '0x' prefix)
49
+ */
50
+ export declare function bigintToHex(num: bigint): string;
51
+ /**
52
+ * Convert a hexadecimal string to a bigint.
53
+ * @param hex The hexadecimal string (with or without '0x' prefix)
54
+ * @returns A bigint representation
55
+ */
56
+ export declare function hexToBigint(hex: string): bigint;
57
+ /**
58
+ * Convert a bigint to a decimal text string.
59
+ * @param num The bigint to convert
60
+ * @returns A decimal string representation
61
+ */
62
+ export declare function bigintToText(num: bigint): string;
63
+ /**
64
+ * Convert a decimal text string to a bigint.
65
+ * @param text The decimal string to convert
66
+ * @returns A bigint representation
67
+ */
68
+ export declare function textToBigint(text: string): bigint;
69
+ /**
70
+ * Convert a bigint to a base64 string.
71
+ * @param num The bigint to convert
72
+ * @returns A base64 string representation
73
+ */
74
+ export declare function bigintToBase64(num: bigint): string;
75
+ /**
76
+ * Convert a base64 string to a bigint.
77
+ * @param base64 The base64 string to convert
78
+ * @returns A bigint representation
79
+ */
80
+ export declare function base64ToBigint(base64: string): bigint;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,80 @@
1
+ import * as conversionUtils from "./conversion/src/ts/index";
2
+ export { conversionUtils };
3
+ export declare let isNative: boolean;
4
+ /**
5
+ * Convert a little-endian buffer into a BigInt.
6
+ * @param buf The little-endian buffer to convert
7
+ * @returns A BigInt with the little-endian representation of buf.
8
+ */
9
+ export declare function toBigIntLE(buf: Buffer): bigint;
10
+ export declare function validateBigIntBuffer(): boolean;
11
+ /**
12
+ * Convert a big-endian buffer into a BigInt
13
+ * @param buf The big-endian buffer to convert.
14
+ * @returns A BigInt with the big-endian representation of buf.
15
+ */
16
+ export declare function toBigIntBE(buf: Buffer): bigint;
17
+ /**
18
+ * Convert a BigInt to a little-endian buffer.
19
+ * @param num The BigInt to convert.
20
+ * @param width The number of bytes that the resulting buffer should be.
21
+ * @returns A little-endian buffer representation of num.
22
+ */
23
+ export declare function toBufferLE(num: bigint, width: number): Buffer;
24
+ /**
25
+ * Convert a BigInt to a big-endian buffer.
26
+ * @param num The BigInt to convert.
27
+ * @param width The number of bytes that the resulting buffer should be.
28
+ * @returns A big-endian buffer representation of num.
29
+ */
30
+ export declare function toBufferBE(num: bigint, width: number): Buffer;
31
+ /**
32
+ * Convert a bigint to a Buffer with automatic sizing.
33
+ * Uses big-endian encoding and calculates the minimum buffer size needed.
34
+ * @param num The bigint to convert
35
+ * @returns A big-endian Buffer representation
36
+ */
37
+ export declare function bigintToBuf(num: bigint): Buffer;
38
+ /**
39
+ * Convert a Buffer to a bigint.
40
+ * Assumes big-endian encoding.
41
+ * @param buf The buffer to convert
42
+ * @returns A bigint representation of the buffer
43
+ */
44
+ export declare function bufToBigint(buf: Buffer): bigint;
45
+ /**
46
+ * Convert a bigint to a hexadecimal string.
47
+ * @param num The bigint to convert
48
+ * @returns A hexadecimal string (without '0x' prefix)
49
+ */
50
+ export declare function bigintToHex(num: bigint): string;
51
+ /**
52
+ * Convert a hexadecimal string to a bigint.
53
+ * @param hex The hexadecimal string (with or without '0x' prefix)
54
+ * @returns A bigint representation
55
+ */
56
+ export declare function hexToBigint(hex: string): bigint;
57
+ /**
58
+ * Convert a bigint to a decimal text string.
59
+ * @param num The bigint to convert
60
+ * @returns A decimal string representation
61
+ */
62
+ export declare function bigintToText(num: bigint): string;
63
+ /**
64
+ * Convert a decimal text string to a bigint.
65
+ * @param text The decimal string to convert
66
+ * @returns A bigint representation
67
+ */
68
+ export declare function textToBigint(text: string): bigint;
69
+ /**
70
+ * Convert a bigint to a base64 string.
71
+ * @param num The bigint to convert
72
+ * @returns A base64 string representation
73
+ */
74
+ export declare function bigintToBase64(num: bigint): string;
75
+ /**
76
+ * Convert a base64 string to a bigint.
77
+ * @param base64 The base64 string to convert
78
+ * @returns A bigint representation
79
+ */
80
+ export declare function base64ToBigint(base64: string): bigint;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import globals from "globals";
2
+ import tseslint from "typescript-eslint";
3
+ import { defineConfig } from "eslint/config";
4
+
5
+ export default defineConfig([
6
+ {
7
+ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
8
+ languageOptions: { globals: { ...globals.browser, ...globals.node } },
9
+ ignores: ["*/build/**", "*/dist/**", "*/coverage/**", "*/test/**", "/src/index.spec.ts", "*/*.test.ts"],
10
+ },
11
+ tseslint.configs.recommended,
12
+ ]);
package/package.json CHANGED
@@ -1,100 +1,115 @@
1
- {
2
- "name": "@gsknnft/bigint-buffer",
3
- "version": "1.3.1",
4
- "description": "bigint to buffer conversion with native support",
5
- "main": "dist/index.js",
6
- "type": "module",
7
- "browser": {
8
- "./dist/node.js": "./dist/browser.js"
9
- },
10
- "types": "dist/index.d.ts",
11
- "scripts": {
12
- "test": "npm run test:node && npm run test:browser",
13
- "coverage": "istanbul cover ./test/index.js",
14
- "coveralls": "npm run coverage && coveralls <coverage/lcov.info",
15
- "lint": "gts check",
16
- "install": "npm run rebuild || echo \"Couldn't build bindings. Non-native version used.\"",
17
- "prepare": "npm run compile",
18
- "prepublishOnly": "rm -rf build/Release; rm build/Makefile; rm build/gyp-*; rm build/*.mk; rm build/*.Makefile; rm *.tgz",
19
- "test:browser": "karma start karma.conf.js",
20
- "test:node": "mocha -r ts-node/register src/**/*.spec.ts --timeout 40000",
21
- "benchmark": "node -r ts-node/register src/index.bench.ts",
22
- "typedoc": "typedoc --out docs $(pwd)/src $(pwd)/helper --target es6 --mode file --tsconfig ./tsconfig.json --excludePrivate --excludeProtected --excludeNotExported --exclude '**/*+(spec|bench).ts'",
23
- "rebuild": "node-gyp rebuild",
24
- "check": "gts check",
25
- "clean": "gts clean",
26
- "compile": "tsc -p . && rollup -c rollup.cjs.config.js && rollup -c rollup.esm.config.js && cpy build/src/*.d.ts dist",
27
- "compileOG": "mkdirp dist && tsc -p . && rollup -c > dist/node.js && cross-env BROWSER=true rollup -c > dist/browser.js && cpx \"build/src/*.d.ts\" dist",
28
- "fix": "gts fix",
29
- "pretest": "npm run compile",
30
- "posttest": "npm run check"
31
- },
32
- "repository": {
33
- "type": "git",
34
- "url": "https://github.com/gsknnft/bigint-buffer.git"
35
- },
36
- "bugs": {
37
- "url": "https://github.com/gsknnft/bigint-buffer/issues"
38
- },
39
- "homepage": "https://github.com/gsknnft/bigintbuffer",
40
- "keywords": [
41
- "bigint",
42
- "bignum",
43
- "tc39-bigint",
44
- "napi"
45
- ],
46
- "license": "Apache-2.0",
47
- "dependencies": {
48
- "bindings": "^1.5.0"
49
- },
50
- "devDependencies": {
51
- "@types/benchmark": "^2.1.5",
52
- "@types/bn.js": "^5.2.0",
53
- "@types/chai": "^5.2.3",
54
- "@types/mocha": "^10.0.10",
55
- "@types/node": "^24.9.1",
56
- "benchmark": "^2.1.4",
57
- "bn.js": "^5.2.2",
58
- "chai": "^4.1.2",
59
- "coveralls": "^3.1.1",
60
- "cpy-cli": "^6.0.0",
61
- "cross-env": "^6.0.3",
62
- "gts": "^0.8.0",
63
- "istanbul": "^0.4.1",
64
- "karma": "^3.0.0",
65
- "karma-chrome-launcher": "^2.2.0",
66
- "karma-env-preprocessor": "^0.1.1",
67
- "karma-mocha": "^1.3.0",
68
- "karma-mocha-reporter": "^2.2.5",
69
- "karma-webpack": "^3.0.0",
70
- "microtime": "^3.0.0",
71
- "mkdirp": "^0.5.1",
72
- "mocha": "^5.2.0",
73
- "pre-commit": "^1.2.2",
74
- "rollup": "^4.52.5",
75
- "rollup-plugin-replace": "^2.2.0",
76
- "ts-loader": "^9.5.4",
77
- "ts-node": "^10.9.2",
78
- "typedoc": "^0.28.14",
79
- "typescript": "5.9.3",
80
- "webpack": "5.102.1",
81
- "webpack-cli": "6.0.1"
82
- },
83
- "exports": {
84
- ".": {
85
- "import": "./dist/index.js",
86
- "require": "./dist/index.cjs",
87
- "types": "./dist/index.d.ts"
88
- }
89
- },
90
- "engines": {
91
- "node": ">=24.0.0"
92
- },
93
- "publishConfig": {
94
- "access": "public"
95
- },
96
- "contributors": [
97
- "Gordon Skinner <gsknnft@gmail.com> (https://github.com/gsknnft)",
98
- "Michael Wei <mwei@vmware.com> (https://github.com/no2chem)"
99
- ]
100
- }
1
+ {
2
+ "name": "@gsknnft/bigint-buffer",
3
+ "version": "1.4.1",
4
+ "description": "bigint to buffer conversion with native support and built-in conversion helpers",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "browser": "dist/browser.js",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./conversion": {
15
+ "types": "./dist/conversion/index.d.ts",
16
+ "import": "./dist/conversion/index.js",
17
+ "require": "./dist/conversion/index.cjs"
18
+ }
19
+ },
20
+ "workspaces": [],
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/gsknnft/bigint-buffer.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/gsknnft/bigint-buffer/issues"
27
+ },
28
+ "homepage": "https://github.com/gsknnft/bigintbuffer",
29
+ "keywords": [
30
+ "bigint",
31
+ "bignum",
32
+ "tc39-bigint",
33
+ "napi"
34
+ ],
35
+ "license": "Apache-2.0",
36
+ "optionalDependencies": {
37
+ "bindings": "^1.5.0"
38
+ },
39
+ "devDependencies": {
40
+ "jiti": "^2.6.1",
41
+ "@rollup/plugin-commonjs": "^29.0.0",
42
+ "@rollup/plugin-esm-shim": "0.1.8",
43
+ "@rollup/plugin-json": "^6.1.0",
44
+ "@rollup/plugin-node-resolve": "^16.0.3",
45
+ "@rollup/plugin-replace": "6.0.3",
46
+ "@rollup/plugin-typescript": "^12.1.4",
47
+ "@types/benchmark": "^2.1.5",
48
+ "@types/bn.js": "^5.2.0",
49
+ "@types/chai": "^5.2.3",
50
+ "@types/mocha": "^10.0.10",
51
+ "@types/node": "^24.10.1",
52
+ "@vitest/coverage-v8": "4.0.14",
53
+ "assertion-error": "^2.0.1",
54
+ "benchmark": "^2.1.4",
55
+ "bindings": "1.5.0",
56
+ "bn.js": "^5.2.2",
57
+ "cpy-cli": "^6.0.0",
58
+ "cross-env": "^10.1.0",
59
+ "eslint": "^9.39.1",
60
+ "globals": "^16.5.0",
61
+ "gts": "^6.0.2",
62
+ "karma": "^6.4.4",
63
+ "karma-chrome-launcher": "^3.2.0",
64
+ "karma-env-preprocessor": "^0.1.1",
65
+ "karma-mocha": "^2.0.1",
66
+ "karma-mocha-reporter": "^2.2.5",
67
+ "karma-webpack": "^5.0.1",
68
+ "microtime": "^3.0.0",
69
+ "mkdirp": "^3.0.1",
70
+ "rollup": "^4.53.3",
71
+ "ts-loader": "^9.5.4",
72
+ "ts-node": "^10.9.2",
73
+ "typedoc": "^0.28.14",
74
+ "typescript": "5.9.3",
75
+ "typescript-eslint": "^8.48.0",
76
+ "undici-types": "^7.16.0",
77
+ "vite": "7.2.4",
78
+ "vitest": "^4.0.14",
79
+ "webpack": "5.103.0",
80
+ "webpack-cli": "6.0.1"
81
+ },
82
+ "engines": {
83
+ "node": ">=24.0.0"
84
+ },
85
+ "publishConfig": {
86
+ "access": "public"
87
+ },
88
+ "contributors": [
89
+ "Gordon Skinner <gsknnft@gmail.com> (https://github.com/gsknnft)",
90
+ "Michael Wei <mwei@vmware.com> (https://github.com/no2chem)"
91
+ ],
92
+ "scripts": {
93
+ "test": "vitest run",
94
+ "test:watch": "vitest watch",
95
+ "coverage": "vitest cover ./test/index.js",
96
+ "lint": "gts check",
97
+ "install": "node-gyp rebuild",
98
+ "clean:js": "npm clean && rm -rf build/* dist/*",
99
+ "test:browser": "vite test --browser",
100
+ "test:node": "mocha build/src/**/*.spec.js --timeout 40000",
101
+ "declare": "tsc -p . --declaration --emitDeclarationOnly --outDir dist/types",
102
+ "benchmark": "node -r ts-node/register src/index.bench.ts",
103
+ "typedoc": "typedoc --out docs $(pwd)/src $(pwd)/helper --target es6 --mode file --tsconfig ./tsconfig.json --excludePrivate --excludeProtected --excludeNotExported --exclude '**/*+(spec|bench).ts'",
104
+ "rebuild:native": "node-gyp rebuild",
105
+ "build": "vite build && npm run declare && tsc -p . && cpy \"index.d.ts\" ../dist --cwd dist/types && cpy \"conversion/index.d.ts\" ../dist/conversion --cwd dist/types",
106
+ "compile": "vite build && npm run declare && tsc -p . && cpy \"index.d.ts\" ../dist/types --cwd dist/types && cpy \"conversion/index.d.ts\" ../dist/conversion --cwd dist/types",
107
+ "check": "eslint src/**/*.ts src/conversion/**/*.ts src/index.spec.ts src/conversion/test/**/*.ts",
108
+ "test:vitest": "vitest",
109
+ "test:all": "pnpm run test && pnpm run benchmark",
110
+ "clean": "gts clean",
111
+ "fix": "gts fix",
112
+ "pretest": "npm run compile",
113
+ "posttest": "npm run check"
114
+ }
115
+ }
@@ -0,0 +1,14 @@
1
+ packages:
2
+ - src/**
3
+
4
+ ignoredBuiltDependencies:
5
+ - inotify
6
+
7
+ onlyBuiltDependencies:
8
+ - core-js
9
+ - es5-ext
10
+ - esbuild
11
+ - fsevents
12
+ - microtime
13
+ - pre-commit
14
+ - spawn-sync
@@ -1,8 +1,13 @@
1
+ import commonjs from '@rollup/plugin-commonjs';
2
+
1
3
  export default {
2
- input: 'build/src/index.js',
4
+ input: 'build/index.js',
3
5
  output: {
4
6
  file: 'dist/index.cjs',
5
7
  format: 'cjs',
8
+ exports: 'named'
6
9
  },
7
- external: ['bindings'],
8
- };
10
+ context: 'globalThis',
11
+ external: ['bindings', '@juanelas/base64'],
12
+ plugins: [commonjs()]
13
+ };
@@ -0,0 +1,13 @@
1
+ import commonjs from '@rollup/plugin-commonjs';
2
+
3
+ export default {
4
+ input: 'build/conversion/index.js',
5
+ output: {
6
+ file: 'dist/conversion/index.cjs',
7
+ format: 'cjs',
8
+ exports: 'named'
9
+ },
10
+ context: 'globalThis',
11
+ external: ['bindings', '@juanelas/base64'],
12
+ plugins: [commonjs()]
13
+ };
@@ -0,0 +1,24 @@
1
+ import replace from '@rollup/plugin-replace';
2
+ import commonjs from '@rollup/plugin-commonjs';
3
+
4
+ export default {
5
+ input: 'build/conversion/index.js',
6
+ output: {
7
+ file: 'dist/conversion/index.js',
8
+ format: 'esm'
9
+ },
10
+ context: 'globalThis',
11
+ external: ['bindings', '@juanelas/base64'],
12
+ plugins: [
13
+ commonjs({
14
+ include: /node_modules/,
15
+ namedExports: {
16
+ '@juanelas/base64': ['encode', 'decode']
17
+ }
18
+ }),
19
+ replace({
20
+ preventAssignment: true,
21
+ 'process.browser': 'false'
22
+ })
23
+ ]
24
+ };
@@ -1,13 +1,24 @@
1
- import replace from 'rollup-plugin-replace';
1
+ import replace from '@rollup/plugin-replace';
2
+ import commonjs from '@rollup/plugin-commonjs';
2
3
 
3
4
  export default {
4
- input: 'build/src/index.js',
5
+ input: 'build/index.js',
5
6
  output: {
6
- format: 'cjs'
7
+ file: 'dist/index.js',
8
+ format: 'esm'
7
9
  },
10
+ context: 'globalThis',
11
+ external: ['bindings', '@juanelas/base64'],
8
12
  plugins: [
13
+ commonjs({
14
+ include: /node_modules/,
15
+ namedExports: {
16
+ '@juanelas/base64': ['encode', 'decode']
17
+ }
18
+ }),
9
19
  replace({
10
- 'process.browser': process.env.BROWSER === "true"
20
+ preventAssignment: true,
21
+ 'process.browser': 'false'
11
22
  })
12
23
  ]
13
- };
24
+ };