base48-standard 1.0.1 → 1.0.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/base48.js +16 -5
- package/package.json +6 -3
- package/test.mjs +23 -5
package/base48.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base-48 Encoding Standard
|
|
3
|
-
* Version: 1.0.
|
|
3
|
+
* Version: 1.0.2
|
|
4
4
|
* Author: [Hrajto Mine/Hrajto]
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const ALPHABET = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjklmnpqr";
|
|
8
8
|
|
|
9
9
|
export function encode(num) {
|
|
10
|
-
let n = BigInt(num);
|
|
10
|
+
let n = BigInt(num);
|
|
11
|
+
|
|
12
|
+
if (n < 0n) throw new Error("Base48: Negative numbers are not supported.");
|
|
11
13
|
if (n === 0n) return ALPHABET[0];
|
|
12
|
-
|
|
14
|
+
|
|
13
15
|
let res = "";
|
|
14
16
|
while (n > 0n) {
|
|
15
17
|
res = ALPHABET[Number(n % 48n)] + res;
|
|
@@ -19,9 +21,18 @@ export function encode(num) {
|
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export function decode(str) {
|
|
24
|
+
if (typeof str !== 'string' || str.length === 0) {
|
|
25
|
+
throw new Error("Base48: Input must be a non-empty string.");
|
|
26
|
+
}
|
|
27
|
+
|
|
22
28
|
return str.split('').reduce((acc, char) => {
|
|
23
29
|
const index = ALPHABET.indexOf(char);
|
|
24
|
-
|
|
30
|
+
|
|
31
|
+
// Tohle je ta klíčová "blbuvzdornost"
|
|
32
|
+
if (index === -1) {
|
|
33
|
+
throw new Error(`Base48 Invalid character: "${char}". Remember, we don't use 0, O, I, or l.`);
|
|
34
|
+
}
|
|
35
|
+
|
|
25
36
|
return acc * 48n + BigInt(index);
|
|
26
37
|
}, 0n);
|
|
27
|
-
}
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "base48-standard",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A high-density, human-friendly numeral system for memory addresses and compact data representation.",
|
|
5
5
|
"main": "base48.js",
|
|
6
6
|
"type": "module",
|
|
@@ -23,5 +23,8 @@
|
|
|
23
23
|
"bugs": {
|
|
24
24
|
"url": "https://github.com/Base48-Standard/Base-48-Standard/issues"
|
|
25
25
|
},
|
|
26
|
-
"homepage": "https://base48-standard.github.io/Base-48-Standard/"
|
|
27
|
-
|
|
26
|
+
"homepage": "https://base48-standard.github.io/Base-48-Standard/",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"base48-standard": "^1.0.1"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/test.mjs
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
|
-
import { encode, decode } from '
|
|
1
|
+
import { encode, decode } from 'base48-standard';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
console.log("--- 🧪 Base-48 Standard v1.0.2 Test Suite ---");
|
|
4
|
+
|
|
5
|
+
// 1. Basic Encoding & Decoding Test
|
|
6
|
+
const number = 123456789n;
|
|
4
7
|
const encoded = encode(number);
|
|
5
8
|
const decoded = decode(encoded);
|
|
6
9
|
|
|
7
|
-
console.log(
|
|
8
|
-
console.log(
|
|
9
|
-
console.log(
|
|
10
|
+
console.log(`✅ Original Number: ${number}`);
|
|
11
|
+
console.log(`✅ Base-48 Result: ${encoded}`);
|
|
12
|
+
console.log(`✅ Decoded Back: ${decoded}`);
|
|
13
|
+
|
|
14
|
+
// 2. BigInt Precision Test
|
|
15
|
+
const bigNumber = 9007199254740991000n;
|
|
16
|
+
console.log(`\n💎 BigInt Test: ${encode(bigNumber)}`);
|
|
17
|
+
|
|
18
|
+
// 3. Robustness Test (Validation)
|
|
19
|
+
console.log("\n⚠️ Testing Validation (Expecting an error):");
|
|
20
|
+
try {
|
|
21
|
+
// Attempting to decode strings with forbidden characters (0, O, I, l)
|
|
22
|
+
decode("3mP8_0");
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.log(`❌ Caught Expected Error: ${error.message}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log("\n--- Testing Complete ---");
|