bigint-base 0.1.3 → 0.2.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/lib/convert-base-to-base.js +4 -8
- package/lib/convert-base-to-base.js.map +1 -1
- package/lib/convert-base-to-decimal.js +12 -7
- package/lib/convert-base-to-decimal.js.map +1 -1
- package/lib/convert-decimal-to-base.js +13 -6
- package/lib/convert-decimal-to-base.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -19
- package/lib/index.js.map +1 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +5 -0
- package/lib/utils.js.map +1 -0
- package/package.json +35 -40
- package/src/convert-base-to-base.ts +24 -0
- package/src/convert-base-to-decimal.ts +41 -0
- package/src/convert-decimal-to-base.ts +42 -0
- package/src/index.ts +3 -0
- package/src/utils.ts +5 -0
- package/dist/index.min.mjs +0 -2
- package/dist/index.min.mjs.map +0 -1
- package/dist/index.mjs +0 -46
- package/dist/index.mjs.map +0 -1
- package/dist/index.umd.js +0 -58
- package/dist/index.umd.js.map +0 -1
- package/dist/index.umd.min.js +0 -2
- package/dist/index.umd.min.js.map +0 -1
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const convert_decimal_to_base_1 = require("./convert-decimal-to-base");
|
|
5
|
-
const convert_base_to_decimal_1 = require("./convert-base-to-decimal");
|
|
6
|
-
function convertBaseToBase(...args) {
|
|
1
|
+
import { convertDecimalToBase } from './convert-decimal-to-base.js';
|
|
2
|
+
import { convertBaseToDecimal } from './convert-base-to-decimal.js';
|
|
3
|
+
export function convertBaseToBase(...args) {
|
|
7
4
|
if (args.length === 2) {
|
|
8
5
|
const [srcAlphabet, destAlphabet] = args;
|
|
9
6
|
return (val) => convertBaseToBase(srcAlphabet, destAlphabet, val);
|
|
10
7
|
}
|
|
11
8
|
const [srcAlphabet, destAlphabet, val] = args;
|
|
12
|
-
return
|
|
9
|
+
return convertDecimalToBase(destAlphabet, convertBaseToDecimal(srcAlphabet, val));
|
|
13
10
|
}
|
|
14
|
-
exports.convertBaseToBase = convertBaseToBase;
|
|
15
11
|
//# sourceMappingURL=convert-base-to-base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-base-to-base.js","sourceRoot":"","sources":["../src/convert-base-to-base.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"convert-base-to-base.js","sourceRoot":"","sources":["../src/convert-base-to-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AAWnE,MAAM,UAAU,iBAAiB,CAAC,GAAG,IAEQ;IAE3C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,GAAG,IAAI,CAAA;QACxC,OAAO,CAAC,GAAW,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,EAAE,YAAY,EAAE,GAAG,CAAC,CAAA;IAC3E,CAAC;IAED,MAAM,CAAC,WAAW,EAAE,YAAY,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;IAC7C,OAAO,oBAAoB,CAAC,YAAY,EAAE,oBAAoB,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAA;AACnF,CAAC"}
|
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function convertBaseToDecimal(...args) {
|
|
1
|
+
import { assert } from '@blackglory/prelude';
|
|
2
|
+
import { validateAlphabet } from './utils.js';
|
|
3
|
+
export function convertBaseToDecimal(...args) {
|
|
5
4
|
if (args.length === 1) {
|
|
6
5
|
const [alphabet] = args;
|
|
7
|
-
|
|
6
|
+
validateAlphabet(alphabet);
|
|
7
|
+
return (val) => _convertBaseToDecimal(alphabet, val);
|
|
8
8
|
}
|
|
9
9
|
const [alphabet, val] = args;
|
|
10
|
+
validateAlphabet(alphabet);
|
|
11
|
+
return _convertBaseToDecimal(alphabet, val);
|
|
12
|
+
}
|
|
13
|
+
function _convertBaseToDecimal(alphabet, val) {
|
|
10
14
|
const base = BigInt(alphabet.length);
|
|
11
15
|
let accumulator = 0n;
|
|
12
16
|
for (let i = val.length; i--;) {
|
|
13
17
|
const char = val[i];
|
|
14
18
|
const indexOfAlphabet = alphabet.indexOf(char);
|
|
15
|
-
|
|
19
|
+
assert(indexOfAlphabet >= 0, `The characer ${JSON.stringify(char)} is not in the alphabet`);
|
|
20
|
+
const currentValue = BigInt(indexOfAlphabet)
|
|
21
|
+
* (base ** BigInt(val.length - i - 1));
|
|
16
22
|
accumulator += currentValue;
|
|
17
23
|
}
|
|
18
24
|
return accumulator;
|
|
19
25
|
}
|
|
20
|
-
exports.convertBaseToDecimal = convertBaseToDecimal;
|
|
21
26
|
//# sourceMappingURL=convert-base-to-decimal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-base-to-decimal.js","sourceRoot":"","sources":["../src/convert-base-to-decimal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"convert-base-to-decimal.js","sourceRoot":"","sources":["../src/convert-base-to-decimal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAI7C,MAAM,UAAU,oBAAoB,CAAC,GAAG,IAEpB;IAElB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;QACvB,gBAAgB,CAAC,QAAQ,CAAC,CAAA;QAE1B,OAAO,CAAC,GAAW,EAAE,EAAE,CAAC,qBAAqB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IAC9D,CAAC;IAED,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;IAC5B,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAE1B,OAAO,qBAAqB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;AAC7C,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAgB,EAAE,GAAW;IAC1D,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAEpC,IAAI,WAAW,GAAG,EAAE,CAAA;IACpB,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC;QAC9B,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QACnB,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9C,MAAM,CACJ,eAAe,IAAI,CAAC,EACpB,gBAAgB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,yBAAyB,CAC9D,CAAA;QAED,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,CAAC;cACvB,CAAC,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QAEzD,WAAW,IAAI,YAAY,CAAA;IAC7B,CAAC;IACD,OAAO,WAAW,CAAA;AACpB,CAAC"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function convertDecimalToBase(...args) {
|
|
1
|
+
import { assert } from '@blackglory/prelude';
|
|
2
|
+
import { validateAlphabet } from './utils.js';
|
|
3
|
+
export function convertDecimalToBase(...args) {
|
|
5
4
|
if (args.length === 1) {
|
|
6
5
|
const [alphabet] = args;
|
|
7
|
-
|
|
6
|
+
validateAlphabet(alphabet);
|
|
7
|
+
return (val) => _convertDecimalToBase(alphabet, val);
|
|
8
8
|
}
|
|
9
9
|
const [alphabet, val] = args;
|
|
10
|
+
validateAlphabet(alphabet);
|
|
11
|
+
return _convertDecimalToBase(alphabet, val);
|
|
12
|
+
}
|
|
13
|
+
function _convertDecimalToBase(alphabet, val) {
|
|
14
|
+
validateVal(val);
|
|
10
15
|
const base = BigInt(alphabet.length);
|
|
11
16
|
const result = [];
|
|
12
17
|
let temp = val;
|
|
@@ -18,5 +23,7 @@ function convertDecimalToBase(...args) {
|
|
|
18
23
|
.reverse()
|
|
19
24
|
.join('');
|
|
20
25
|
}
|
|
21
|
-
|
|
26
|
+
function validateVal(val) {
|
|
27
|
+
assert(val >= 0, 'The val must be greater than or equal to 0');
|
|
28
|
+
}
|
|
22
29
|
//# sourceMappingURL=convert-decimal-to-base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-decimal-to-base.js","sourceRoot":"","sources":["../src/convert-decimal-to-base.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"convert-decimal-to-base.js","sourceRoot":"","sources":["../src/convert-decimal-to-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAI7C,MAAM,UAAU,oBAAoB,CAAC,GAAG,IAEpB;IAElB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;QACvB,gBAAgB,CAAC,QAAQ,CAAC,CAAA;QAE1B,OAAO,CAAC,GAAW,EAAE,EAAE,CAAC,qBAAqB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IAC9D,CAAC;IAED,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;IAC5B,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IAE1B,OAAO,qBAAqB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;AAC7C,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAgB,EAAE,GAAW;IAC1D,WAAW,CAAC,GAAG,CAAC,CAAA;IAEhB,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACpC,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,IAAI,IAAI,GAAG,GAAG,CAAA;IACd,GAAG,CAAC;QACF,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;QACrC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAA;IAClC,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,EAAC;IAErC,OAAO,MAAM;SACV,OAAO,EAAE;SACT,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAED,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,4CAA4C,CAAC,CAAA;AAChE,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './convert-base-to-decimal';
|
|
2
|
-
export * from './convert-decimal-to-base';
|
|
3
|
-
export * from './convert-base-to-base';
|
|
1
|
+
export * from './convert-base-to-decimal.js';
|
|
2
|
+
export * from './convert-decimal-to-base.js';
|
|
3
|
+
export * from './convert-base-to-base.js';
|
package/lib/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./convert-base-to-decimal"), exports);
|
|
18
|
-
__exportStar(require("./convert-decimal-to-base"), exports);
|
|
19
|
-
__exportStar(require("./convert-base-to-base"), exports);
|
|
1
|
+
export * from './convert-base-to-decimal.js';
|
|
2
|
+
export * from './convert-decimal-to-base.js';
|
|
3
|
+
export * from './convert-base-to-base.js';
|
|
20
4
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA"}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateAlphabet(alphabet: string): void;
|
package/lib/utils.js
ADDED
package/lib/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,MAAM,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,EAAE,gDAAgD,CAAC,CAAA;AAChF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bigint-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Yet another base conversion library, but using BigInt.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bigint",
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
],
|
|
9
9
|
"files": [
|
|
10
10
|
"lib",
|
|
11
|
-
"
|
|
11
|
+
"src"
|
|
12
12
|
],
|
|
13
|
+
"type": "module",
|
|
13
14
|
"main": "lib/index.js",
|
|
14
15
|
"types": "lib/index.d.ts",
|
|
15
16
|
"repository": "git@github.com:BlackGlory/bigint-base.git",
|
|
@@ -17,57 +18,51 @@
|
|
|
17
18
|
"license": "MIT",
|
|
18
19
|
"sideEffects": false,
|
|
19
20
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
21
|
+
"node": ">=22"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
24
|
+
"prepare": "ts-patch install -s",
|
|
23
25
|
"lint": "eslint --ext .js,.jsx,.ts,.tsx --quiet src __tests__",
|
|
24
|
-
"test": "
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"clean:build": "rimraf lib",
|
|
30
|
-
"clean:bundle": "rimraf dist",
|
|
31
|
-
"build": "run-s build:*",
|
|
32
|
-
"build:compile": "tsc --project tsconfig.build.json",
|
|
33
|
-
"build:patch": "tscpaths -p tsconfig.build.json -s ./src -o ./lib",
|
|
34
|
-
"bundle": "rollup --config rollup.config.js",
|
|
35
|
-
"bench": "./benches/benchmark.sh",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"prepublishOnly": "run-s prepare clean build",
|
|
28
|
+
"clean": "rimraf lib",
|
|
29
|
+
"build": "tsc --project tsconfig.build.json",
|
|
30
|
+
"bench": "tsx benches/index.ts",
|
|
36
31
|
"release": "standard-version"
|
|
37
32
|
},
|
|
38
33
|
"husky": {
|
|
39
34
|
"hooks": {
|
|
40
|
-
"pre-commit": "run-s lint build test",
|
|
35
|
+
"pre-commit": "run-s prepare lint build test",
|
|
41
36
|
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
42
37
|
}
|
|
43
38
|
},
|
|
44
39
|
"devDependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"@commitlint/
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
55
|
-
"@typescript-eslint/parser": "^5.36.2",
|
|
56
|
-
"eslint": "^8.23.0",
|
|
57
|
-
"extra-benchmark": "^0.1.0",
|
|
58
|
-
"extra-generator": "^0.2.17",
|
|
40
|
+
"@commitlint/cli": "^20.4.1",
|
|
41
|
+
"@commitlint/config-conventional": "^20.4.1",
|
|
42
|
+
"@eslint/js": "^10.0.1",
|
|
43
|
+
"@types/node": "22",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^8.55.0",
|
|
45
|
+
"@typescript-eslint/parser": "^8.55.0",
|
|
46
|
+
"eslint": "^10.0.0",
|
|
47
|
+
"extra-benchmark": "^0.2.5",
|
|
48
|
+
"extra-generator": "^0.5.9",
|
|
59
49
|
"husky": "^4.3.8",
|
|
60
|
-
"jest": "^26.6.3",
|
|
61
50
|
"npm-run-all": "^4.1.5",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"rollup-plugin-analyzer": "^4.0.0",
|
|
65
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
51
|
+
"return-style": "^3.0.1",
|
|
52
|
+
"rimraf": "^6.1.2",
|
|
66
53
|
"standard-version": "^9.5.0",
|
|
67
|
-
"ts-
|
|
68
|
-
"
|
|
69
|
-
"tslib": "^2.
|
|
70
|
-
"
|
|
54
|
+
"ts-patch": "^3.3.0",
|
|
55
|
+
"tsconfig-paths": "^4.2.0",
|
|
56
|
+
"tslib": "^2.8.1",
|
|
57
|
+
"tsx": "^4.21.0",
|
|
58
|
+
"typescript": "^5.9.3",
|
|
59
|
+
"typescript-eslint": "^8.55.0",
|
|
60
|
+
"typescript-transform-paths": "^3.5.6",
|
|
61
|
+
"vite": "^7.3.1",
|
|
62
|
+
"vite-tsconfig-paths": "^6.1.1",
|
|
63
|
+
"vitest": "^4.0.18"
|
|
71
64
|
},
|
|
72
|
-
"dependencies": {
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"@blackglory/prelude": "^0.4.0"
|
|
67
|
+
}
|
|
73
68
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { convertDecimalToBase } from './convert-decimal-to-base.js'
|
|
2
|
+
import { convertBaseToDecimal } from './convert-base-to-decimal.js'
|
|
3
|
+
|
|
4
|
+
export function convertBaseToBase(
|
|
5
|
+
srcAlphabet: string
|
|
6
|
+
, destAlphabet: string
|
|
7
|
+
, val: string
|
|
8
|
+
): string
|
|
9
|
+
export function convertBaseToBase(
|
|
10
|
+
srcAlphabet: string
|
|
11
|
+
, destAlphabet: string
|
|
12
|
+
): (val: string) => string
|
|
13
|
+
export function convertBaseToBase(...args:
|
|
14
|
+
| [srcAlphabet: string, destAlphabet: string, val: string]
|
|
15
|
+
| [srcAlphabet: string, destAlphabet: string]
|
|
16
|
+
) {
|
|
17
|
+
if (args.length === 2) {
|
|
18
|
+
const [srcAlphabet, destAlphabet] = args
|
|
19
|
+
return (val: string) => convertBaseToBase(srcAlphabet, destAlphabet, val)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const [srcAlphabet, destAlphabet, val] = args
|
|
23
|
+
return convertDecimalToBase(destAlphabet, convertBaseToDecimal(srcAlphabet, val))
|
|
24
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { assert } from '@blackglory/prelude'
|
|
2
|
+
import { validateAlphabet } from './utils.js'
|
|
3
|
+
|
|
4
|
+
export function convertBaseToDecimal(alphabet: string, val: string): bigint
|
|
5
|
+
export function convertBaseToDecimal(alphabet: string): (val: string) => bigint
|
|
6
|
+
export function convertBaseToDecimal(...args:
|
|
7
|
+
| [alphabet: string, val: string]
|
|
8
|
+
| [alphabet: string]
|
|
9
|
+
) {
|
|
10
|
+
if (args.length === 1) {
|
|
11
|
+
const [alphabet] = args
|
|
12
|
+
validateAlphabet(alphabet)
|
|
13
|
+
|
|
14
|
+
return (val: string) => _convertBaseToDecimal(alphabet, val)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const [alphabet, val] = args
|
|
18
|
+
validateAlphabet(alphabet)
|
|
19
|
+
|
|
20
|
+
return _convertBaseToDecimal(alphabet, val)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function _convertBaseToDecimal(alphabet: string, val: string): bigint {
|
|
24
|
+
const base = BigInt(alphabet.length)
|
|
25
|
+
|
|
26
|
+
let accumulator = 0n
|
|
27
|
+
for (let i = val.length; i--;) {
|
|
28
|
+
const char = val[i]
|
|
29
|
+
const indexOfAlphabet = alphabet.indexOf(char)
|
|
30
|
+
assert(
|
|
31
|
+
indexOfAlphabet >= 0
|
|
32
|
+
, `The characer ${JSON.stringify(char)} is not in the alphabet`
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const currentValue = BigInt(indexOfAlphabet)
|
|
36
|
+
* (base ** BigInt(val.length - i - 1))
|
|
37
|
+
|
|
38
|
+
accumulator += currentValue
|
|
39
|
+
}
|
|
40
|
+
return accumulator
|
|
41
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { assert } from '@blackglory/prelude'
|
|
2
|
+
import { validateAlphabet } from './utils.js'
|
|
3
|
+
|
|
4
|
+
export function convertDecimalToBase(alphabet: string, val: bigint): string
|
|
5
|
+
export function convertDecimalToBase(alphabet: string): (val: bigint) => string
|
|
6
|
+
export function convertDecimalToBase(...args:
|
|
7
|
+
| [alphabet: string, val: bigint]
|
|
8
|
+
| [alphabet: string]
|
|
9
|
+
) {
|
|
10
|
+
if (args.length === 1) {
|
|
11
|
+
const [alphabet] = args
|
|
12
|
+
validateAlphabet(alphabet)
|
|
13
|
+
|
|
14
|
+
return (val: bigint) => _convertDecimalToBase(alphabet, val)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const [alphabet, val] = args
|
|
18
|
+
validateAlphabet(alphabet)
|
|
19
|
+
|
|
20
|
+
return _convertDecimalToBase(alphabet, val)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function _convertDecimalToBase(alphabet: string, val: bigint): string {
|
|
24
|
+
validateVal(val)
|
|
25
|
+
|
|
26
|
+
const base = BigInt(alphabet.length)
|
|
27
|
+
const result: string[] = []
|
|
28
|
+
|
|
29
|
+
let temp = val
|
|
30
|
+
do {
|
|
31
|
+
const remainder = Number(temp % base)
|
|
32
|
+
result.push(alphabet[remainder])
|
|
33
|
+
} while ((temp = temp / base) !== 0n)
|
|
34
|
+
|
|
35
|
+
return result
|
|
36
|
+
.reverse()
|
|
37
|
+
.join('')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function validateVal(val: bigint): void {
|
|
41
|
+
assert(val >= 0, 'The val must be greater than or equal to 0')
|
|
42
|
+
}
|
package/src/index.ts
ADDED
package/src/utils.ts
ADDED
package/dist/index.min.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function n(...t){if(1===t.length){const[e]=t;return t=>n(e,t)}const[e,r]=t,o=BigInt(e.length);let i=0n;for(let n=r.length;n--;){const t=r[n],c=e.indexOf(t);i+=BigInt(c)*o**BigInt(r.length-n-1)}return i}function t(...n){if(1===n.length){const[e]=n;return n=>t(e,n)}const[e,r]=n,o=BigInt(e.length),i=[];let c=r;do{const n=Number(c%o);i.push(e[n])}while(0n!==(c/=o));return i.reverse().join("")}function e(...r){if(2===r.length){const[n,t]=r;return r=>e(n,t,r)}const[o,i,c]=r;return t(i,n(o,c))}export{e as convertBaseToBase,n as convertBaseToDecimal,t as convertDecimalToBase};
|
|
2
|
-
//# sourceMappingURL=index.min.mjs.map
|
package/dist/index.min.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.min.mjs","sources":["../src/convert-base-to-decimal.ts","../src/convert-decimal-to-base.ts","../src/convert-base-to-base.ts"],"sourcesContent":["export function convertBaseToDecimal(alphabet: string, val: string): bigint\nexport function convertBaseToDecimal(alphabet: string): (val: string) => bigint\nexport function convertBaseToDecimal(...args:\n| [alphabet: string, val: string]\n| [alphabet: string]\n) {\n if (args.length === 1) {\n const [alphabet] = args\n return (val: string) => convertBaseToDecimal(alphabet, val)\n }\n\n const [alphabet, val] = args\n const base = BigInt(alphabet.length)\n\n let accumulator = 0n\n for (let i = val.length; i--;) {\n const char = val[i]\n const indexOfAlphabet = alphabet.indexOf(char)\n const currentValue = BigInt(indexOfAlphabet) * (base ** BigInt(val.length - i - 1))\n accumulator += currentValue\n }\n return accumulator\n}\n","export function convertDecimalToBase(alphabet: string, val: bigint): string\nexport function convertDecimalToBase(alphabet: string): (val: bigint) => string\nexport function convertDecimalToBase(...args:\n| [alphabet: string, val: bigint]\n| [alphabet: string]\n) {\n if (args.length === 1) {\n const [alphabet] = args\n return (val: bigint) => convertDecimalToBase(alphabet, val)\n }\n\n const [alphabet, val] = args\n const base = BigInt(alphabet.length)\n const result: string[] = []\n\n let temp = val\n do {\n const remainder = Number(temp % base)\n result.push(alphabet[remainder])\n } while ((temp = temp / base) !== 0n)\n\n return result\n .reverse()\n .join('')\n}\n","import { convertDecimalToBase } from './convert-decimal-to-base'\nimport { convertBaseToDecimal } from './convert-base-to-decimal'\n\nexport function convertBaseToBase(\n srcAlphabet: string\n, destAlphabet: string\n, val: string\n): string\nexport function convertBaseToBase(\n srcAlphabet: string\n, destAlphabet: string\n): (val: string) => string\nexport function convertBaseToBase(...args:\n| [srcAlphabet: string, destAlphabet: string, val: string]\n| [srcAlphabet: string, destAlphabet: string]\n) {\n if (args.length === 2) {\n const [srcAlphabet, destAlphabet] = args\n return (val: string) => convertBaseToBase(srcAlphabet, destAlphabet, val)\n }\n\n const [srcAlphabet, destAlphabet, val] = args\n return convertDecimalToBase(destAlphabet, convertBaseToDecimal(srcAlphabet, val))\n}\n"],"names":["convertBaseToDecimal","args","length","alphabet","val","base","BigInt","accumulator","i","char","indexOfAlphabet","indexOf","convertDecimalToBase","result","temp","remainder","Number","push","reverse","join","convertBaseToBase","srcAlphabet","destAlphabet"],"mappings":"AAEgB,SAAAA,KAAwBC,GAItC,GAAoB,IAAhBA,EAAKC,OAAc,CACrB,MAAOC,GAAYF,EACnB,OAAQG,GAAgBJ,EAAqBG,EAAUC,GAGzD,MAAOD,EAAUC,GAAOH,EAClBI,EAAOC,OAAOH,EAASD,QAE7B,IAAIK,EAAc,GAClB,IAAK,IAAIC,EAAIJ,EAAIF,OAAQM,KAAM,CAC7B,MAAMC,EAAOL,EAAII,GACXE,EAAkBP,EAASQ,QAAQF,GAEzCF,GADqBD,OAAOI,GAAoBL,GAAQC,OAAOF,EAAIF,OAASM,EAAI,GAGlF,OAAOD,ECnBO,SAAAK,KAAwBX,GAItC,GAAoB,IAAhBA,EAAKC,OAAc,CACrB,MAAOC,GAAYF,EACnB,OAAQG,GAAgBQ,EAAqBT,EAAUC,GAGzD,MAAOD,EAAUC,GAAOH,EAClBI,EAAOC,OAAOH,EAASD,QACvBW,EAAmB,GAEzB,IAAIC,EAAOV,EACX,EAAG,CACD,MAAMW,EAAYC,OAAOF,EAAOT,GAChCQ,EAAOI,KAAKd,EAASY,UACW,MAAxBD,GAAcT,IAExB,OAAOQ,EACJK,UACAC,KAAK,ICXM,SAAAC,KAAqBnB,GAInC,GAAoB,IAAhBA,EAAKC,OAAc,CACrB,MAAOmB,EAAaC,GAAgBrB,EACpC,OAAQG,GAAgBgB,EAAkBC,EAAaC,EAAclB,GAGvE,MAAOiB,EAAaC,EAAclB,GAAOH,EACzC,OAAOW,EAAqBU,EAActB,EAAqBqB,EAAajB"}
|
package/dist/index.mjs
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
function convertBaseToDecimal(...args) {
|
|
2
|
-
if (args.length === 1) {
|
|
3
|
-
const [alphabet] = args;
|
|
4
|
-
return (val) => convertBaseToDecimal(alphabet, val);
|
|
5
|
-
}
|
|
6
|
-
const [alphabet, val] = args;
|
|
7
|
-
const base = BigInt(alphabet.length);
|
|
8
|
-
let accumulator = 0n;
|
|
9
|
-
for (let i = val.length; i--;) {
|
|
10
|
-
const char = val[i];
|
|
11
|
-
const indexOfAlphabet = alphabet.indexOf(char);
|
|
12
|
-
const currentValue = BigInt(indexOfAlphabet) * (base ** BigInt(val.length - i - 1));
|
|
13
|
-
accumulator += currentValue;
|
|
14
|
-
}
|
|
15
|
-
return accumulator;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function convertDecimalToBase(...args) {
|
|
19
|
-
if (args.length === 1) {
|
|
20
|
-
const [alphabet] = args;
|
|
21
|
-
return (val) => convertDecimalToBase(alphabet, val);
|
|
22
|
-
}
|
|
23
|
-
const [alphabet, val] = args;
|
|
24
|
-
const base = BigInt(alphabet.length);
|
|
25
|
-
const result = [];
|
|
26
|
-
let temp = val;
|
|
27
|
-
do {
|
|
28
|
-
const remainder = Number(temp % base);
|
|
29
|
-
result.push(alphabet[remainder]);
|
|
30
|
-
} while ((temp = temp / base) !== 0n);
|
|
31
|
-
return result
|
|
32
|
-
.reverse()
|
|
33
|
-
.join('');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function convertBaseToBase(...args) {
|
|
37
|
-
if (args.length === 2) {
|
|
38
|
-
const [srcAlphabet, destAlphabet] = args;
|
|
39
|
-
return (val) => convertBaseToBase(srcAlphabet, destAlphabet, val);
|
|
40
|
-
}
|
|
41
|
-
const [srcAlphabet, destAlphabet, val] = args;
|
|
42
|
-
return convertDecimalToBase(destAlphabet, convertBaseToDecimal(srcAlphabet, val));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { convertBaseToBase, convertBaseToDecimal, convertDecimalToBase };
|
|
46
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/convert-base-to-decimal.ts","../src/convert-decimal-to-base.ts","../src/convert-base-to-base.ts"],"sourcesContent":["export function convertBaseToDecimal(alphabet: string, val: string): bigint\nexport function convertBaseToDecimal(alphabet: string): (val: string) => bigint\nexport function convertBaseToDecimal(...args:\n| [alphabet: string, val: string]\n| [alphabet: string]\n) {\n if (args.length === 1) {\n const [alphabet] = args\n return (val: string) => convertBaseToDecimal(alphabet, val)\n }\n\n const [alphabet, val] = args\n const base = BigInt(alphabet.length)\n\n let accumulator = 0n\n for (let i = val.length; i--;) {\n const char = val[i]\n const indexOfAlphabet = alphabet.indexOf(char)\n const currentValue = BigInt(indexOfAlphabet) * (base ** BigInt(val.length - i - 1))\n accumulator += currentValue\n }\n return accumulator\n}\n","export function convertDecimalToBase(alphabet: string, val: bigint): string\nexport function convertDecimalToBase(alphabet: string): (val: bigint) => string\nexport function convertDecimalToBase(...args:\n| [alphabet: string, val: bigint]\n| [alphabet: string]\n) {\n if (args.length === 1) {\n const [alphabet] = args\n return (val: bigint) => convertDecimalToBase(alphabet, val)\n }\n\n const [alphabet, val] = args\n const base = BigInt(alphabet.length)\n const result: string[] = []\n\n let temp = val\n do {\n const remainder = Number(temp % base)\n result.push(alphabet[remainder])\n } while ((temp = temp / base) !== 0n)\n\n return result\n .reverse()\n .join('')\n}\n","import { convertDecimalToBase } from './convert-decimal-to-base'\nimport { convertBaseToDecimal } from './convert-base-to-decimal'\n\nexport function convertBaseToBase(\n srcAlphabet: string\n, destAlphabet: string\n, val: string\n): string\nexport function convertBaseToBase(\n srcAlphabet: string\n, destAlphabet: string\n): (val: string) => string\nexport function convertBaseToBase(...args:\n| [srcAlphabet: string, destAlphabet: string, val: string]\n| [srcAlphabet: string, destAlphabet: string]\n) {\n if (args.length === 2) {\n const [srcAlphabet, destAlphabet] = args\n return (val: string) => convertBaseToBase(srcAlphabet, destAlphabet, val)\n }\n\n const [srcAlphabet, destAlphabet, val] = args\n return convertDecimalToBase(destAlphabet, convertBaseToDecimal(srcAlphabet, val))\n}\n"],"names":[],"mappings":"AAEgB,SAAA,oBAAoB,CAAC,GAAG,IAEpB,EAAA;AAElB,IAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AACrB,QAAA,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;QACvB,OAAO,CAAC,GAAW,KAAK,oBAAoB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;AAC5D,KAAA;AAED,IAAA,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;IAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAEpC,IAAI,WAAW,GAAG,EAAE,CAAA;IACpB,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG;AAC7B,QAAA,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QACnB,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9C,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACnF,WAAW,IAAI,YAAY,CAAA;AAC5B,KAAA;AACD,IAAA,OAAO,WAAW,CAAA;AACpB;;ACpBgB,SAAA,oBAAoB,CAAC,GAAG,IAEpB,EAAA;AAElB,IAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AACrB,QAAA,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;QACvB,OAAO,CAAC,GAAW,KAAK,oBAAoB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;AAC5D,KAAA;AAED,IAAA,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;IAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACpC,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,IAAI,IAAI,GAAG,GAAG,CAAA;IACd,GAAG;QACD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;QACrC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAA;KACjC,QAAQ,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,MAAM,EAAE,EAAC;AAErC,IAAA,OAAO,MAAM;AACV,SAAA,OAAO,EAAE;SACT,IAAI,CAAC,EAAE,CAAC,CAAA;AACb;;ACZgB,SAAA,iBAAiB,CAAC,GAAG,IAEQ,EAAA;AAE3C,IAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AACrB,QAAA,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,GAAG,IAAI,CAAA;AACxC,QAAA,OAAO,CAAC,GAAW,KAAK,iBAAiB,CAAC,WAAW,EAAE,YAAY,EAAE,GAAG,CAAC,CAAA;AAC1E,KAAA;IAED,MAAM,CAAC,WAAW,EAAE,YAAY,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;IAC7C,OAAO,oBAAoB,CAAC,YAAY,EAAE,oBAAoB,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAA;AACnF;;;;"}
|
package/dist/index.umd.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BigIntBase = {}));
|
|
5
|
-
})(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function convertBaseToDecimal(...args) {
|
|
8
|
-
if (args.length === 1) {
|
|
9
|
-
const [alphabet] = args;
|
|
10
|
-
return (val) => convertBaseToDecimal(alphabet, val);
|
|
11
|
-
}
|
|
12
|
-
const [alphabet, val] = args;
|
|
13
|
-
const base = BigInt(alphabet.length);
|
|
14
|
-
let accumulator = 0n;
|
|
15
|
-
for (let i = val.length; i--;) {
|
|
16
|
-
const char = val[i];
|
|
17
|
-
const indexOfAlphabet = alphabet.indexOf(char);
|
|
18
|
-
const currentValue = BigInt(indexOfAlphabet) * (base ** BigInt(val.length - i - 1));
|
|
19
|
-
accumulator += currentValue;
|
|
20
|
-
}
|
|
21
|
-
return accumulator;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function convertDecimalToBase(...args) {
|
|
25
|
-
if (args.length === 1) {
|
|
26
|
-
const [alphabet] = args;
|
|
27
|
-
return (val) => convertDecimalToBase(alphabet, val);
|
|
28
|
-
}
|
|
29
|
-
const [alphabet, val] = args;
|
|
30
|
-
const base = BigInt(alphabet.length);
|
|
31
|
-
const result = [];
|
|
32
|
-
let temp = val;
|
|
33
|
-
do {
|
|
34
|
-
const remainder = Number(temp % base);
|
|
35
|
-
result.push(alphabet[remainder]);
|
|
36
|
-
} while ((temp = temp / base) !== 0n);
|
|
37
|
-
return result
|
|
38
|
-
.reverse()
|
|
39
|
-
.join('');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function convertBaseToBase(...args) {
|
|
43
|
-
if (args.length === 2) {
|
|
44
|
-
const [srcAlphabet, destAlphabet] = args;
|
|
45
|
-
return (val) => convertBaseToBase(srcAlphabet, destAlphabet, val);
|
|
46
|
-
}
|
|
47
|
-
const [srcAlphabet, destAlphabet, val] = args;
|
|
48
|
-
return convertDecimalToBase(destAlphabet, convertBaseToDecimal(srcAlphabet, val));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
exports.convertBaseToBase = convertBaseToBase;
|
|
52
|
-
exports.convertBaseToDecimal = convertBaseToDecimal;
|
|
53
|
-
exports.convertDecimalToBase = convertDecimalToBase;
|
|
54
|
-
|
|
55
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
56
|
-
|
|
57
|
-
}));
|
|
58
|
-
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/convert-base-to-decimal.ts","../src/convert-decimal-to-base.ts","../src/convert-base-to-base.ts"],"sourcesContent":["export function convertBaseToDecimal(alphabet: string, val: string): bigint\nexport function convertBaseToDecimal(alphabet: string): (val: string) => bigint\nexport function convertBaseToDecimal(...args:\n| [alphabet: string, val: string]\n| [alphabet: string]\n) {\n if (args.length === 1) {\n const [alphabet] = args\n return (val: string) => convertBaseToDecimal(alphabet, val)\n }\n\n const [alphabet, val] = args\n const base = BigInt(alphabet.length)\n\n let accumulator = 0n\n for (let i = val.length; i--;) {\n const char = val[i]\n const indexOfAlphabet = alphabet.indexOf(char)\n const currentValue = BigInt(indexOfAlphabet) * (base ** BigInt(val.length - i - 1))\n accumulator += currentValue\n }\n return accumulator\n}\n","export function convertDecimalToBase(alphabet: string, val: bigint): string\nexport function convertDecimalToBase(alphabet: string): (val: bigint) => string\nexport function convertDecimalToBase(...args:\n| [alphabet: string, val: bigint]\n| [alphabet: string]\n) {\n if (args.length === 1) {\n const [alphabet] = args\n return (val: bigint) => convertDecimalToBase(alphabet, val)\n }\n\n const [alphabet, val] = args\n const base = BigInt(alphabet.length)\n const result: string[] = []\n\n let temp = val\n do {\n const remainder = Number(temp % base)\n result.push(alphabet[remainder])\n } while ((temp = temp / base) !== 0n)\n\n return result\n .reverse()\n .join('')\n}\n","import { convertDecimalToBase } from './convert-decimal-to-base'\nimport { convertBaseToDecimal } from './convert-base-to-decimal'\n\nexport function convertBaseToBase(\n srcAlphabet: string\n, destAlphabet: string\n, val: string\n): string\nexport function convertBaseToBase(\n srcAlphabet: string\n, destAlphabet: string\n): (val: string) => string\nexport function convertBaseToBase(...args:\n| [srcAlphabet: string, destAlphabet: string, val: string]\n| [srcAlphabet: string, destAlphabet: string]\n) {\n if (args.length === 2) {\n const [srcAlphabet, destAlphabet] = args\n return (val: string) => convertBaseToBase(srcAlphabet, destAlphabet, val)\n }\n\n const [srcAlphabet, destAlphabet, val] = args\n return convertDecimalToBase(destAlphabet, convertBaseToDecimal(srcAlphabet, val))\n}\n"],"names":[],"mappings":";;;;;;IAEgB,SAAA,oBAAoB,CAAC,GAAG,IAEpB,EAAA;IAElB,IAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;IACrB,QAAA,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;YACvB,OAAO,CAAC,GAAW,KAAK,oBAAoB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IAC5D,KAAA;IAED,IAAA,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;QAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QAEpC,IAAI,WAAW,GAAG,EAAE,CAAA;QACpB,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG;IAC7B,QAAA,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;YACnB,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YAC9C,MAAM,YAAY,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;YACnF,WAAW,IAAI,YAAY,CAAA;IAC5B,KAAA;IACD,IAAA,OAAO,WAAW,CAAA;IACpB;;ICpBgB,SAAA,oBAAoB,CAAC,GAAG,IAEpB,EAAA;IAElB,IAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;IACrB,QAAA,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;YACvB,OAAO,CAAC,GAAW,KAAK,oBAAoB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IAC5D,KAAA;IAED,IAAA,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;QAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QACpC,MAAM,MAAM,GAAa,EAAE,CAAA;QAE3B,IAAI,IAAI,GAAG,GAAG,CAAA;QACd,GAAG;YACD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;YACrC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAA;SACjC,QAAQ,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,MAAM,EAAE,EAAC;IAErC,IAAA,OAAO,MAAM;IACV,SAAA,OAAO,EAAE;aACT,IAAI,CAAC,EAAE,CAAC,CAAA;IACb;;ICZgB,SAAA,iBAAiB,CAAC,GAAG,IAEQ,EAAA;IAE3C,IAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;IACrB,QAAA,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,GAAG,IAAI,CAAA;IACxC,QAAA,OAAO,CAAC,GAAW,KAAK,iBAAiB,CAAC,WAAW,EAAE,YAAY,EAAE,GAAG,CAAC,CAAA;IAC1E,KAAA;QAED,MAAM,CAAC,WAAW,EAAE,YAAY,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;QAC7C,OAAO,oBAAoB,CAAC,YAAY,EAAE,oBAAoB,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAA;IACnF;;;;;;;;;;;;"}
|
package/dist/index.umd.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).BigIntBase={})}(this,(function(e){"use strict";function n(...e){if(1===e.length){const[t]=e;return e=>n(t,e)}const[t,o]=e,i=BigInt(t.length);let r=0n;for(let e=o.length;e--;){const n=o[e],s=t.indexOf(n);r+=BigInt(s)*i**BigInt(o.length-e-1)}return r}function t(...e){if(1===e.length){const[n]=e;return e=>t(n,e)}const[n,o]=e,i=BigInt(n.length),r=[];let s=o;do{const e=Number(s%i);r.push(n[e])}while(0n!==(s/=i));return r.reverse().join("")}e.convertBaseToBase=function e(...o){if(2===o.length){const[n,t]=o;return o=>e(n,t,o)}const[i,r,s]=o;return t(r,n(i,s))},e.convertBaseToDecimal=n,e.convertDecimalToBase=t,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
|
-
//# sourceMappingURL=index.umd.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.min.js","sources":["../src/convert-base-to-decimal.ts","../src/convert-decimal-to-base.ts","../src/convert-base-to-base.ts"],"sourcesContent":["export function convertBaseToDecimal(alphabet: string, val: string): bigint\nexport function convertBaseToDecimal(alphabet: string): (val: string) => bigint\nexport function convertBaseToDecimal(...args:\n| [alphabet: string, val: string]\n| [alphabet: string]\n) {\n if (args.length === 1) {\n const [alphabet] = args\n return (val: string) => convertBaseToDecimal(alphabet, val)\n }\n\n const [alphabet, val] = args\n const base = BigInt(alphabet.length)\n\n let accumulator = 0n\n for (let i = val.length; i--;) {\n const char = val[i]\n const indexOfAlphabet = alphabet.indexOf(char)\n const currentValue = BigInt(indexOfAlphabet) * (base ** BigInt(val.length - i - 1))\n accumulator += currentValue\n }\n return accumulator\n}\n","export function convertDecimalToBase(alphabet: string, val: bigint): string\nexport function convertDecimalToBase(alphabet: string): (val: bigint) => string\nexport function convertDecimalToBase(...args:\n| [alphabet: string, val: bigint]\n| [alphabet: string]\n) {\n if (args.length === 1) {\n const [alphabet] = args\n return (val: bigint) => convertDecimalToBase(alphabet, val)\n }\n\n const [alphabet, val] = args\n const base = BigInt(alphabet.length)\n const result: string[] = []\n\n let temp = val\n do {\n const remainder = Number(temp % base)\n result.push(alphabet[remainder])\n } while ((temp = temp / base) !== 0n)\n\n return result\n .reverse()\n .join('')\n}\n","import { convertDecimalToBase } from './convert-decimal-to-base'\nimport { convertBaseToDecimal } from './convert-base-to-decimal'\n\nexport function convertBaseToBase(\n srcAlphabet: string\n, destAlphabet: string\n, val: string\n): string\nexport function convertBaseToBase(\n srcAlphabet: string\n, destAlphabet: string\n): (val: string) => string\nexport function convertBaseToBase(...args:\n| [srcAlphabet: string, destAlphabet: string, val: string]\n| [srcAlphabet: string, destAlphabet: string]\n) {\n if (args.length === 2) {\n const [srcAlphabet, destAlphabet] = args\n return (val: string) => convertBaseToBase(srcAlphabet, destAlphabet, val)\n }\n\n const [srcAlphabet, destAlphabet, val] = args\n return convertDecimalToBase(destAlphabet, convertBaseToDecimal(srcAlphabet, val))\n}\n"],"names":["convertBaseToDecimal","args","length","alphabet","val","base","BigInt","accumulator","i","char","indexOfAlphabet","indexOf","convertDecimalToBase","result","temp","remainder","Number","push","reverse","join","convertBaseToBase","srcAlphabet","destAlphabet"],"mappings":"kPAEgB,SAAAA,KAAwBC,GAItC,GAAoB,IAAhBA,EAAKC,OAAc,CACrB,MAAOC,GAAYF,EACnB,OAAQG,GAAgBJ,EAAqBG,EAAUC,GAGzD,MAAOD,EAAUC,GAAOH,EAClBI,EAAOC,OAAOH,EAASD,QAE7B,IAAIK,EAAc,GAClB,IAAK,IAAIC,EAAIJ,EAAIF,OAAQM,KAAM,CAC7B,MAAMC,EAAOL,EAAII,GACXE,EAAkBP,EAASQ,QAAQF,GAEzCF,GADqBD,OAAOI,GAAoBL,GAAQC,OAAOF,EAAIF,OAASM,EAAI,GAGlF,OAAOD,ECnBO,SAAAK,KAAwBX,GAItC,GAAoB,IAAhBA,EAAKC,OAAc,CACrB,MAAOC,GAAYF,EACnB,OAAQG,GAAgBQ,EAAqBT,EAAUC,GAGzD,MAAOD,EAAUC,GAAOH,EAClBI,EAAOC,OAAOH,EAASD,QACvBW,EAAmB,GAEzB,IAAIC,EAAOV,EACX,EAAG,CACD,MAAMW,EAAYC,OAAOF,EAAOT,GAChCQ,EAAOI,KAAKd,EAASY,UACW,MAAxBD,GAAcT,IAExB,OAAOQ,EACJK,UACAC,KAAK,wBCXM,SAAAC,KAAqBnB,GAInC,GAAoB,IAAhBA,EAAKC,OAAc,CACrB,MAAOmB,EAAaC,GAAgBrB,EACpC,OAAQG,GAAgBgB,EAAkBC,EAAaC,EAAclB,GAGvE,MAAOiB,EAAaC,EAAclB,GAAOH,EACzC,OAAOW,EAAqBU,EAActB,EAAqBqB,EAAajB"}
|