1.1.0 • Published 4 years ago

errorsparty.dev-base v1.1.0

Weekly downloads
3
License
MIT
Repository
-
Last release
4 years ago

errorsparty.dev-base

Turn a number into various radiusses.

Installation

yarn add errorpary.dev-base

Usage

In this Base module there are a few terms to learn;

  • Alphabet - A set of characters used to define the number system.
  • Base - In a positional numeral system, the radix or base is the number of unique digits, including the digit zero, used to represent numbers.
  • Encode - To convert something to another system.
  • Decode - To convert something from another system.

In this module an alphabet is a set of characters that build up the number system of the base. This module encodes from and decodes to Base 10, which is our normal number system. The module has Built-In alphabets and bases:

  • Base2
  • Base8
  • Base10
  • Base16
  • Base32
  • Base36
  • Base62
  • Base256

To use either of these bases you can import them by doing:

// Imports
import { Base16 } from "errorsparty.dev-base";

// Encode some number
Base16.encode(123); // "7b"

// Decode some string
Base16.decode("7b"); // 123n

Creating your own base.

myBase.ts

// Imports
import {
	Alphabet,
	Base
} from "errorsparty.dev-base";

// My base's alphabet.
export const alphabet = new Alphabet("abcdef");

// My custom base.
export const base = new Base(alphabet);

Gotchas

  1. This module uses errorsparty.dev-bigint to turn input into a big integer, values like 123, "0b123" or "9".repeat(999) are accepted.
  2. Decoding returns a big integer, you can turn them into a number by using Number(n).