An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# [`@natoboram/based.ts`](https://github.com/NatoBoram/based.ts)

[![Node.js CI](https://github.com/NatoBoram/based.ts/actions/workflows/node.js.yaml/badge.svg)](https://github.com/NatoBoram/based.ts/actions/workflows/node.js.yaml) [![Docker CI](https://github.com/NatoBoram/based.ts/actions/workflows/docker.yaml/badge.svg)](https://github.com/NatoBoram/based.ts/actions/workflows/docker.yaml) [![CodeQL](https://github.com/NatoBoram/based.ts/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/NatoBoram/based.ts/actions/workflows/github-code-scanning/codeql) [![Coverage](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fnatoboram.github.io%2Fbased.ts%2Fcoverage%2Fcoverage-summary.json&query=total.branches.pct&suffix=%25&logo=Vitest&label=Coverage&color=acd268)](https://natoboram.github.io/based.ts/coverage) [![GitHub Pages](https://github.com/NatoBoram/based.ts/actions/workflows/github-pages.yaml/badge.svg)](https://github.com/NatoBoram/based.ts/actions/workflows/github-pages.yaml) [![IPFS](https://img.shields.io/website?url=https%3A%2F%2Fk51qzi5uqu5dg6qr4avntelsqd6iljwbsvf24h6qxh0dcl5i00x86hhip22cc5.ipns.dweb.link&up_color=6BC4CE&down_color=E9502F&logo=ipfs&label=IPFS&labelColor=073A53)](https://k51qzi5uqu5dg6qr4avntelsqd6iljwbsvf24h6qxh0dcl5i00x86hhip22cc5.ipns.dweb.link) [![GitHub Downloads](https://img.shields.io/github/downloads/NatoBoram/based.ts/total?logo=github)](https://github.com/NatoBoram/based.ts/releases) [![NPM Downloads](https://img.shields.io/npm/dt/%40natoboram/based.ts?logo=npm)](https://www.npmjs.com/package/@natoboram/based.ts) [![JSR Score](https://jsr.io/badges/@natoboram/based-ts/score)](https://jsr.io/@natoboram/based-ts) [![Docker Pulls](https://img.shields.io/docker/pulls/natoboram/based.ts?logo=docker)](https://hub.docker.com/repository/docker/natoboram/based.ts) [![Dependabot Updates](https://github.com/NatoBoram/based.ts/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/NatoBoram/based.ts/actions/workflows/dependabot/dependabot-updates) [![Wakapi](https://wakapi.dev/api/badge/NatoBoram/interval:any/project:based.ts)](https://wakapi.dev/summary?interval=any&project=based.ts) [![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/NatoBoram/based.ts?logo=CodeRabbit&logoColor=FF570A&label=CodeRabbit%20Reviews&labelColor=171717&color=FF570A)](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 .