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) 644 B
import{c as i,d as c,e as s}from"./chunk-KSXH2JGP.js";import{a as o}from"./chunk-JF3YMNGM.js";var t=61,f=new TextEncoder().encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),y=new Uint8Array(128).fill(64);f.forEach((e,r)=>y[e]=r);function U(e){typeof e=="string"?e=new TextEncoder().encode(e):e instanceof ArrayBuffer?e=new Uint8Array(e).slice():e=e.slice();let[r,a]=o(e,i(e.length)),n=c(r,a,0,f,t);return n=r.indexOf(t,n-2),new TextDecoder().decode(n>0?new Uint8Array(r.buffer.transfer(n)):r)}function l(e){let r=new TextEncoder().encode(e);return new Uint8Array(r.buffer.transfer(s(r,0,0,y,t)))}export{U as a,l as b};