From c9a0f009d97410b1f0e6409cd5af5ef91d67df35 Mon Sep 17 00:00:00 2001 From: luaneko Date: Sun, 12 Jan 2025 03:50:07 +1100 Subject: [PATCH] Add more encoder wrappers --- bytes.ts | 40 ++++++++++++++++++++++++++++++++++++++++ deno.json | 2 +- mod.ts | 14 +++++++++++--- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/bytes.ts b/bytes.ts index 6856245..9c21c3c 100644 --- a/bytes.ts +++ b/bytes.ts @@ -1,7 +1,15 @@ import { + decodeAscii85, + decodeBase32, + decodeBase58, decodeBase64, + decodeBase64Url, decodeHex, + encodeAscii85, + encodeBase32, + encodeBase58, encodeBase64, + encodeBase64Url, encodeHex, } from "jsr:@std/encoding@^1.0.6"; @@ -35,6 +43,22 @@ export function to_hex(b: BinaryLike): string { return encodeHex(to_utf8(b)); } +export function from_base32(s: BinaryLike): Uint8Array { + return decodeBase32(from_utf8(s)); +} + +export function to_base32(b: BinaryLike): string { + return encodeBase32(to_utf8(b)); +} + +export function from_base58(s: BinaryLike): Uint8Array { + return decodeBase58(from_utf8(s)); +} + +export function to_base58(b: BinaryLike): string { + return encodeBase58(to_utf8(b)); +} + export function from_base64(s: BinaryLike): Uint8Array { return decodeBase64(from_utf8(s)); } @@ -43,6 +67,22 @@ export function to_base64(b: BinaryLike): string { return encodeBase64(to_utf8(b)); } +export function from_base64url(s: BinaryLike): Uint8Array { + return decodeBase64Url(from_utf8(s)); +} + +export function to_base64url(b: BinaryLike): string { + return encodeBase64Url(to_utf8(b)); +} + +export function from_ascii85(s: BinaryLike): Uint8Array { + return decodeAscii85(from_utf8(s)); +} + +export function to_ascii85(b: BinaryLike): string { + return encodeAscii85(to_utf8(b)); +} + export function read_u8(b: Uint8Array, i = 0) { return b[i]; } diff --git a/deno.json b/deno.json index 2dfc35e..6921470 100644 --- a/deno.json +++ b/deno.json @@ -1,5 +1,5 @@ { "name": "@luaneko/lstd", - "version": "0.2.0", + "version": "0.2.1", "exports": "./mod.ts" } diff --git a/mod.ts b/mod.ts index a44ce4a..3887a63 100644 --- a/mod.ts +++ b/mod.ts @@ -1,12 +1,20 @@ export { type BinaryLike, from_utf8, - to_utf8, - encode_utf8, from_hex, - to_hex, + from_base32, + from_base58, from_base64, + from_base64url, + from_ascii85, + to_utf8, + to_hex, + to_base32, + to_base58, to_base64, + to_base64url, + to_ascii85, + encode_utf8, read_u8, write_u8, read_i8,