base48-standard 1.0.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.
Files changed (3) hide show
  1. package/base48.js +27 -0
  2. package/package.json +27 -0
  3. package/test.mjs +9 -0
package/base48.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Base-48 Encoding Standard
3
+ * Version: 1.0.0
4
+ * Author: [Hrajto Mine/Hrajto]
5
+ */
6
+
7
+ const ALPHABET = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjklmnpqr";
8
+
9
+ export function encode(num) {
10
+ let n = BigInt(num); // Převod na BigInt pro nekonečnou přesnost
11
+ if (n === 0n) return ALPHABET[0];
12
+
13
+ let res = "";
14
+ while (n > 0n) {
15
+ res = ALPHABET[Number(n % 48n)] + res;
16
+ n = n / 48n;
17
+ }
18
+ return res;
19
+ }
20
+
21
+ export function decode(str) {
22
+ return str.split('').reduce((acc, char) => {
23
+ const index = ALPHABET.indexOf(char);
24
+ if (index === -1) throw new Error(`Invalid character: ${char}`);
25
+ return acc * 48n + BigInt(index);
26
+ }, 0n);
27
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "base48-standard",
3
+ "version": "1.0.0",
4
+ "description": "A high-density, human-friendly numeral system for memory addresses and compact data representation.",
5
+ "main": "base48.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "node test.mjs"
9
+ },
10
+ "keywords": [
11
+ "base48",
12
+ "encoding",
13
+ "hex-alternative",
14
+ "numeral-system",
15
+ "bigint"
16
+ ],
17
+ "author": "Hrajto",
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/hrajtocz1/base48.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/hrajtocz1/base48/issues"
25
+ },
26
+ "homepage": "https://hrajtocz1.github.io/base48/"
27
+ }
package/test.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import { encode, decode } from './base48.js';
2
+
3
+ const number = 123456789n; // 'n' denotes BigInt
4
+ const encoded = encode(number);
5
+ const decoded = decode(encoded);
6
+
7
+ console.log(`Original: ${number}`);
8
+ console.log(`Base-48: ${encoded}`);
9
+ console.log(`Retrospectively: ${decoded}`);