https://github.com/natoboram/based.ts
A TypeScript library for working with arbitrary bases
https://github.com/natoboram/based.ts
base10 base16 base2 base36 base62 base64 uuid
Last synced: 2 months ago
JSON representation
A TypeScript library for working with arbitrary bases
- Host: GitHub
- URL: https://github.com/natoboram/based.ts
- Owner: NatoBoram
- License: lgpl-3.0
- Created: 2024-01-06T20:25:01.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-01T08:06:26.000Z (about 1 year ago)
- Last Synced: 2025-04-02T22:06:12.763Z (about 1 year ago)
- Topics: base10, base16, base2, base36, base62, base64, uuid
- Language: TypeScript
- Homepage: https://natoboram.github.io/based.ts/
- Size: 392 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yaml
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# [`@natoboram/based.ts`](https://github.com/NatoBoram/based.ts)
[](https://github.com/NatoBoram/based.ts/actions/workflows/node.js.yaml) [](https://github.com/NatoBoram/based.ts/actions/workflows/docker.yaml) [](https://github.com/NatoBoram/based.ts/actions/workflows/github-code-scanning/codeql) [](https://natoboram.github.io/based.ts/coverage) [](https://github.com/NatoBoram/based.ts/actions/workflows/github-pages.yaml) [](https://k51qzi5uqu5dg6qr4avntelsqd6iljwbsvf24h6qxh0dcl5i00x86hhip22cc5.ipns.dweb.link) [](https://github.com/NatoBoram/based.ts/releases) [](https://www.npmjs.com/package/@natoboram/based.ts) [](https://jsr.io/@natoboram/based-ts) [](https://hub.docker.com/repository/docker/natoboram/based.ts) [](https://github.com/NatoBoram/based.ts/actions/workflows/dependabot/dependabot-updates) [](https://wakapi.dev/summary?interval=any&project=based.ts) [](https://github.com/NatoBoram/based.ts/pulls?q=reviewed-by%3Acoderabbitai%5Bbot%5D)
A TypeScript library for working with arbitrary bases.
## CLI
It can be installed globally if you want to convert numbers or generate UUIDs from the terminal.
```sh
pnpm add --global @natoboram/based.ts
pnpm add --global jsr:@natoboram/based-ts
```
```log
Usage: basedts convert [options]
Convert a number from a base in a space to another base in another space
Arguments:
number The number to convert
Options:
--from-base The base of the number (default: "10")
--from-space The space of the number to convert from (default: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/")
--to-base The base to convert to (default: "10")
--to-space The space to convert the number to (default: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/")
```
```log
Usage: basedts uuid [options]
Generate a UUID in a different base with a different space than normal UUIDs
Options:
--base The base of the UUID to generate (default: "16")
--space The space of the UUID to generate (default: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/")
-h, --help Display help for command
```
## Library
```sh
pnpm add @natoboram/based.ts
pnpm add jsr:@natoboram/based-ts
```
```ts
import { toBase, basedToBigInt } from "@natoboram/based.ts"
// Convert between two bases
const bigInt = basedToBigInt("69", 10n)
const based = toBase(bigInt, 16n)
console.log(based) // 45
```
```ts
import { Based } from "@natoboram/based.ts"
// Perform operations on numbers of different bases
const four = new Based("4", 64n)
const two = new Based("2", 16n)
const result = four.divide(two).to(10n)
console.log(result.value) // 2
```
## License
This _Source Code Form_ is subject to the terms of the **Mozilla Public License v2.0**. If a copy of the MPL was not distributed with this file, you can obtain one at .