diff options
Diffstat (limited to 'src/lib/base.ts')
-rw-r--r-- | src/lib/base.ts | 32 |
1 files changed, 0 insertions, 32 deletions
diff --git a/src/lib/base.ts b/src/lib/base.ts deleted file mode 100644 index 59c91cc..0000000 --- a/src/lib/base.ts +++ /dev/null @@ -1,32 +0,0 @@ -export const b2: string[] = - '01'.split('') - -export const b16: string[] = - '0123456789abcdef'.split('') - -export const b62: string[] = - '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('') - -export function encode(n: bigint, charset: string[]): string { - const base = BigInt(charset.length) - - if (n == BigInt(0)) { - return '0' - } else { - var xs = [] - while (n > BigInt(0)) { - xs.push(charset[Number(n % base)]) - n = n / base - } - return xs.reverse().join('') - } -} - -export function decode(xs: string, charset: string[]): bigint { - const base = BigInt(charset.length) - - return xs - .split('') - .reverse() - .reduce((acc, x, i) => acc + (BigInt(charset.indexOf(x)) * (base ** BigInt(i))), BigInt(0)) -} |