UNPKG

byte-encodings

Version:

Utilities for encoding and decoding common formats like hex, base64, and varint. Ported from Deno's @std/encoding.

2 lines (1 loc) 883 B
import{a as n,b as c,c as s,d as o,e as f}from"./chunk-FH24VJR6.js";import{a as A}from"./chunk-JF3YMNGM.js";function b(e,r={}){r.alphabet??="base32",typeof e=="string"?e=new TextEncoder().encode(e):e instanceof ArrayBuffer&&(e=new Uint8Array(e));let[a,t]=A(e,s(e.length));return o(a,t,0,n[r.alphabet],61),new TextDecoder().decode(a)}function U(e,r,a={}){a.alphabet??="base32",typeof e=="string"?e=new TextEncoder().encode(e):e instanceof ArrayBuffer&&(e=new Uint8Array(e));let t=s(e.length);if(r.length<t)throw new RangeError("Cannot encode input as base32: Output too small");r=r.subarray(0,t);let i=t-e.length;return r.set(e,i),o(r,i,0,n[a.alphabet],61)}function h(e,r={}){return r.alphabet??="base32",typeof e=="string"&&(e=new TextEncoder().encode(e)),e.subarray(0,f(e,0,0,c[r.alphabet],61))}export{s as calcSizeBase32,h as decodeBase32,b as encodeBase32,U as encodeIntoBase32};