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) 737 B
import{a,b as c,c as t,d as o,e as f}from"./chunk-VAQA7TNE.js";import{a as y}from"./chunk-JF3YMNGM.js";function d(r){typeof r=="string"?r=new TextEncoder().encode(r):r instanceof ArrayBuffer&&(r=new Uint8Array(r));let[e,n]=y(r,t(r.length));return o(e,n,0,a),new TextDecoder().decode(e)}function U(r,e){typeof r=="string"?r=new TextEncoder().encode(r):r instanceof ArrayBuffer&&(r=new Uint8Array(r));let n=t(r.length);if(e.length<n)throw new RangeError("Cannot encode input as hex: Output too small");e=e.subarray(0,n);let s=n-r.length;return e.set(r,s),o(e,s,0,a)}function _(r){return typeof r=="string"&&(r=new TextEncoder().encode(r)),r.subarray(0,f(r,0,0,c))}export{t as calcSizeHex,_ as decodeHex,d as encodeHex,U as encodeIntoHex};