Ecosyste.ms: Awesome
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: 30 days 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 (10 months ago)
- Default Branch: main
- Last Pushed: 2024-09-02T02:19:08.000Z (2 months ago)
- Last Synced: 2024-09-24T02:24:16.578Z (about 2 months ago)
- Topics: base10, base16, base2, base36, base62, base64, uuid
- Language: TypeScript
- Homepage: https://natoboram.github.io/based.ts/
- Size: 191 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# `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) [![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) [![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) [![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)
A TypeScript library for working with arbitrary bases.
## Installation
It can be installed globally if you want to generate base36-encoded UUIDs.
```sh
pnpm install --global @natoboram/based.ts
basedts
``````log
Base 36 UUID: 2pcugbwbg50o24pnu8h3u1f0b
```Proper CLI options are planned for the future, but for now that's all I needed this package for.
## Usage
```sh
pnpm i -D @natoboram/based.ts
``````ts
import {
basedToBigInt,
bytesToBigInt,
getRandomBytes,
toBase,
} from "@natoboram/based.ts"// Generate a base36-encoded UUID
const bytes = getRandomBytes()
const bigInt = bytesToBigInt(bytes)
const base36 = toBase(bigInt, 36n)
console.log("Base 36 UUID:", base36)// Convert between two bases
const base64 = toBase(basedToBigInt("20zsnycqen1k898slr7xgnc9t", 36n), 64n)
```