Add more encoder wrappers

This commit is contained in:
luaneko 2025-01-12 03:50:07 +11:00
parent dff22f2b41
commit c9a0f009d9
Signed by: luaneko
GPG Key ID: 406809B8763FF07A
3 changed files with 52 additions and 4 deletions

View File

@ -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];
}

View File

@ -1,5 +1,5 @@
{
"name": "@luaneko/lstd",
"version": "0.2.0",
"version": "0.2.1",
"exports": "./mod.ts"
}

14
mod.ts
View File

@ -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,