| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Ascii85. */ | ||
| export declare const enA85: Encode; | ||
| /** Converts Ascii85 to binary. */ | ||
| export declare const deA85: Decode; | ||
| /** Decodable Ascii85. */ | ||
| export declare const A85: RegExp; |
| /** @module */ | ||
| import { de85, en85, map } from "./lib.js"; | ||
| const A85_STR = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu"; | ||
| const A85_BIN = /* @__PURE__ */ map(A85_STR); | ||
| /** Converts binary to Ascii85. */ | ||
| export const enA85 = ($) => ($.length & 3 | ||
| ? en85(A85_STR, $).slice(0, ($.length & 3) - 4) | ||
| : en85(A85_STR, $)).replace(/(?<=^(?:[!-u]{5})*)!{5}/g, "z"); | ||
| /** Converts Ascii85 to binary. */ | ||
| export const deA85 = ($) => { | ||
| const as = $.replace(/\s+/g, "").replaceAll("z", "!!!!!"), to = as.length % 5; | ||
| return to | ||
| ? new Uint8Array(de85(A85_BIN, as + "u".repeat(5 - to)).subarray(0, to - 5)) | ||
| : de85(A85_BIN, as); | ||
| }; | ||
| /** Decodable Ascii85. */ | ||
| export const A85 = /^[!-uz]*$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base16. */ | ||
| export declare const enB16: Encode; | ||
| /** Converts base16 to binary. */ | ||
| export declare const deB16: Decode; | ||
| /** Decodable base16. */ | ||
| export declare const B16: RegExp; |
| /** @module */ | ||
| import { en, map } from "./lib.js"; | ||
| const B16_STR = /* @__PURE__ */ Array.from({ length: 256 }, (_, byte) => byte.toString(16).toUpperCase().padStart(2, "0")); | ||
| const B16_BIN = /* @__PURE__ */ map("0123456789ABCDEF", 32); | ||
| /** Converts binary to base16. */ | ||
| export const enB16 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; ++z) | ||
| string += B16_STR[$[z]]; | ||
| return string; | ||
| }; | ||
| /** Converts base16 to binary. */ | ||
| export const deB16 = ($) => { | ||
| const binary = new Uint8Array($.length >> 1); | ||
| for (let z = 0; z < $.length; z += 2) { | ||
| binary[z >> 1] = B16_BIN[en.call($, z)] << 4 | B16_BIN[en.call($, z + 1)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| /** Decodable base16. */ | ||
| export const B16 = /^(?:[\dA-Fa-f]{2})*$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base32. */ | ||
| export declare const enB32: Encode; | ||
| /** Converts base32 to binary. */ | ||
| export declare const deB32: Decode; | ||
| /** Decodable base32. */ | ||
| export declare const B32: RegExp; |
| /** @module */ | ||
| import { de32, en32, map } from "./lib.js"; | ||
| const B32_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | ||
| /** Converts binary to base32. */ | ||
| export const enB32 = /* @__PURE__ */ en32.bind(null, B32_STR); | ||
| /** Converts base32 to binary. */ | ||
| export const deB32 = /* @__PURE__ */ de32.bind(null, /* @__PURE__ */ map(B32_STR, 32)); | ||
| /** Decodable base32. */ | ||
| export const B32 = /^[2-7A-Za-z]*$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base58. */ | ||
| export declare const enB58: Encode; | ||
| /** Converts base58 to binary. */ | ||
| export declare const deB58: Decode; | ||
| /** Decodable base58. */ | ||
| export declare const B58: RegExp; |
| /** @module */ | ||
| import { en, map } from "./lib.js"; | ||
| const B58_STR = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; | ||
| const B58_BIN = /* @__PURE__ */ map(B58_STR); | ||
| /** Converts binary to base58. */ | ||
| export const enB58 = ($) => { | ||
| let length = 0, string = "", z = 0; | ||
| while ($[z] === 0) | ||
| string += "1", ++z; | ||
| const size = $.length * 1.38 + 1 | 0, temp = new Uint8Array(size); | ||
| for (let carry, y, x; z < $.length; length = y, ++z) { | ||
| carry = $[z], y = 0, x = size; | ||
| do | ||
| carry += temp[--x] << 8, | ||
| temp[x] = carry % 58, | ||
| carry = carry / 58 | 0; | ||
| while ((++y < length || carry) && x); | ||
| } | ||
| for (z = size - length; z < size; ++z) | ||
| string += B58_STR[temp[z]]; | ||
| return string; | ||
| }; | ||
| /** Converts base58 to binary. */ | ||
| export const deB58 = ($) => { | ||
| let length = 0, zeroes = 0, z = 0; | ||
| while (en.call($, z) === 49) | ||
| ++z, ++zeroes; | ||
| const size = $.length * .733 + 1 | 0, temp = new Uint8Array(size); | ||
| for (let carry, y, x; z < $.length; length = y, ++z) { | ||
| carry = B58_BIN[en.call($, z)], y = 0, x = size; | ||
| do | ||
| carry += temp[--x] * 58, temp[x] = carry, carry >>= 8; | ||
| while ((++y < length || carry) && x); | ||
| } | ||
| const binary = new Uint8Array(zeroes + length); | ||
| for (z = size - length; z < size; ++zeroes, ++z) | ||
| binary[zeroes] = temp[z]; | ||
| return binary; | ||
| }; | ||
| /** Decodable base58. */ | ||
| export const B58 = /^[1-9A-HJ-NP-Za-km-z]*$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base64. */ | ||
| export declare const enB64: Encode; | ||
| /** Converts base64 to binary. */ | ||
| export declare const deB64: Decode; | ||
| /** Decodable base64. */ | ||
| export declare const B64: RegExp; |
| /** @module */ | ||
| import { de64, en, map } from "./lib.js"; | ||
| const B64_BIN = /* @__PURE__ */ map("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); | ||
| /** Converts binary to base64. */ | ||
| export const enB64 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; ++z) | ||
| string += String.fromCharCode($[z]); | ||
| return btoa(string); | ||
| }; | ||
| /** Converts base64 to binary. */ | ||
| export const deB64 = ($) => { | ||
| try { | ||
| const raw = atob($), binary = new Uint8Array(raw.length); | ||
| for (let z = 0; z < raw.length; ++z) | ||
| binary[z] = en.call(raw, z); | ||
| return binary; | ||
| } | ||
| catch { | ||
| return de64(B64_BIN, $ = $.replace(/=+$/, "")); | ||
| } | ||
| }; | ||
| /** Decodable base64. */ | ||
| export const B64 = /^(?:[+/\dA-Za-z]{4})*(?:[+/\dA-Za-z]{2}[+/\d=A-Za-z]=)?$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Crockford base 32. */ | ||
| export declare const enC32: Encode; | ||
| /** Converts Crockford base 32 to binary. */ | ||
| export declare const deC32: Decode; | ||
| /** Decodable Crockford base32. */ | ||
| export declare const C32: RegExp; |
| /** @module */ | ||
| import { de32, en, en32, map } from "./lib.js"; | ||
| const C32_STR = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"; | ||
| const C32_BIN = /* @__PURE__ */ (() => { | ||
| const bin = map(C32_STR, 32); | ||
| for (const $ of "Oo") | ||
| bin[en.call($)] = 0; | ||
| for (const $ of "IiLl") | ||
| bin[en.call($)] = 1; | ||
| return bin; | ||
| })(); | ||
| /** Converts binary to Crockford base 32. */ | ||
| export const enC32 = /* @__PURE__ */ en32.bind(null, C32_STR); | ||
| /** Converts Crockford base 32 to binary. */ | ||
| export const deC32 = ($) => de32(C32_BIN, $.replace(/-+/g, "")); | ||
| /** Decodable Crockford base32. */ | ||
| export const C32 = /^[-\dA-TV-Za-tv-z]*$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base32hex. */ | ||
| export declare const enH32: Encode; | ||
| /** Converts base32hex to binary. */ | ||
| export declare const deH32: Decode; | ||
| /** Decodable base32hex. */ | ||
| export declare const H32: RegExp; |
| /** @module */ | ||
| import { de32, en32, map } from "./lib.js"; | ||
| const H32_STR = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; | ||
| /** Converts binary to base32hex. */ | ||
| export const enH32 = /* @__PURE__ */ en32.bind(null, H32_STR); | ||
| /** Converts base32hex to binary. */ | ||
| export const deH32 = /* @__PURE__ */ de32.bind(null, /* @__PURE__ */ map(H32_STR, 32)); | ||
| /** Decodable base32hex. */ | ||
| export const H32 = /^[\dA-Va-v]*$/; |
| /** Binary-to-string function. */ | ||
| export type Encode = (binary: Uint8Array) => string; | ||
| /** String-to-binary function. */ | ||
| export type Decode = (string: string) => Uint8Array<ArrayBuffer>; | ||
| /** UTF-16 character code encoder. */ | ||
| export declare const en: (this: string, index?: number) => number; | ||
| /** Creates a code-to-byte map. */ | ||
| export declare const map: ($: string, or?: number) => Uint8Array<ArrayBuffer>; | ||
| /** Converts binary to a radix-32 string. */ | ||
| export declare const en32: (str: string, $: Uint8Array) => string; | ||
| /** Converts a radix-32 string to binary. */ | ||
| export declare const de32: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; | ||
| /** Converts a radix-64 string to binary. */ | ||
| export declare const de64: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; | ||
| /** Converts binary to a radix-85 string. */ | ||
| export declare const en85: (str: string, $: Uint8Array) => string; | ||
| /** Converts a radix-85 string to binary. */ | ||
| export declare const de85: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; |
| /** UTF-16 character code encoder. */ | ||
| export const en = | ||
| /* @__PURE__ */ (() => String.prototype.charCodeAt)(); | ||
| /** Creates a code-to-byte map. */ | ||
| export const map = ($, or) => { | ||
| const bin = new Uint8Array(256); | ||
| for (let z = 0; z < $.length; ++z) { | ||
| bin[en.call($, z)] = z; | ||
| if (or) | ||
| bin[en.call($, z) | or] = z; | ||
| } | ||
| return bin; | ||
| }; | ||
| /** Converts binary to a radix-32 string. */ | ||
| export const en32 = (str, $) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 5) { | ||
| const a = $[z], b = $[z + 1], c = $[z + 2], d = $[z + 3], e = $[z + 4]; | ||
| string += str[a >> 3] + str[a << 2 & 28 | b >> 6] + str[b >> 1 & 31] + | ||
| str[b << 4 & 16 | c >> 4] + str[c << 1 & 30 | d >> 7] + str[d >> 2 & 31] + | ||
| str[d << 3 & 24 | e >> 5] + str[e & 31]; | ||
| } | ||
| return string.slice(0, Math.ceil($.length / 5 * 8)); | ||
| }; | ||
| /** Converts a radix-32 string to binary. */ | ||
| export const de32 = (bin, $) => { | ||
| const binary = new Uint8Array($.length * 5 >> 3); | ||
| for (let z = 0, y = 0; z < $.length; z += 8, y += 5) { | ||
| const a = bin[en.call($, z + 1)], b = bin[en.call($, z + 3)]; | ||
| const c = bin[en.call($, z + 4)], d = bin[en.call($, z + 6)]; | ||
| binary[y] = bin[en.call($, z)] << 3 | a >> 2 & 7; | ||
| binary[y + 1] = a << 6 & 192 | bin[en.call($, z + 2)] << 1 | b >> 4 & 1; | ||
| binary[y + 2] = b << 4 & 240 | c >> 1 & 15; | ||
| binary[y + 3] = c << 7 & 128 | bin[en.call($, z + 5)] << 2 | d >> 3 & 7; | ||
| binary[y + 4] = d << 5 & 224 | bin[en.call($, z + 7)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| /** Converts a radix-64 string to binary. */ | ||
| export const de64 = (bin, $) => { | ||
| const binary = new Uint8Array($.length * 3 >> 2); | ||
| for (let z = 0, y = 0; z < $.length; z += 4, y += 3) { | ||
| const a = bin[en.call($, z + 1)], b = bin[en.call($, z + 2)]; | ||
| binary[y] = bin[en.call($, z)] << 2 | a >> 4; | ||
| binary[y + 1] = a << 4 | b >> 2; | ||
| binary[y + 2] = b << 6 | bin[en.call($, z + 3)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| /** Converts binary to a radix-85 string. */ | ||
| export const en85 = (str, $) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 4) { | ||
| const a = ($[z] << 24 | $[z + 1] << 16 | $[z + 2] << 8 | $[z + 3]) >>> 0; | ||
| string += str[a / 52200625 % 85 | 0] + str[a / 614125 % 85 | 0] + | ||
| str[a / 7225 % 85 | 0] + str[a / 85 % 85 | 0] + str[a % 85]; | ||
| } | ||
| return string; | ||
| }; | ||
| /** Converts a radix-85 string to binary. */ | ||
| export const de85 = (bin, $) => { | ||
| const binary = new Uint8Array(Math.ceil($.length / 5 * 4)); | ||
| for (let z = 0, y = 0; z < $.length; z += 5, y += 4) { | ||
| const a = binary[y + 3] = bin[en.call($, z)] * 52200625 + | ||
| bin[en.call($, z + 1)] * 614125 + bin[en.call($, z + 2)] * 7225 + | ||
| bin[en.call($, z + 3)] * 85 + bin[en.call($, z + 4)]; | ||
| binary[y] = a >> 24, binary[y + 1] = a >> 16, binary[y + 2] = a >> 8; | ||
| } | ||
| return binary; | ||
| }; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base64url. */ | ||
| export declare const enU64: Encode; | ||
| /** Converts base64url to binary. */ | ||
| export declare const deU64: Decode; | ||
| /** Decodable base64url. */ | ||
| export declare const U64: RegExp; |
| /** @module */ | ||
| import { de64, map } from "./lib.js"; | ||
| const U64_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; | ||
| /** Converts binary to base64url. */ | ||
| export const enU64 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 3) { | ||
| const a = $[z], b = $[z + 1], c = $[z + 2]; | ||
| string += U64_STR[a >> 2] + U64_STR[a << 4 & 48 | b >> 4] + | ||
| U64_STR[b << 2 & 60 | c >> 6] + U64_STR[c & 63]; | ||
| } | ||
| return string.slice(0, Math.ceil($.length / 3 * 4)); | ||
| }; | ||
| /** Converts base64url to binary. */ | ||
| export const deU64 = /* @__PURE__ */ de64.bind(null, /* @__PURE__ */ map(U64_STR)); | ||
| /** Decodable base64url. */ | ||
| export const U64 = /^(?:[-\w]{4})*(?:[-\w]{2,3})?$/; |
| declare namespace _default { | ||
| let b16: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let b32: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let h32: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let b64: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let u64: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let c32: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let b58: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let z85: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let a85: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| } | ||
| export default _default; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Z85. */ | ||
| export declare const enZ85: Encode; | ||
| /** Converts Z85 to binary. */ | ||
| export declare const deZ85: Decode; | ||
| /** Decodable Z85. */ | ||
| export declare const Z85: RegExp; |
| /** @module */ | ||
| import { de85, en85, map } from "./lib.js"; | ||
| const Z85_STR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"; | ||
| /** Converts binary to Z85. */ | ||
| export const enZ85 = /* @__PURE__ */ en85.bind(null, Z85_STR); | ||
| /** Converts Z85 to binary. */ | ||
| export const deZ85 = /* @__PURE__ */ de85.bind(null, /* @__PURE__ */ map(Z85_STR)); | ||
| /** Decodable Z85. */ | ||
| export const Z85 = /^[!#-&(-+--:<-[\]^a-{}]*$/; |
| declare namespace _default { | ||
| let ranges: number[][]; | ||
| let utf8: string; | ||
| } | ||
| export default _default; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Ascii85. */ | ||
| export declare const enA85: Encode; | ||
| /** Converts Ascii85 to binary. */ | ||
| export declare const deA85: Decode; | ||
| /** Decodable Ascii85. */ | ||
| export declare const A85: RegExp; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.A85 = exports.deA85 = exports.enA85 = void 0; | ||
| /** @module */ | ||
| const lib_js_1 = require("./lib.js"); | ||
| const A85_STR = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu"; | ||
| const A85_BIN = /* @__PURE__ */ (0, lib_js_1.map)(A85_STR); | ||
| /** Converts binary to Ascii85. */ | ||
| const enA85 = ($) => ($.length & 3 | ||
| ? (0, lib_js_1.en85)(A85_STR, $).slice(0, ($.length & 3) - 4) | ||
| : (0, lib_js_1.en85)(A85_STR, $)).replace(/(?<=^(?:[!-u]{5})*)!{5}/g, "z"); | ||
| exports.enA85 = enA85; | ||
| /** Converts Ascii85 to binary. */ | ||
| const deA85 = ($) => { | ||
| const as = $.replace(/\s+/g, "").replaceAll("z", "!!!!!"), to = as.length % 5; | ||
| return to | ||
| ? new Uint8Array((0, lib_js_1.de85)(A85_BIN, as + "u".repeat(5 - to)).subarray(0, to - 5)) | ||
| : (0, lib_js_1.de85)(A85_BIN, as); | ||
| }; | ||
| exports.deA85 = deA85; | ||
| /** Decodable Ascii85. */ | ||
| exports.A85 = /^[!-uz]*$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base16. */ | ||
| export declare const enB16: Encode; | ||
| /** Converts base16 to binary. */ | ||
| export declare const deB16: Decode; | ||
| /** Decodable base16. */ | ||
| export declare const B16: RegExp; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.B16 = exports.deB16 = exports.enB16 = void 0; | ||
| /** @module */ | ||
| const lib_js_1 = require("./lib.js"); | ||
| const B16_STR = /* @__PURE__ */ Array.from({ length: 256 }, (_, byte) => byte.toString(16).toUpperCase().padStart(2, "0")); | ||
| const B16_BIN = /* @__PURE__ */ (0, lib_js_1.map)("0123456789ABCDEF", 32); | ||
| /** Converts binary to base16. */ | ||
| const enB16 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; ++z) | ||
| string += B16_STR[$[z]]; | ||
| return string; | ||
| }; | ||
| exports.enB16 = enB16; | ||
| /** Converts base16 to binary. */ | ||
| const deB16 = ($) => { | ||
| const binary = new Uint8Array($.length >> 1); | ||
| for (let z = 0; z < $.length; z += 2) { | ||
| binary[z >> 1] = B16_BIN[lib_js_1.en.call($, z)] << 4 | B16_BIN[lib_js_1.en.call($, z + 1)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| exports.deB16 = deB16; | ||
| /** Decodable base16. */ | ||
| exports.B16 = /^(?:[\dA-Fa-f]{2})*$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base32. */ | ||
| export declare const enB32: Encode; | ||
| /** Converts base32 to binary. */ | ||
| export declare const deB32: Decode; | ||
| /** Decodable base32. */ | ||
| export declare const B32: RegExp; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.B32 = exports.deB32 = exports.enB32 = void 0; | ||
| /** @module */ | ||
| const lib_js_1 = require("./lib.js"); | ||
| const B32_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | ||
| /** Converts binary to base32. */ | ||
| exports.enB32 = lib_js_1.en32.bind(null, B32_STR); | ||
| /** Converts base32 to binary. */ | ||
| exports.deB32 = lib_js_1.de32.bind(null, /* @__PURE__ */ (0, lib_js_1.map)(B32_STR, 32)); | ||
| /** Decodable base32. */ | ||
| exports.B32 = /^[2-7A-Za-z]*$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base58. */ | ||
| export declare const enB58: Encode; | ||
| /** Converts base58 to binary. */ | ||
| export declare const deB58: Decode; | ||
| /** Decodable base58. */ | ||
| export declare const B58: RegExp; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.B58 = exports.deB58 = exports.enB58 = void 0; | ||
| /** @module */ | ||
| const lib_js_1 = require("./lib.js"); | ||
| const B58_STR = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; | ||
| const B58_BIN = /* @__PURE__ */ (0, lib_js_1.map)(B58_STR); | ||
| /** Converts binary to base58. */ | ||
| const enB58 = ($) => { | ||
| let length = 0, string = "", z = 0; | ||
| while ($[z] === 0) | ||
| string += "1", ++z; | ||
| const size = $.length * 1.38 + 1 | 0, temp = new Uint8Array(size); | ||
| for (let carry, y, x; z < $.length; length = y, ++z) { | ||
| carry = $[z], y = 0, x = size; | ||
| do | ||
| carry += temp[--x] << 8, | ||
| temp[x] = carry % 58, | ||
| carry = carry / 58 | 0; | ||
| while ((++y < length || carry) && x); | ||
| } | ||
| for (z = size - length; z < size; ++z) | ||
| string += B58_STR[temp[z]]; | ||
| return string; | ||
| }; | ||
| exports.enB58 = enB58; | ||
| /** Converts base58 to binary. */ | ||
| const deB58 = ($) => { | ||
| let length = 0, zeroes = 0, z = 0; | ||
| while (lib_js_1.en.call($, z) === 49) | ||
| ++z, ++zeroes; | ||
| const size = $.length * .733 + 1 | 0, temp = new Uint8Array(size); | ||
| for (let carry, y, x; z < $.length; length = y, ++z) { | ||
| carry = B58_BIN[lib_js_1.en.call($, z)], y = 0, x = size; | ||
| do | ||
| carry += temp[--x] * 58, temp[x] = carry, carry >>= 8; | ||
| while ((++y < length || carry) && x); | ||
| } | ||
| const binary = new Uint8Array(zeroes + length); | ||
| for (z = size - length; z < size; ++zeroes, ++z) | ||
| binary[zeroes] = temp[z]; | ||
| return binary; | ||
| }; | ||
| exports.deB58 = deB58; | ||
| /** Decodable base58. */ | ||
| exports.B58 = /^[1-9A-HJ-NP-Za-km-z]*$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base64. */ | ||
| export declare const enB64: Encode; | ||
| /** Converts base64 to binary. */ | ||
| export declare const deB64: Decode; | ||
| /** Decodable base64. */ | ||
| export declare const B64: RegExp; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.B64 = exports.deB64 = exports.enB64 = void 0; | ||
| /** @module */ | ||
| const lib_js_1 = require("./lib.js"); | ||
| const B64_BIN = /* @__PURE__ */ (0, lib_js_1.map)("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); | ||
| /** Converts binary to base64. */ | ||
| const enB64 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; ++z) | ||
| string += String.fromCharCode($[z]); | ||
| return btoa(string); | ||
| }; | ||
| exports.enB64 = enB64; | ||
| /** Converts base64 to binary. */ | ||
| const deB64 = ($) => { | ||
| try { | ||
| const raw = atob($), binary = new Uint8Array(raw.length); | ||
| for (let z = 0; z < raw.length; ++z) | ||
| binary[z] = lib_js_1.en.call(raw, z); | ||
| return binary; | ||
| } | ||
| catch { | ||
| return (0, lib_js_1.de64)(B64_BIN, $ = $.replace(/=+$/, "")); | ||
| } | ||
| }; | ||
| exports.deB64 = deB64; | ||
| /** Decodable base64. */ | ||
| exports.B64 = /^(?:[+/\dA-Za-z]{4})*(?:[+/\dA-Za-z]{2}[+/\d=A-Za-z]=)?$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Crockford base 32. */ | ||
| export declare const enC32: Encode; | ||
| /** Converts Crockford base 32 to binary. */ | ||
| export declare const deC32: Decode; | ||
| /** Decodable Crockford base32. */ | ||
| export declare const C32: RegExp; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.C32 = exports.deC32 = exports.enC32 = void 0; | ||
| /** @module */ | ||
| const lib_js_1 = require("./lib.js"); | ||
| const C32_STR = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"; | ||
| const C32_BIN = /* @__PURE__ */ (() => { | ||
| const bin = (0, lib_js_1.map)(C32_STR, 32); | ||
| for (const $ of "Oo") | ||
| bin[lib_js_1.en.call($)] = 0; | ||
| for (const $ of "IiLl") | ||
| bin[lib_js_1.en.call($)] = 1; | ||
| return bin; | ||
| })(); | ||
| /** Converts binary to Crockford base 32. */ | ||
| exports.enC32 = lib_js_1.en32.bind(null, C32_STR); | ||
| /** Converts Crockford base 32 to binary. */ | ||
| const deC32 = ($) => (0, lib_js_1.de32)(C32_BIN, $.replace(/-+/g, "")); | ||
| exports.deC32 = deC32; | ||
| /** Decodable Crockford base32. */ | ||
| exports.C32 = /^[-\dA-TV-Za-tv-z]*$/; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base32hex. */ | ||
| export declare const enH32: Encode; | ||
| /** Converts base32hex to binary. */ | ||
| export declare const deH32: Decode; | ||
| /** Decodable base32hex. */ | ||
| export declare const H32: RegExp; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.H32 = exports.deH32 = exports.enH32 = void 0; | ||
| /** @module */ | ||
| const lib_js_1 = require("./lib.js"); | ||
| const H32_STR = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; | ||
| /** Converts binary to base32hex. */ | ||
| exports.enH32 = lib_js_1.en32.bind(null, H32_STR); | ||
| /** Converts base32hex to binary. */ | ||
| exports.deH32 = lib_js_1.de32.bind(null, /* @__PURE__ */ (0, lib_js_1.map)(H32_STR, 32)); | ||
| /** Decodable base32hex. */ | ||
| exports.H32 = /^[\dA-Va-v]*$/; |
| /** Binary-to-string function. */ | ||
| export type Encode = (binary: Uint8Array) => string; | ||
| /** String-to-binary function. */ | ||
| export type Decode = (string: string) => Uint8Array<ArrayBuffer>; | ||
| /** UTF-16 character code encoder. */ | ||
| export declare const en: (this: string, index?: number) => number; | ||
| /** Creates a code-to-byte map. */ | ||
| export declare const map: ($: string, or?: number) => Uint8Array<ArrayBuffer>; | ||
| /** Converts binary to a radix-32 string. */ | ||
| export declare const en32: (str: string, $: Uint8Array) => string; | ||
| /** Converts a radix-32 string to binary. */ | ||
| export declare const de32: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; | ||
| /** Converts a radix-64 string to binary. */ | ||
| export declare const de64: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; | ||
| /** Converts binary to a radix-85 string. */ | ||
| export declare const en85: (str: string, $: Uint8Array) => string; | ||
| /** Converts a radix-85 string to binary. */ | ||
| export declare const de85: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.de85 = exports.en85 = exports.de64 = exports.de32 = exports.en32 = exports.map = exports.en = void 0; | ||
| /** UTF-16 character code encoder. */ | ||
| exports.en = | ||
| /* @__PURE__ */ (() => String.prototype.charCodeAt)(); | ||
| /** Creates a code-to-byte map. */ | ||
| const map = ($, or) => { | ||
| const bin = new Uint8Array(256); | ||
| for (let z = 0; z < $.length; ++z) { | ||
| bin[exports.en.call($, z)] = z; | ||
| if (or) | ||
| bin[exports.en.call($, z) | or] = z; | ||
| } | ||
| return bin; | ||
| }; | ||
| exports.map = map; | ||
| /** Converts binary to a radix-32 string. */ | ||
| const en32 = (str, $) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 5) { | ||
| const a = $[z], b = $[z + 1], c = $[z + 2], d = $[z + 3], e = $[z + 4]; | ||
| string += str[a >> 3] + str[a << 2 & 28 | b >> 6] + str[b >> 1 & 31] + | ||
| str[b << 4 & 16 | c >> 4] + str[c << 1 & 30 | d >> 7] + str[d >> 2 & 31] + | ||
| str[d << 3 & 24 | e >> 5] + str[e & 31]; | ||
| } | ||
| return string.slice(0, Math.ceil($.length / 5 * 8)); | ||
| }; | ||
| exports.en32 = en32; | ||
| /** Converts a radix-32 string to binary. */ | ||
| const de32 = (bin, $) => { | ||
| const binary = new Uint8Array($.length * 5 >> 3); | ||
| for (let z = 0, y = 0; z < $.length; z += 8, y += 5) { | ||
| const a = bin[exports.en.call($, z + 1)], b = bin[exports.en.call($, z + 3)]; | ||
| const c = bin[exports.en.call($, z + 4)], d = bin[exports.en.call($, z + 6)]; | ||
| binary[y] = bin[exports.en.call($, z)] << 3 | a >> 2 & 7; | ||
| binary[y + 1] = a << 6 & 192 | bin[exports.en.call($, z + 2)] << 1 | b >> 4 & 1; | ||
| binary[y + 2] = b << 4 & 240 | c >> 1 & 15; | ||
| binary[y + 3] = c << 7 & 128 | bin[exports.en.call($, z + 5)] << 2 | d >> 3 & 7; | ||
| binary[y + 4] = d << 5 & 224 | bin[exports.en.call($, z + 7)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| exports.de32 = de32; | ||
| /** Converts a radix-64 string to binary. */ | ||
| const de64 = (bin, $) => { | ||
| const binary = new Uint8Array($.length * 3 >> 2); | ||
| for (let z = 0, y = 0; z < $.length; z += 4, y += 3) { | ||
| const a = bin[exports.en.call($, z + 1)], b = bin[exports.en.call($, z + 2)]; | ||
| binary[y] = bin[exports.en.call($, z)] << 2 | a >> 4; | ||
| binary[y + 1] = a << 4 | b >> 2; | ||
| binary[y + 2] = b << 6 | bin[exports.en.call($, z + 3)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| exports.de64 = de64; | ||
| /** Converts binary to a radix-85 string. */ | ||
| const en85 = (str, $) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 4) { | ||
| const a = ($[z] << 24 | $[z + 1] << 16 | $[z + 2] << 8 | $[z + 3]) >>> 0; | ||
| string += str[a / 52200625 % 85 | 0] + str[a / 614125 % 85 | 0] + | ||
| str[a / 7225 % 85 | 0] + str[a / 85 % 85 | 0] + str[a % 85]; | ||
| } | ||
| return string; | ||
| }; | ||
| exports.en85 = en85; | ||
| /** Converts a radix-85 string to binary. */ | ||
| const de85 = (bin, $) => { | ||
| const binary = new Uint8Array(Math.ceil($.length / 5 * 4)); | ||
| for (let z = 0, y = 0; z < $.length; z += 5, y += 4) { | ||
| const a = binary[y + 3] = bin[exports.en.call($, z)] * 52200625 + | ||
| bin[exports.en.call($, z + 1)] * 614125 + bin[exports.en.call($, z + 2)] * 7225 + | ||
| bin[exports.en.call($, z + 3)] * 85 + bin[exports.en.call($, z + 4)]; | ||
| binary[y] = a >> 24, binary[y + 1] = a >> 16, binary[y + 2] = a >> 8; | ||
| } | ||
| return binary; | ||
| }; | ||
| exports.de85 = de85; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base64url. */ | ||
| export declare const enU64: Encode; | ||
| /** Converts base64url to binary. */ | ||
| export declare const deU64: Decode; | ||
| /** Decodable base64url. */ | ||
| export declare const U64: RegExp; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.U64 = exports.deU64 = exports.enU64 = void 0; | ||
| /** @module */ | ||
| const lib_js_1 = require("./lib.js"); | ||
| const U64_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; | ||
| /** Converts binary to base64url. */ | ||
| const enU64 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 3) { | ||
| const a = $[z], b = $[z + 1], c = $[z + 2]; | ||
| string += U64_STR[a >> 2] + U64_STR[a << 4 & 48 | b >> 4] + | ||
| U64_STR[b << 2 & 60 | c >> 6] + U64_STR[c & 63]; | ||
| } | ||
| return string.slice(0, Math.ceil($.length / 3 * 4)); | ||
| }; | ||
| exports.enU64 = enU64; | ||
| /** Converts base64url to binary. */ | ||
| exports.deU64 = lib_js_1.de64.bind(null, /* @__PURE__ */ (0, lib_js_1.map)(U64_STR)); | ||
| /** Decodable base64url. */ | ||
| exports.U64 = /^(?:[-\w]{4})*(?:[-\w]{2,3})?$/; |
| declare namespace _default { | ||
| let b16: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let b32: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let h32: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let b64: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let u64: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let c32: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let b58: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let z85: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| let a85: { | ||
| binary: string; | ||
| string: string; | ||
| }[]; | ||
| } | ||
| export default _default; |
| /** @module */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Z85. */ | ||
| export declare const enZ85: Encode; | ||
| /** Converts Z85 to binary. */ | ||
| export declare const deZ85: Decode; | ||
| /** Decodable Z85. */ | ||
| export declare const Z85: RegExp; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Z85 = exports.deZ85 = exports.enZ85 = void 0; | ||
| /** @module */ | ||
| const lib_js_1 = require("./lib.js"); | ||
| const Z85_STR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"; | ||
| /** Converts binary to Z85. */ | ||
| exports.enZ85 = lib_js_1.en85.bind(null, Z85_STR); | ||
| /** Converts Z85 to binary. */ | ||
| exports.deZ85 = lib_js_1.de85.bind(null, /* @__PURE__ */ (0, lib_js_1.map)(Z85_STR)); | ||
| /** Decodable Z85. */ | ||
| exports.Z85 = /^[!#-&(-+--:<-[\]^a-{}]*$/; |
| declare namespace _default { | ||
| let ranges: number[][]; | ||
| let utf8: string; | ||
| } | ||
| export default _default; |
+32
-27
| { | ||
| "name": "@libn/base", | ||
| "version": "0.3.5", | ||
| "version": "0.4.0", | ||
| "homepage": "https://jsr.io/@libn/base", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/nathanielyoon/libn.git" | ||
| "url": "git+https://github.com/nathanielyoon/libn.git", | ||
| "directory": "base" | ||
| }, | ||
| "license": "0BSD", | ||
| "main": "./script/utf.js", | ||
| "module": "./esm/utf.js", | ||
| "main": "./script/base/b16.js", | ||
| "module": "./esm/base/b16.js", | ||
| "exports": { | ||
| "./utf": { | ||
| "import": "./esm/utf.js", | ||
| "require": "./script/utf.js" | ||
| }, | ||
| "./b16": { | ||
| "import": "./esm/b16.js", | ||
| "require": "./script/b16.js" | ||
| "import": "./esm/base/b16.js", | ||
| "require": "./script/base/b16.js" | ||
| }, | ||
| "./b32": { | ||
| "import": "./esm/b32.js", | ||
| "require": "./script/b32.js" | ||
| "import": "./esm/base/b32.js", | ||
| "require": "./script/base/b32.js" | ||
| }, | ||
| "./h32": { | ||
| "import": "./esm/h32.js", | ||
| "require": "./script/h32.js" | ||
| "import": "./esm/base/h32.js", | ||
| "require": "./script/base/h32.js" | ||
| }, | ||
| "./c32": { | ||
| "import": "./esm/c32.js", | ||
| "require": "./script/c32.js" | ||
| "import": "./esm/base/c32.js", | ||
| "require": "./script/base/c32.js" | ||
| }, | ||
| "./b58": { | ||
| "import": "./esm/b58.js", | ||
| "require": "./script/b58.js" | ||
| "import": "./esm/base/b58.js", | ||
| "require": "./script/base/b58.js" | ||
| }, | ||
| "./b64": { | ||
| "import": "./esm/b64.js", | ||
| "require": "./script/b64.js" | ||
| "import": "./esm/base/b64.js", | ||
| "require": "./script/base/b64.js" | ||
| }, | ||
| "./u64": { | ||
| "import": "./esm/u64.js", | ||
| "require": "./script/u64.js" | ||
| "import": "./esm/base/u64.js", | ||
| "require": "./script/base/u64.js" | ||
| }, | ||
| "./z85": { | ||
| "import": "./esm/z85.js", | ||
| "require": "./script/z85.js" | ||
| "import": "./esm/base/z85.js", | ||
| "require": "./script/base/z85.js" | ||
| }, | ||
| "./a85": { | ||
| "import": "./esm/a85.js", | ||
| "require": "./script/a85.js" | ||
| "import": "./esm/base/a85.js", | ||
| "require": "./script/base/a85.js" | ||
| } | ||
| }, | ||
| "scripts": {}, | ||
| "scripts": { | ||
| "test": "node test_runner.js" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^20.9.0", | ||
| "picocolors": "^1.0.0", | ||
| "fast-check": "^4.3.0", | ||
| "@deno/shim-deno": "~0.18.0" | ||
| }, | ||
| "_generatedBy": "dnt@dev" | ||
| } |
+136
-11
@@ -5,16 +5,141 @@ # @libn/base | ||
| ```sh | ||
| deno add jsr:@libn/base | ||
| ## b16 | ||
| npm install @libn/base | ||
| npx jsr add @libn/base | ||
| [Base16](https://www.rfc-editor.org/rfc/rfc4648#section-8) uses hexadecimal | ||
| characters ("0-9" and "A-F"). Encoding is always uppercase (diverging from | ||
| [Number.prototype.toString](https://dev.mozilla.org/Web/JavaScript/Reference/Global_Objects/Number/toString) | ||
| and | ||
| [Uint8Array.prototype.toHex](https://dev.mozilla.org/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex), | ||
| which use lowercase "a-f"), and decoding is case-insensitive. | ||
| bun add @libn/base | ||
| bunx jsr add @libn/base | ||
| ```ts | ||
| import { deB16, enB16 } from "@libn/base/b16"; | ||
| import { assertEquals } from "@std/assert"; | ||
| const binary = new TextEncoder().encode("Hello :)"); | ||
| assertEquals(enB16(binary), "48656C6C6F203A29"); | ||
| assertEquals(deB16("48656C6C6F203A29"), binary); | ||
| ``` | ||
| - [RFC 4648](https://www.rfc-editor.org/rfc/rfc4648) | ||
| - [Crockford base 32](https://crockford.com/base32) | ||
| - [base58.h](https://github.com/bitcoin/bitcoin/blob/master/src/base58.h) | ||
| - [Z85](https://rfc.zeromq.org/spec/32) | ||
| - [Ascii85](https://en.wikipedia.org/wiki/Ascii85) | ||
| ## b32 | ||
| [Base32](https://www.rfc-editor.org/rfc/rfc4648#section-6) uses uppercase | ||
| letters and digits, excluding "0", "1", "8", and "9". Encoding is always | ||
| uppercase, and decoding is case-insensitive. | ||
| ```ts | ||
| import { deB32, enB32 } from "@libn/base/b32"; | ||
| import { assertEquals } from "@std/assert"; | ||
| const binary = new TextEncoder().encode("Hello :)"); | ||
| assertEquals(enB32(binary), "JBSWY3DPEA5CS"); | ||
| assertEquals(deB32("JBSWY3DPEA5CS"), binary); | ||
| ``` | ||
| ## h32 | ||
| [Base32hex](https://www.rfc-editor.org/rfc/rfc4648#section-7) uses digits and | ||
| uppercase letters, excluding "W-Z". Encoding is always uppercase, and decoding | ||
| is case-insensitive. | ||
| ```ts | ||
| import { deH32, enH32 } from "@libn/base/h32"; | ||
| import { assertEquals } from "@std/assert"; | ||
| const binary = new TextEncoder().encode("Hello :)"); | ||
| assertEquals(enH32(binary), "91IMOR3F40T2I"); | ||
| assertEquals(deH32("91IMOR3F40T2I"), binary); | ||
| ``` | ||
| ## c32 | ||
| [Crockford base 32](https://crockford.com/base32) uses digits and uppercase | ||
| letters, excluding "I", "L", "O", and "U". Encoding is always uppercase, and | ||
| decoding is case-insensitive, and additionally accepts hyphens (which don't | ||
| affect the output) and substitutes "I", "L", and "O" characters for their | ||
| similar-looking numeric counterparts ("1", "1", and "0", respectively). | ||
| ```ts | ||
| import { deC32, enC32 } from "@libn/base/c32"; | ||
| import { assertEquals } from "@std/assert"; | ||
| const binary = new TextEncoder().encode("Hello :)"); | ||
| assertEquals(enC32(binary), "91JPRV3F40X2J"); | ||
| assertEquals(deC32("91JPRV3F40X2J"), binary); | ||
| ``` | ||
| ## b58 | ||
| [Base58](https://github.com/bitcoin/bitcoin/blob/master/src/base58.h) uses | ||
| alphanumeric characters, excluding "0", "I", "O", and "l". | ||
| ```ts | ||
| import { deB58, enB58 } from "@libn/base/b58"; | ||
| import { assertEquals } from "@std/assert"; | ||
| const binary = new TextEncoder().encode("Hello :)"); | ||
| assertEquals(enB58(binary), "D7LMXYjUZJQ"); | ||
| assertEquals(deB58("D7LMXYjUZJQ"), binary); | ||
| ``` | ||
| ## b64 | ||
| [Base64](https://www.rfc-editor.org/rfc/rfc4648#section-4) uses alphanumeric | ||
| characters and "+" and "/", and "=" for padding. | ||
| ```ts | ||
| import { deB64, enB64 } from "@libn/base/b64"; | ||
| import { assertEquals } from "@std/assert"; | ||
| const binary = new TextEncoder().encode("Hello :)"); | ||
| assertEquals(enB64(binary), "SGVsbG8gOik="); | ||
| assertEquals(deB64("SGVsbG8gOik="), binary); | ||
| ``` | ||
| ## u64 | ||
| [Base64url](https://www.rfc-editor.org/rfc/rfc4648#section-5) uses alphanumeric | ||
| characters and "-" and "_". Padding is neither encoded nor decoded. | ||
| ```ts | ||
| import { deU64, enU64 } from "@libn/base/u64"; | ||
| import { assertEquals, assertMatch } from "@std/assert"; | ||
| const binary = new TextEncoder().encode("Hello :)"); | ||
| assertEquals(enU64(binary), "SGVsbG8gOik"); | ||
| assertEquals(deU64("SGVsbG8gOik"), binary); | ||
| ``` | ||
| ## z85 | ||
| [Z85](https://rfc.zeromq.org/spec/32) uses printable, non-whitespace ASCII | ||
| characters, excluding '"', "'", ",", ";", "\\", "_", "`", "|", and "~". Unlike | ||
| the [original](https://rfc.zeromq.org/spec/32/#formal-specification), the binary | ||
| input length doesn't have to be a multiple of 4, the encoding and decoding | ||
| functions add and remove padding automatically. | ||
| ```ts | ||
| import { deZ85, enZ85 } from "@libn/base/z85"; | ||
| import { assertEquals, assertMatch } from "@std/assert"; | ||
| const binary = new TextEncoder().encode("Hello :)"); | ||
| assertEquals(enZ85(binary), "nm=QNzY?7&"); | ||
| assertEquals(deZ85("nm=QNzY?7&"), binary); | ||
| ``` | ||
| ## a85 | ||
| [Ascii85](https://en.wikipedia.org/wiki/Ascii85) uses the first 85 printable, | ||
| non-whitespace ASCII characters, as well as "z" to compress sequences of 4 empty | ||
| bytes. Unlike the [original](https://en.wikipedia.org/wiki/Ascii85#Limitations), | ||
| the binary input length doesn't have to be a multiple of 4, the encoding and | ||
| decoding functions add and remove padding automatically. | ||
| ```ts | ||
| import { deA85, enA85 } from "@libn/base/a85"; | ||
| import { assertEquals } from "@std/assert"; | ||
| const binary = new TextEncoder().encode("Hello :)"); | ||
| assertEquals(enA85(binary), "87cURD]h(i"); | ||
| assertEquals(deA85("87cURD]h(i"), binary); | ||
| ``` |
-27
| /** | ||
| * [Ascii85](https://en.wikipedia.org/wiki/Ascii85) uses the first 85 printable, | ||
| * non-whitespace ASCII characters, as well as "z" to compress sequences of 4 | ||
| * empty bytes. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enA85(binary), "87cURD]h(i"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deA85("87cURD]h(i"), binary); | ||
| * ``` | ||
| * | ||
| * @module a85 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Ascii85. */ | ||
| export declare const enA85: Encode; | ||
| /** Converts Ascii85 to binary. */ | ||
| export declare const deA85: Decode; | ||
| /** Decodable Ascii85. */ | ||
| export declare const A85: RegExp; |
-36
| /** | ||
| * [Ascii85](https://en.wikipedia.org/wiki/Ascii85) uses the first 85 printable, | ||
| * non-whitespace ASCII characters, as well as "z" to compress sequences of 4 | ||
| * empty bytes. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enA85(binary), "87cURD]h(i"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deA85("87cURD]h(i"), binary); | ||
| * ``` | ||
| * | ||
| * @module a85 | ||
| */ | ||
| import { de85, en85, map } from "./lib.js"; | ||
| const A85_STR = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu"; | ||
| const A85_BIN = /* @__PURE__ */ map(A85_STR); | ||
| /** Converts binary to Ascii85. */ | ||
| export const enA85 = ($) => ($.length & 3 | ||
| ? en85(A85_STR, $).slice(0, ($.length & 3) - 4) | ||
| : en85(A85_STR, $)).replace(/(?<=^(?:[!-u]{5})*)!{5}/g, "z"); | ||
| /** Converts Ascii85 to binary. */ | ||
| export const deA85 = ($) => { | ||
| const as = $.replace(/\s+/g, "").replaceAll("z", "!!!!!"), to = as.length % 5; | ||
| return to | ||
| ? new Uint8Array(de85(A85_BIN, as + "u".repeat(5 - to)).subarray(0, to - 5)) | ||
| : de85(A85_BIN, as); | ||
| }; | ||
| /** Decodable Ascii85. */ | ||
| export const A85 = /^[!-uz]*$/; |
-30
| /** | ||
| * [Base16](https://www.rfc-editor.org/rfc/rfc4648#section-8) uses hexadecimal | ||
| * characters ("0-9" and "A-F"). Encoding is always uppercase (diverging from | ||
| * [Number.prototype.toString](https://dev.mozilla.org/Web/JavaScript/Reference/Global_Objects/Number/toString) | ||
| * and | ||
| * [Uint8Array.prototype.toHex](https://dev.mozilla.org/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex), | ||
| * which use lowercase "a-f"), and decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB16(binary), "48656C6C6F203A29"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB16("48656C6C6F203A29"), binary); | ||
| * ``` | ||
| * | ||
| * @module b16 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base16. */ | ||
| export declare const enB16: Encode; | ||
| /** Converts base16 to binary. */ | ||
| export declare const deB16: Decode; | ||
| /** Decodable base16. */ | ||
| export declare const B16: RegExp; |
-44
| /** | ||
| * [Base16](https://www.rfc-editor.org/rfc/rfc4648#section-8) uses hexadecimal | ||
| * characters ("0-9" and "A-F"). Encoding is always uppercase (diverging from | ||
| * [Number.prototype.toString](https://dev.mozilla.org/Web/JavaScript/Reference/Global_Objects/Number/toString) | ||
| * and | ||
| * [Uint8Array.prototype.toHex](https://dev.mozilla.org/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex), | ||
| * which use lowercase "a-f"), and decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB16(binary), "48656C6C6F203A29"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB16("48656C6C6F203A29"), binary); | ||
| * ``` | ||
| * | ||
| * @module b16 | ||
| */ | ||
| import { map } from "./lib.js"; | ||
| import { en } from "./utf.js"; | ||
| const B16_STR = /* @__PURE__ */ Array.from({ length: 256 }, (_, byte) => byte.toString(16).toUpperCase().padStart(2, "0")); | ||
| const B16_BIN = /* @__PURE__ */ map("0123456789ABCDEF", 32); | ||
| /** Converts binary to base16. */ | ||
| export const enB16 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; ++z) | ||
| string += B16_STR[$[z]]; | ||
| return string; | ||
| }; | ||
| /** Converts base16 to binary. */ | ||
| export const deB16 = ($) => { | ||
| const binary = new Uint8Array($.length >> 1); | ||
| for (let z = 0; z < $.length; z += 2) { | ||
| binary[z >> 1] = B16_BIN[en.call($, z)] << 4 | B16_BIN[en.call($, z + 1)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| /** Decodable base16. */ | ||
| export const B16 = /^(?:[\dA-Fa-f]{2})*$/; |
-27
| /** | ||
| * [Base32](https://www.rfc-editor.org/rfc/rfc4648#section-6) uses uppercase | ||
| * letters and digits, excluding "0", "1", "8", and "9". Encoding is always | ||
| * uppercase, and decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB32(binary), "JBSWY3DPEA5CS"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB32("JBSWY3DPEA5CS"), binary); | ||
| * ``` | ||
| * | ||
| * @module b32 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base32. */ | ||
| export declare const enB32: Encode; | ||
| /** Converts base32 to binary. */ | ||
| export declare const deB32: Decode; | ||
| /** Decodable base32. */ | ||
| export declare const B32: RegExp; |
-28
| /** | ||
| * [Base32](https://www.rfc-editor.org/rfc/rfc4648#section-6) uses uppercase | ||
| * letters and digits, excluding "0", "1", "8", and "9". Encoding is always | ||
| * uppercase, and decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB32(binary), "JBSWY3DPEA5CS"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB32("JBSWY3DPEA5CS"), binary); | ||
| * ``` | ||
| * | ||
| * @module b32 | ||
| */ | ||
| import { de32, en32, map } from "./lib.js"; | ||
| const B32_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | ||
| /** Converts binary to base32. */ | ||
| export const enB32 = /* @__PURE__ */ en32.bind(null, B32_STR); | ||
| /** Converts base32 to binary. */ | ||
| export const deB32 = /* @__PURE__ */ de32.bind(null, /* @__PURE__ */ map(B32_STR, 32)); | ||
| /** Decodable base32. */ | ||
| export const B32 = /^[2-7A-Za-z]*$/; |
-26
| /** | ||
| * [Base58](https://github.com/bitcoin/bitcoin/blob/master/src/base58.h) uses | ||
| * alphanumeric characters, excluding "0", "I", "O", and "l". | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB58(binary), "D7LMXYjUZJQ"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB58("D7LMXYjUZJQ"), binary); | ||
| * ``` | ||
| * | ||
| * @module b58 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base58. */ | ||
| export declare const enB58: Encode; | ||
| /** Converts base58 to binary. */ | ||
| export declare const deB58: Decode; | ||
| /** Decodable base58. */ | ||
| export declare const B58: RegExp; |
-60
| /** | ||
| * [Base58](https://github.com/bitcoin/bitcoin/blob/master/src/base58.h) uses | ||
| * alphanumeric characters, excluding "0", "I", "O", and "l". | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB58(binary), "D7LMXYjUZJQ"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB58("D7LMXYjUZJQ"), binary); | ||
| * ``` | ||
| * | ||
| * @module b58 | ||
| */ | ||
| import { map } from "./lib.js"; | ||
| import { en } from "./utf.js"; | ||
| const B58_STR = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; | ||
| const B58_BIN = /* @__PURE__ */ map(B58_STR); | ||
| /** Converts binary to base58. */ | ||
| export const enB58 = ($) => { | ||
| let length = 0, string = "", z = 0; | ||
| while ($[z] === 0) | ||
| string += "1", ++z; | ||
| const size = $.length * 1.38 + 1 | 0, temp = new Uint8Array(size); | ||
| for (let carry, y, x; z < $.length; length = y, ++z) { | ||
| carry = $[z], y = 0, x = size; | ||
| do | ||
| carry += temp[--x] << 8, | ||
| temp[x] = carry % 58, | ||
| carry = carry / 58 | 0; | ||
| while ((++y < length || carry) && x); | ||
| } | ||
| for (z = size - length; z < size; ++z) | ||
| string += B58_STR[temp[z]]; | ||
| return string; | ||
| }; | ||
| /** Converts base58 to binary. */ | ||
| export const deB58 = ($) => { | ||
| let length = 0, zeroes = 0, z = 0; | ||
| while (en.call($, z) === 49) | ||
| ++z, ++zeroes; | ||
| const size = $.length * .733 + 1 | 0, temp = new Uint8Array(size); | ||
| for (let carry, y, x; z < $.length; length = y, ++z) { | ||
| carry = B58_BIN[en.call($, z)], y = 0, x = size; | ||
| do | ||
| carry += temp[--x] * 58, temp[x] = carry, carry >>= 8; | ||
| while ((++y < length || carry) && x); | ||
| } | ||
| const binary = new Uint8Array(zeroes + length); | ||
| for (z = size - length; z < size; ++zeroes, ++z) | ||
| binary[zeroes] = temp[z]; | ||
| return binary; | ||
| }; | ||
| /** Decodable base58. */ | ||
| export const B58 = /^[1-9A-HJ-NP-Za-km-z]*$/; |
-26
| /** | ||
| * [Base64](https://www.rfc-editor.org/rfc/rfc4648#section-4) uses alphanumeric | ||
| * characters and "+" and "/", and "=" for padding. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB64(binary), "SGVsbG8gOik="); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB64("SGVsbG8gOik="), binary); | ||
| * ``` | ||
| * | ||
| * @module b64 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base64. */ | ||
| export declare const enB64: Encode; | ||
| /** Converts base64 to binary. */ | ||
| export declare const deB64: Decode; | ||
| /** Decodable base64. */ | ||
| export declare const B64: RegExp; |
-43
| /** | ||
| * [Base64](https://www.rfc-editor.org/rfc/rfc4648#section-4) uses alphanumeric | ||
| * characters and "+" and "/", and "=" for padding. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB64(binary), "SGVsbG8gOik="); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB64("SGVsbG8gOik="), binary); | ||
| * ``` | ||
| * | ||
| * @module b64 | ||
| */ | ||
| import { de64, map } from "./lib.js"; | ||
| import { de, en } from "./utf.js"; | ||
| const B64_BIN = /* @__PURE__ */ map("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); | ||
| /** Converts binary to base64. */ | ||
| export const enB64 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; ++z) | ||
| string += de($[z]); | ||
| return btoa(string); | ||
| }; | ||
| /** Converts base64 to binary. */ | ||
| export const deB64 = ($) => { | ||
| try { | ||
| const raw = atob($), binary = new Uint8Array(raw.length); | ||
| for (let z = 0; z < raw.length; ++z) | ||
| binary[z] = en.call(raw, z); | ||
| return binary; | ||
| } | ||
| catch { | ||
| return de64(B64_BIN, $ = $.replace(/=+$/, "")); | ||
| } | ||
| }; | ||
| /** Decodable base64. */ | ||
| export const B64 = /^(?:[+/\dA-Za-z]{4})*(?:[+/\dA-Za-z]{2}[+/\d=A-Za-z]=)?$/; |
-29
| /** | ||
| * [Crockford base 32](https://crockford.com/base32) uses digits and uppercase | ||
| * letters, excluding "I", "L", "O", and "U". Encoding is always uppercase, and | ||
| * decoding is case-insensitive, and additionally accepts hyphens (which don't | ||
| * affect the output) and substitutes "I", "L", and "O" characters for their | ||
| * similar-looking numeric counterparts ("1", "1", and "0", respectively). | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enC32(binary), "91JPRV3F40X2J"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deC32("91JPRV3F40X2J"), binary); | ||
| * ``` | ||
| * | ||
| * @module c32 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Crockford base 32. */ | ||
| export declare const enC32: Encode; | ||
| /** Converts Crockford base 32 to binary. */ | ||
| export declare const deC32: Decode; | ||
| /** Decodable Crockford base32. */ | ||
| export declare const C32: RegExp; |
-39
| /** | ||
| * [Crockford base 32](https://crockford.com/base32) uses digits and uppercase | ||
| * letters, excluding "I", "L", "O", and "U". Encoding is always uppercase, and | ||
| * decoding is case-insensitive, and additionally accepts hyphens (which don't | ||
| * affect the output) and substitutes "I", "L", and "O" characters for their | ||
| * similar-looking numeric counterparts ("1", "1", and "0", respectively). | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enC32(binary), "91JPRV3F40X2J"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deC32("91JPRV3F40X2J"), binary); | ||
| * ``` | ||
| * | ||
| * @module c32 | ||
| */ | ||
| import { de32, en32, map } from "./lib.js"; | ||
| import { en } from "./utf.js"; | ||
| const C32_STR = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"; | ||
| const C32_BIN = /* @__PURE__ */ (() => { | ||
| const bin = map(C32_STR, 32); | ||
| for (const $ of "Oo") | ||
| bin[en.call($)] = 0; | ||
| for (const $ of "IiLl") | ||
| bin[en.call($)] = 1; | ||
| return bin; | ||
| })(); | ||
| /** Converts binary to Crockford base 32. */ | ||
| export const enC32 = /* @__PURE__ */ en32.bind(null, C32_STR); | ||
| /** Converts Crockford base 32 to binary. */ | ||
| export const deC32 = ($) => de32(C32_BIN, $.replace(/-+/g, "")); | ||
| /** Decodable Crockford base32. */ | ||
| export const C32 = /^[-\dA-TV-Za-tv-z]*$/; |
-27
| /** | ||
| * [Base32hex](https://www.rfc-editor.org/rfc/rfc4648#section-7) uses digits | ||
| * and uppercase letters, excluding "W-Z". Encoding is always uppercase, and | ||
| * decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enH32(binary), "91IMOR3F40T2I"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deH32("91IMOR3F40T2I"), binary); | ||
| * ``` | ||
| * | ||
| * @module h32 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base32hex. */ | ||
| export declare const enH32: Encode; | ||
| /** Converts base32hex to binary. */ | ||
| export declare const deH32: Decode; | ||
| /** Decodable base32hex. */ | ||
| export declare const H32: RegExp; |
-28
| /** | ||
| * [Base32hex](https://www.rfc-editor.org/rfc/rfc4648#section-7) uses digits | ||
| * and uppercase letters, excluding "W-Z". Encoding is always uppercase, and | ||
| * decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enH32(binary), "91IMOR3F40T2I"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deH32("91IMOR3F40T2I"), binary); | ||
| * ``` | ||
| * | ||
| * @module h32 | ||
| */ | ||
| import { de32, en32, map } from "./lib.js"; | ||
| const H32_STR = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; | ||
| /** Converts binary to base32hex. */ | ||
| export const enH32 = /* @__PURE__ */ en32.bind(null, H32_STR); | ||
| /** Converts base32hex to binary. */ | ||
| export const deH32 = /* @__PURE__ */ de32.bind(null, /* @__PURE__ */ map(H32_STR, 32)); | ||
| /** Decodable base32hex. */ | ||
| export const H32 = /^[\dA-Va-v]*$/; |
-16
| /** Binary-to-string function. */ | ||
| export type Encode = (binary: Uint8Array) => string; | ||
| /** String-to-binary function. */ | ||
| export type Decode = (string: string) => Uint8Array<ArrayBuffer>; | ||
| /** Creates a code-to-byte map. */ | ||
| export declare const map: ($: string, or?: number) => Uint8Array<ArrayBuffer>; | ||
| /** Converts binary to a radix-32 string. */ | ||
| export declare const en32: (str: string, $: Uint8Array) => string; | ||
| /** Converts a radix-32 string to binary. */ | ||
| export declare const de32: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; | ||
| /** Converts a radix-64 string to binary. */ | ||
| export declare const de64: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; | ||
| /** Converts binary to a radix-85 string. */ | ||
| export declare const en85: (str: string, $: Uint8Array) => string; | ||
| /** Converts a radix-85 string to binary. */ | ||
| export declare const de85: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; |
-75
| import { en } from "./utf.js"; | ||
| /** Creates a code-to-byte map. */ | ||
| export const map = ($, or) => { | ||
| const bin = new Uint8Array(256); | ||
| for (let z = 0; z < $.length; ++z) { | ||
| bin[en.call($, z)] = z; | ||
| if (or) | ||
| bin[en.call($, z) | or] = z; | ||
| } | ||
| return bin; | ||
| }; | ||
| /** Converts binary to a radix-32 string. */ | ||
| export const en32 = (str, $) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 5) { | ||
| const a = $[z], b = $[z + 1], c = $[z + 2], d = $[z + 3], e = $[z + 4]; | ||
| string += str[a >> 3] + str[a << 2 & 28 | b >> 6] + str[b >> 1 & 31] + | ||
| str[b << 4 & 16 | c >> 4] + str[c << 1 & 30 | d >> 7] + str[d >> 2 & 31] + | ||
| str[d << 3 & 24 | e >> 5] + str[e & 31]; | ||
| } | ||
| return string.slice(0, Math.ceil($.length / 5 * 8)); | ||
| }; | ||
| /** Converts a radix-32 string to binary. */ | ||
| export const de32 = (bin, $) => { | ||
| const binary = new Uint8Array($.length * 5 >> 3); | ||
| for (let z = 0, y = 0; z < $.length; z += 8, y += 5) { | ||
| const a = bin[en.call($, z + 1)], b = bin[en.call($, z + 3)]; | ||
| const c = bin[en.call($, z + 4)], d = bin[en.call($, z + 6)]; | ||
| binary[y] = bin[en.call($, z)] << 3 | a >> 2 & 7; | ||
| binary[y + 1] = a << 6 & 192 | bin[en.call($, z + 2)] << 1 | b >> 4 & 1; | ||
| binary[y + 2] = b << 4 & 240 | c >> 1 & 15; | ||
| binary[y + 3] = c << 7 & 128 | bin[en.call($, z + 5)] << 2 | d >> 3 & 7; | ||
| binary[y + 4] = d << 5 & 224 | bin[en.call($, z + 7)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| /** Converts a radix-64 string to binary. */ | ||
| export const de64 = (bin, $) => { | ||
| const binary = new Uint8Array($.length * 3 >> 2); | ||
| for (let z = 0, y = 0; z < $.length; z += 4, y += 3) { | ||
| const a = bin[en.call($, z + 1)], b = bin[en.call($, z + 2)]; | ||
| binary[y] = bin[en.call($, z)] << 2 | a >> 4; | ||
| binary[y + 1] = a << 4 | b >> 2; | ||
| binary[y + 2] = b << 6 | bin[en.call($, z + 3)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| var Step; | ||
| (function (Step) { | ||
| Step[Step["A"] = 52200625] = "A"; | ||
| Step[Step["B"] = 614125] = "B"; | ||
| Step[Step["C"] = 7225] = "C"; | ||
| Step[Step["D"] = 85] = "D"; | ||
| })(Step || (Step = {})); | ||
| /** Converts binary to a radix-85 string. */ | ||
| export const en85 = (str, $) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 4) { | ||
| const a = ($[z] << 24 | $[z + 1] << 16 | $[z + 2] << 8 | $[z + 3]) >>> 0; | ||
| string += str[a / Step.A % 85 | 0] + str[a / Step.B % 85 | 0] + | ||
| str[a / Step.C % 85 | 0] + str[a / Step.D % 85 | 0] + str[a % 85]; | ||
| } | ||
| return string; | ||
| }; | ||
| /** Converts a radix-85 string to binary. */ | ||
| export const de85 = (bin, $) => { | ||
| const binary = new Uint8Array(Math.ceil($.length / 5 * 4)); | ||
| for (let z = 0, y = 0; z < $.length; z += 5, y += 4) { | ||
| const a = binary[y + 3] = bin[en.call($, z)] * Step.A + | ||
| bin[en.call($, z + 1)] * Step.B + bin[en.call($, z + 2)] * Step.C + | ||
| bin[en.call($, z + 3)] * Step.D + bin[en.call($, z + 4)]; | ||
| binary[y] = a >> 24, binary[y + 1] = a >> 16, binary[y + 2] = a >> 8; | ||
| } | ||
| return binary; | ||
| }; |
-27
| /** | ||
| * [Base64url](https://www.rfc-editor.org/rfc/rfc4648#section-5) uses | ||
| * alphanumeric characters and "-" and "_". Padding is neither encoded nor | ||
| * decoded. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals, assertMatch } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enU64(binary), "SGVsbG8gOik"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deU64("SGVsbG8gOik"), binary); | ||
| * ``` | ||
| * | ||
| * @module u64 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base64url. */ | ||
| export declare const enU64: Encode; | ||
| /** Converts base64url to binary. */ | ||
| export declare const deU64: Decode; | ||
| /** Decodable base64url. */ | ||
| export declare const U64: RegExp; |
-36
| /** | ||
| * [Base64url](https://www.rfc-editor.org/rfc/rfc4648#section-5) uses | ||
| * alphanumeric characters and "-" and "_". Padding is neither encoded nor | ||
| * decoded. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals, assertMatch } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enU64(binary), "SGVsbG8gOik"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deU64("SGVsbG8gOik"), binary); | ||
| * ``` | ||
| * | ||
| * @module u64 | ||
| */ | ||
| import { de64, map } from "./lib.js"; | ||
| const U64_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; | ||
| /** Converts binary to base64url. */ | ||
| export const enU64 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 3) { | ||
| const a = $[z], b = $[z + 1], c = $[z + 2]; | ||
| string += U64_STR[a >> 2] + U64_STR[a << 4 & 48 | b >> 4] + | ||
| U64_STR[b << 2 & 60 | c >> 6] + U64_STR[c & 63]; | ||
| } | ||
| return string.slice(0, Math.ceil($.length / 3 * 4)); | ||
| }; | ||
| /** Converts base64url to binary. */ | ||
| export const deU64 = /* @__PURE__ */ de64.bind(null, /* @__PURE__ */ map(U64_STR)); | ||
| /** Decodable base64url. */ | ||
| export const U64 = /^(?:[-\w]{4})*(?:[-\w]{2,3})?$/; |
-26
| /** | ||
| * Aliases for built-in UTF-8 and UTF-16 APIs. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * assertEquals(enUtf8("Hello :)"), binary); | ||
| * assertEquals(deUtf8(binary), "Hello :)"); | ||
| * | ||
| * assertEquals(en.call("Hello :)"), 72); | ||
| * assertEquals(en.call("Hello :)", 1), 101); | ||
| * assertEquals(de(...binary), "Hello :)"); | ||
| * ``` | ||
| * | ||
| * @module utf8 | ||
| */ | ||
| /** Character code getter. */ | ||
| export declare const en: (this: string, index?: number) => number; | ||
| /** Character code setter. */ | ||
| export declare const de: (...codes: number[]) => string; | ||
| /** Converts UTF-8 to binary. */ | ||
| export declare const enUtf8: ($?: string) => Uint8Array<ArrayBuffer>; | ||
| /** Converts binary to UTF-8. */ | ||
| export declare const deUtf8: ($?: AllowSharedBufferSource, options?: TextDecodeOptions) => string; |
-31
| /** | ||
| * Aliases for built-in UTF-8 and UTF-16 APIs. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * assertEquals(enUtf8("Hello :)"), binary); | ||
| * assertEquals(deUtf8(binary), "Hello :)"); | ||
| * | ||
| * assertEquals(en.call("Hello :)"), 72); | ||
| * assertEquals(en.call("Hello :)", 1), 101); | ||
| * assertEquals(de(...binary), "Hello :)"); | ||
| * ``` | ||
| * | ||
| * @module utf8 | ||
| */ | ||
| /** Character code getter. */ | ||
| export const en = | ||
| /* @__PURE__ */ (() => String.prototype.charCodeAt)(); | ||
| /** Character code setter. */ | ||
| export const de = | ||
| /* @__PURE__ */ (() => String.fromCharCode)(); | ||
| /** Converts UTF-8 to binary. */ | ||
| export const enUtf8 = | ||
| /* @__PURE__ */ TextEncoder.prototype.encode.bind( | ||
| /* @__PURE__ */ new TextEncoder()); | ||
| /** Converts binary to UTF-8. */ | ||
| export const deUtf8 = /* @__PURE__ */ TextDecoder.prototype.decode.bind( | ||
| /* @__PURE__ */ new TextDecoder("utf-8")); |
-26
| /** | ||
| * [Z85](https://rfc.zeromq.org/spec/32) uses printable, non-whitespace ASCII | ||
| * characters, excluding '"', "'", ",", ";", "\", "_", "`", "|", and "~". | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals, assertMatch } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enZ85(binary), "nm=QNzY?7&"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deZ85("nm=QNzY?7&"), binary); | ||
| * ``` | ||
| * | ||
| * @module z85 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Z85. */ | ||
| export declare const enZ85: Encode; | ||
| /** Converts Z85 to binary. */ | ||
| export declare const deZ85: Decode; | ||
| /** Decodable Z85. */ | ||
| export declare const Z85: RegExp; |
-27
| /** | ||
| * [Z85](https://rfc.zeromq.org/spec/32) uses printable, non-whitespace ASCII | ||
| * characters, excluding '"', "'", ",", ";", "\", "_", "`", "|", and "~". | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals, assertMatch } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enZ85(binary), "nm=QNzY?7&"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deZ85("nm=QNzY?7&"), binary); | ||
| * ``` | ||
| * | ||
| * @module z85 | ||
| */ | ||
| import { de85, en85, map } from "./lib.js"; | ||
| const Z85_STR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"; | ||
| /** Converts binary to Z85. */ | ||
| export const enZ85 = /* @__PURE__ */ en85.bind(null, Z85_STR); | ||
| /** Converts Z85 to binary. */ | ||
| export const deZ85 = /* @__PURE__ */ de85.bind(null, /* @__PURE__ */ map(Z85_STR)); | ||
| /** Decodable Z85. */ | ||
| export const Z85 = /^[!#-&(-+--:<-[\]^a-{}]*$/; |
| /** | ||
| * [Ascii85](https://en.wikipedia.org/wiki/Ascii85) uses the first 85 printable, | ||
| * non-whitespace ASCII characters, as well as "z" to compress sequences of 4 | ||
| * empty bytes. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enA85(binary), "87cURD]h(i"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deA85("87cURD]h(i"), binary); | ||
| * ``` | ||
| * | ||
| * @module a85 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Ascii85. */ | ||
| export declare const enA85: Encode; | ||
| /** Converts Ascii85 to binary. */ | ||
| export declare const deA85: Decode; | ||
| /** Decodable Ascii85. */ | ||
| export declare const A85: RegExp; |
| "use strict"; | ||
| /** | ||
| * [Ascii85](https://en.wikipedia.org/wiki/Ascii85) uses the first 85 printable, | ||
| * non-whitespace ASCII characters, as well as "z" to compress sequences of 4 | ||
| * empty bytes. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enA85(binary), "87cURD]h(i"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deA85("87cURD]h(i"), binary); | ||
| * ``` | ||
| * | ||
| * @module a85 | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.A85 = exports.deA85 = exports.enA85 = void 0; | ||
| const lib_js_1 = require("./lib.js"); | ||
| const A85_STR = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu"; | ||
| const A85_BIN = /* @__PURE__ */ (0, lib_js_1.map)(A85_STR); | ||
| /** Converts binary to Ascii85. */ | ||
| const enA85 = ($) => ($.length & 3 | ||
| ? (0, lib_js_1.en85)(A85_STR, $).slice(0, ($.length & 3) - 4) | ||
| : (0, lib_js_1.en85)(A85_STR, $)).replace(/(?<=^(?:[!-u]{5})*)!{5}/g, "z"); | ||
| exports.enA85 = enA85; | ||
| /** Converts Ascii85 to binary. */ | ||
| const deA85 = ($) => { | ||
| const as = $.replace(/\s+/g, "").replaceAll("z", "!!!!!"), to = as.length % 5; | ||
| return to | ||
| ? new Uint8Array((0, lib_js_1.de85)(A85_BIN, as + "u".repeat(5 - to)).subarray(0, to - 5)) | ||
| : (0, lib_js_1.de85)(A85_BIN, as); | ||
| }; | ||
| exports.deA85 = deA85; | ||
| /** Decodable Ascii85. */ | ||
| exports.A85 = /^[!-uz]*$/; |
| /** | ||
| * [Base16](https://www.rfc-editor.org/rfc/rfc4648#section-8) uses hexadecimal | ||
| * characters ("0-9" and "A-F"). Encoding is always uppercase (diverging from | ||
| * [Number.prototype.toString](https://dev.mozilla.org/Web/JavaScript/Reference/Global_Objects/Number/toString) | ||
| * and | ||
| * [Uint8Array.prototype.toHex](https://dev.mozilla.org/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex), | ||
| * which use lowercase "a-f"), and decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB16(binary), "48656C6C6F203A29"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB16("48656C6C6F203A29"), binary); | ||
| * ``` | ||
| * | ||
| * @module b16 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base16. */ | ||
| export declare const enB16: Encode; | ||
| /** Converts base16 to binary. */ | ||
| export declare const deB16: Decode; | ||
| /** Decodable base16. */ | ||
| export declare const B16: RegExp; |
| "use strict"; | ||
| /** | ||
| * [Base16](https://www.rfc-editor.org/rfc/rfc4648#section-8) uses hexadecimal | ||
| * characters ("0-9" and "A-F"). Encoding is always uppercase (diverging from | ||
| * [Number.prototype.toString](https://dev.mozilla.org/Web/JavaScript/Reference/Global_Objects/Number/toString) | ||
| * and | ||
| * [Uint8Array.prototype.toHex](https://dev.mozilla.org/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex), | ||
| * which use lowercase "a-f"), and decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB16(binary), "48656C6C6F203A29"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB16("48656C6C6F203A29"), binary); | ||
| * ``` | ||
| * | ||
| * @module b16 | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.B16 = exports.deB16 = exports.enB16 = void 0; | ||
| const lib_js_1 = require("./lib.js"); | ||
| const utf_js_1 = require("./utf.js"); | ||
| const B16_STR = /* @__PURE__ */ Array.from({ length: 256 }, (_, byte) => byte.toString(16).toUpperCase().padStart(2, "0")); | ||
| const B16_BIN = /* @__PURE__ */ (0, lib_js_1.map)("0123456789ABCDEF", 32); | ||
| /** Converts binary to base16. */ | ||
| const enB16 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; ++z) | ||
| string += B16_STR[$[z]]; | ||
| return string; | ||
| }; | ||
| exports.enB16 = enB16; | ||
| /** Converts base16 to binary. */ | ||
| const deB16 = ($) => { | ||
| const binary = new Uint8Array($.length >> 1); | ||
| for (let z = 0; z < $.length; z += 2) { | ||
| binary[z >> 1] = B16_BIN[utf_js_1.en.call($, z)] << 4 | B16_BIN[utf_js_1.en.call($, z + 1)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| exports.deB16 = deB16; | ||
| /** Decodable base16. */ | ||
| exports.B16 = /^(?:[\dA-Fa-f]{2})*$/; |
| /** | ||
| * [Base32](https://www.rfc-editor.org/rfc/rfc4648#section-6) uses uppercase | ||
| * letters and digits, excluding "0", "1", "8", and "9". Encoding is always | ||
| * uppercase, and decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB32(binary), "JBSWY3DPEA5CS"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB32("JBSWY3DPEA5CS"), binary); | ||
| * ``` | ||
| * | ||
| * @module b32 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base32. */ | ||
| export declare const enB32: Encode; | ||
| /** Converts base32 to binary. */ | ||
| export declare const deB32: Decode; | ||
| /** Decodable base32. */ | ||
| export declare const B32: RegExp; |
| "use strict"; | ||
| /** | ||
| * [Base32](https://www.rfc-editor.org/rfc/rfc4648#section-6) uses uppercase | ||
| * letters and digits, excluding "0", "1", "8", and "9". Encoding is always | ||
| * uppercase, and decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB32(binary), "JBSWY3DPEA5CS"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB32("JBSWY3DPEA5CS"), binary); | ||
| * ``` | ||
| * | ||
| * @module b32 | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.B32 = exports.deB32 = exports.enB32 = void 0; | ||
| const lib_js_1 = require("./lib.js"); | ||
| const B32_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | ||
| /** Converts binary to base32. */ | ||
| exports.enB32 = lib_js_1.en32.bind(null, B32_STR); | ||
| /** Converts base32 to binary. */ | ||
| exports.deB32 = lib_js_1.de32.bind(null, /* @__PURE__ */ (0, lib_js_1.map)(B32_STR, 32)); | ||
| /** Decodable base32. */ | ||
| exports.B32 = /^[2-7A-Za-z]*$/; |
| /** | ||
| * [Base58](https://github.com/bitcoin/bitcoin/blob/master/src/base58.h) uses | ||
| * alphanumeric characters, excluding "0", "I", "O", and "l". | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB58(binary), "D7LMXYjUZJQ"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB58("D7LMXYjUZJQ"), binary); | ||
| * ``` | ||
| * | ||
| * @module b58 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base58. */ | ||
| export declare const enB58: Encode; | ||
| /** Converts base58 to binary. */ | ||
| export declare const deB58: Decode; | ||
| /** Decodable base58. */ | ||
| export declare const B58: RegExp; |
| "use strict"; | ||
| /** | ||
| * [Base58](https://github.com/bitcoin/bitcoin/blob/master/src/base58.h) uses | ||
| * alphanumeric characters, excluding "0", "I", "O", and "l". | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB58(binary), "D7LMXYjUZJQ"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB58("D7LMXYjUZJQ"), binary); | ||
| * ``` | ||
| * | ||
| * @module b58 | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.B58 = exports.deB58 = exports.enB58 = void 0; | ||
| const lib_js_1 = require("./lib.js"); | ||
| const utf_js_1 = require("./utf.js"); | ||
| const B58_STR = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; | ||
| const B58_BIN = /* @__PURE__ */ (0, lib_js_1.map)(B58_STR); | ||
| /** Converts binary to base58. */ | ||
| const enB58 = ($) => { | ||
| let length = 0, string = "", z = 0; | ||
| while ($[z] === 0) | ||
| string += "1", ++z; | ||
| const size = $.length * 1.38 + 1 | 0, temp = new Uint8Array(size); | ||
| for (let carry, y, x; z < $.length; length = y, ++z) { | ||
| carry = $[z], y = 0, x = size; | ||
| do | ||
| carry += temp[--x] << 8, | ||
| temp[x] = carry % 58, | ||
| carry = carry / 58 | 0; | ||
| while ((++y < length || carry) && x); | ||
| } | ||
| for (z = size - length; z < size; ++z) | ||
| string += B58_STR[temp[z]]; | ||
| return string; | ||
| }; | ||
| exports.enB58 = enB58; | ||
| /** Converts base58 to binary. */ | ||
| const deB58 = ($) => { | ||
| let length = 0, zeroes = 0, z = 0; | ||
| while (utf_js_1.en.call($, z) === 49) | ||
| ++z, ++zeroes; | ||
| const size = $.length * .733 + 1 | 0, temp = new Uint8Array(size); | ||
| for (let carry, y, x; z < $.length; length = y, ++z) { | ||
| carry = B58_BIN[utf_js_1.en.call($, z)], y = 0, x = size; | ||
| do | ||
| carry += temp[--x] * 58, temp[x] = carry, carry >>= 8; | ||
| while ((++y < length || carry) && x); | ||
| } | ||
| const binary = new Uint8Array(zeroes + length); | ||
| for (z = size - length; z < size; ++zeroes, ++z) | ||
| binary[zeroes] = temp[z]; | ||
| return binary; | ||
| }; | ||
| exports.deB58 = deB58; | ||
| /** Decodable base58. */ | ||
| exports.B58 = /^[1-9A-HJ-NP-Za-km-z]*$/; |
| /** | ||
| * [Base64](https://www.rfc-editor.org/rfc/rfc4648#section-4) uses alphanumeric | ||
| * characters and "+" and "/", and "=" for padding. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB64(binary), "SGVsbG8gOik="); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB64("SGVsbG8gOik="), binary); | ||
| * ``` | ||
| * | ||
| * @module b64 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base64. */ | ||
| export declare const enB64: Encode; | ||
| /** Converts base64 to binary. */ | ||
| export declare const deB64: Decode; | ||
| /** Decodable base64. */ | ||
| export declare const B64: RegExp; |
| "use strict"; | ||
| /** | ||
| * [Base64](https://www.rfc-editor.org/rfc/rfc4648#section-4) uses alphanumeric | ||
| * characters and "+" and "/", and "=" for padding. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enB64(binary), "SGVsbG8gOik="); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deB64("SGVsbG8gOik="), binary); | ||
| * ``` | ||
| * | ||
| * @module b64 | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.B64 = exports.deB64 = exports.enB64 = void 0; | ||
| const lib_js_1 = require("./lib.js"); | ||
| const utf_js_1 = require("./utf.js"); | ||
| const B64_BIN = /* @__PURE__ */ (0, lib_js_1.map)("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); | ||
| /** Converts binary to base64. */ | ||
| const enB64 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; ++z) | ||
| string += (0, utf_js_1.de)($[z]); | ||
| return btoa(string); | ||
| }; | ||
| exports.enB64 = enB64; | ||
| /** Converts base64 to binary. */ | ||
| const deB64 = ($) => { | ||
| try { | ||
| const raw = atob($), binary = new Uint8Array(raw.length); | ||
| for (let z = 0; z < raw.length; ++z) | ||
| binary[z] = utf_js_1.en.call(raw, z); | ||
| return binary; | ||
| } | ||
| catch { | ||
| return (0, lib_js_1.de64)(B64_BIN, $ = $.replace(/=+$/, "")); | ||
| } | ||
| }; | ||
| exports.deB64 = deB64; | ||
| /** Decodable base64. */ | ||
| exports.B64 = /^(?:[+/\dA-Za-z]{4})*(?:[+/\dA-Za-z]{2}[+/\d=A-Za-z]=)?$/; |
| /** | ||
| * [Crockford base 32](https://crockford.com/base32) uses digits and uppercase | ||
| * letters, excluding "I", "L", "O", and "U". Encoding is always uppercase, and | ||
| * decoding is case-insensitive, and additionally accepts hyphens (which don't | ||
| * affect the output) and substitutes "I", "L", and "O" characters for their | ||
| * similar-looking numeric counterparts ("1", "1", and "0", respectively). | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enC32(binary), "91JPRV3F40X2J"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deC32("91JPRV3F40X2J"), binary); | ||
| * ``` | ||
| * | ||
| * @module c32 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Crockford base 32. */ | ||
| export declare const enC32: Encode; | ||
| /** Converts Crockford base 32 to binary. */ | ||
| export declare const deC32: Decode; | ||
| /** Decodable Crockford base32. */ | ||
| export declare const C32: RegExp; |
| "use strict"; | ||
| /** | ||
| * [Crockford base 32](https://crockford.com/base32) uses digits and uppercase | ||
| * letters, excluding "I", "L", "O", and "U". Encoding is always uppercase, and | ||
| * decoding is case-insensitive, and additionally accepts hyphens (which don't | ||
| * affect the output) and substitutes "I", "L", and "O" characters for their | ||
| * similar-looking numeric counterparts ("1", "1", and "0", respectively). | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enC32(binary), "91JPRV3F40X2J"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deC32("91JPRV3F40X2J"), binary); | ||
| * ``` | ||
| * | ||
| * @module c32 | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.C32 = exports.deC32 = exports.enC32 = void 0; | ||
| const lib_js_1 = require("./lib.js"); | ||
| const utf_js_1 = require("./utf.js"); | ||
| const C32_STR = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"; | ||
| const C32_BIN = /* @__PURE__ */ (() => { | ||
| const bin = (0, lib_js_1.map)(C32_STR, 32); | ||
| for (const $ of "Oo") | ||
| bin[utf_js_1.en.call($)] = 0; | ||
| for (const $ of "IiLl") | ||
| bin[utf_js_1.en.call($)] = 1; | ||
| return bin; | ||
| })(); | ||
| /** Converts binary to Crockford base 32. */ | ||
| exports.enC32 = lib_js_1.en32.bind(null, C32_STR); | ||
| /** Converts Crockford base 32 to binary. */ | ||
| const deC32 = ($) => (0, lib_js_1.de32)(C32_BIN, $.replace(/-+/g, "")); | ||
| exports.deC32 = deC32; | ||
| /** Decodable Crockford base32. */ | ||
| exports.C32 = /^[-\dA-TV-Za-tv-z]*$/; |
| /** | ||
| * [Base32hex](https://www.rfc-editor.org/rfc/rfc4648#section-7) uses digits | ||
| * and uppercase letters, excluding "W-Z". Encoding is always uppercase, and | ||
| * decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enH32(binary), "91IMOR3F40T2I"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deH32("91IMOR3F40T2I"), binary); | ||
| * ``` | ||
| * | ||
| * @module h32 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base32hex. */ | ||
| export declare const enH32: Encode; | ||
| /** Converts base32hex to binary. */ | ||
| export declare const deH32: Decode; | ||
| /** Decodable base32hex. */ | ||
| export declare const H32: RegExp; |
| "use strict"; | ||
| /** | ||
| * [Base32hex](https://www.rfc-editor.org/rfc/rfc4648#section-7) uses digits | ||
| * and uppercase letters, excluding "W-Z". Encoding is always uppercase, and | ||
| * decoding is case-insensitive. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enH32(binary), "91IMOR3F40T2I"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deH32("91IMOR3F40T2I"), binary); | ||
| * ``` | ||
| * | ||
| * @module h32 | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.H32 = exports.deH32 = exports.enH32 = void 0; | ||
| const lib_js_1 = require("./lib.js"); | ||
| const H32_STR = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; | ||
| /** Converts binary to base32hex. */ | ||
| exports.enH32 = lib_js_1.en32.bind(null, H32_STR); | ||
| /** Converts base32hex to binary. */ | ||
| exports.deH32 = lib_js_1.de32.bind(null, /* @__PURE__ */ (0, lib_js_1.map)(H32_STR, 32)); | ||
| /** Decodable base32hex. */ | ||
| exports.H32 = /^[\dA-Va-v]*$/; |
| /** Binary-to-string function. */ | ||
| export type Encode = (binary: Uint8Array) => string; | ||
| /** String-to-binary function. */ | ||
| export type Decode = (string: string) => Uint8Array<ArrayBuffer>; | ||
| /** Creates a code-to-byte map. */ | ||
| export declare const map: ($: string, or?: number) => Uint8Array<ArrayBuffer>; | ||
| /** Converts binary to a radix-32 string. */ | ||
| export declare const en32: (str: string, $: Uint8Array) => string; | ||
| /** Converts a radix-32 string to binary. */ | ||
| export declare const de32: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; | ||
| /** Converts a radix-64 string to binary. */ | ||
| export declare const de64: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; | ||
| /** Converts binary to a radix-85 string. */ | ||
| export declare const en85: (str: string, $: Uint8Array) => string; | ||
| /** Converts a radix-85 string to binary. */ | ||
| export declare const de85: (bin: Uint8Array, $: string) => Uint8Array<ArrayBuffer>; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.de85 = exports.en85 = exports.de64 = exports.de32 = exports.en32 = exports.map = void 0; | ||
| const utf_js_1 = require("./utf.js"); | ||
| /** Creates a code-to-byte map. */ | ||
| const map = ($, or) => { | ||
| const bin = new Uint8Array(256); | ||
| for (let z = 0; z < $.length; ++z) { | ||
| bin[utf_js_1.en.call($, z)] = z; | ||
| if (or) | ||
| bin[utf_js_1.en.call($, z) | or] = z; | ||
| } | ||
| return bin; | ||
| }; | ||
| exports.map = map; | ||
| /** Converts binary to a radix-32 string. */ | ||
| const en32 = (str, $) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 5) { | ||
| const a = $[z], b = $[z + 1], c = $[z + 2], d = $[z + 3], e = $[z + 4]; | ||
| string += str[a >> 3] + str[a << 2 & 28 | b >> 6] + str[b >> 1 & 31] + | ||
| str[b << 4 & 16 | c >> 4] + str[c << 1 & 30 | d >> 7] + str[d >> 2 & 31] + | ||
| str[d << 3 & 24 | e >> 5] + str[e & 31]; | ||
| } | ||
| return string.slice(0, Math.ceil($.length / 5 * 8)); | ||
| }; | ||
| exports.en32 = en32; | ||
| /** Converts a radix-32 string to binary. */ | ||
| const de32 = (bin, $) => { | ||
| const binary = new Uint8Array($.length * 5 >> 3); | ||
| for (let z = 0, y = 0; z < $.length; z += 8, y += 5) { | ||
| const a = bin[utf_js_1.en.call($, z + 1)], b = bin[utf_js_1.en.call($, z + 3)]; | ||
| const c = bin[utf_js_1.en.call($, z + 4)], d = bin[utf_js_1.en.call($, z + 6)]; | ||
| binary[y] = bin[utf_js_1.en.call($, z)] << 3 | a >> 2 & 7; | ||
| binary[y + 1] = a << 6 & 192 | bin[utf_js_1.en.call($, z + 2)] << 1 | b >> 4 & 1; | ||
| binary[y + 2] = b << 4 & 240 | c >> 1 & 15; | ||
| binary[y + 3] = c << 7 & 128 | bin[utf_js_1.en.call($, z + 5)] << 2 | d >> 3 & 7; | ||
| binary[y + 4] = d << 5 & 224 | bin[utf_js_1.en.call($, z + 7)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| exports.de32 = de32; | ||
| /** Converts a radix-64 string to binary. */ | ||
| const de64 = (bin, $) => { | ||
| const binary = new Uint8Array($.length * 3 >> 2); | ||
| for (let z = 0, y = 0; z < $.length; z += 4, y += 3) { | ||
| const a = bin[utf_js_1.en.call($, z + 1)], b = bin[utf_js_1.en.call($, z + 2)]; | ||
| binary[y] = bin[utf_js_1.en.call($, z)] << 2 | a >> 4; | ||
| binary[y + 1] = a << 4 | b >> 2; | ||
| binary[y + 2] = b << 6 | bin[utf_js_1.en.call($, z + 3)]; | ||
| } | ||
| return binary; | ||
| }; | ||
| exports.de64 = de64; | ||
| var Step; | ||
| (function (Step) { | ||
| Step[Step["A"] = 52200625] = "A"; | ||
| Step[Step["B"] = 614125] = "B"; | ||
| Step[Step["C"] = 7225] = "C"; | ||
| Step[Step["D"] = 85] = "D"; | ||
| })(Step || (Step = {})); | ||
| /** Converts binary to a radix-85 string. */ | ||
| const en85 = (str, $) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 4) { | ||
| const a = ($[z] << 24 | $[z + 1] << 16 | $[z + 2] << 8 | $[z + 3]) >>> 0; | ||
| string += str[a / Step.A % 85 | 0] + str[a / Step.B % 85 | 0] + | ||
| str[a / Step.C % 85 | 0] + str[a / Step.D % 85 | 0] + str[a % 85]; | ||
| } | ||
| return string; | ||
| }; | ||
| exports.en85 = en85; | ||
| /** Converts a radix-85 string to binary. */ | ||
| const de85 = (bin, $) => { | ||
| const binary = new Uint8Array(Math.ceil($.length / 5 * 4)); | ||
| for (let z = 0, y = 0; z < $.length; z += 5, y += 4) { | ||
| const a = binary[y + 3] = bin[utf_js_1.en.call($, z)] * Step.A + | ||
| bin[utf_js_1.en.call($, z + 1)] * Step.B + bin[utf_js_1.en.call($, z + 2)] * Step.C + | ||
| bin[utf_js_1.en.call($, z + 3)] * Step.D + bin[utf_js_1.en.call($, z + 4)]; | ||
| binary[y] = a >> 24, binary[y + 1] = a >> 16, binary[y + 2] = a >> 8; | ||
| } | ||
| return binary; | ||
| }; | ||
| exports.de85 = de85; |
| /** | ||
| * [Base64url](https://www.rfc-editor.org/rfc/rfc4648#section-5) uses | ||
| * alphanumeric characters and "-" and "_". Padding is neither encoded nor | ||
| * decoded. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals, assertMatch } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enU64(binary), "SGVsbG8gOik"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deU64("SGVsbG8gOik"), binary); | ||
| * ``` | ||
| * | ||
| * @module u64 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to base64url. */ | ||
| export declare const enU64: Encode; | ||
| /** Converts base64url to binary. */ | ||
| export declare const deU64: Decode; | ||
| /** Decodable base64url. */ | ||
| export declare const U64: RegExp; |
| "use strict"; | ||
| /** | ||
| * [Base64url](https://www.rfc-editor.org/rfc/rfc4648#section-5) uses | ||
| * alphanumeric characters and "-" and "_". Padding is neither encoded nor | ||
| * decoded. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals, assertMatch } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enU64(binary), "SGVsbG8gOik"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deU64("SGVsbG8gOik"), binary); | ||
| * ``` | ||
| * | ||
| * @module u64 | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.U64 = exports.deU64 = exports.enU64 = void 0; | ||
| const lib_js_1 = require("./lib.js"); | ||
| const U64_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; | ||
| /** Converts binary to base64url. */ | ||
| const enU64 = ($) => { | ||
| let string = ""; | ||
| for (let z = 0; z < $.length; z += 3) { | ||
| const a = $[z], b = $[z + 1], c = $[z + 2]; | ||
| string += U64_STR[a >> 2] + U64_STR[a << 4 & 48 | b >> 4] + | ||
| U64_STR[b << 2 & 60 | c >> 6] + U64_STR[c & 63]; | ||
| } | ||
| return string.slice(0, Math.ceil($.length / 3 * 4)); | ||
| }; | ||
| exports.enU64 = enU64; | ||
| /** Converts base64url to binary. */ | ||
| exports.deU64 = lib_js_1.de64.bind(null, /* @__PURE__ */ (0, lib_js_1.map)(U64_STR)); | ||
| /** Decodable base64url. */ | ||
| exports.U64 = /^(?:[-\w]{4})*(?:[-\w]{2,3})?$/; |
| /** | ||
| * Aliases for built-in UTF-8 and UTF-16 APIs. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * assertEquals(enUtf8("Hello :)"), binary); | ||
| * assertEquals(deUtf8(binary), "Hello :)"); | ||
| * | ||
| * assertEquals(en.call("Hello :)"), 72); | ||
| * assertEquals(en.call("Hello :)", 1), 101); | ||
| * assertEquals(de(...binary), "Hello :)"); | ||
| * ``` | ||
| * | ||
| * @module utf8 | ||
| */ | ||
| /** Character code getter. */ | ||
| export declare const en: (this: string, index?: number) => number; | ||
| /** Character code setter. */ | ||
| export declare const de: (...codes: number[]) => string; | ||
| /** Converts UTF-8 to binary. */ | ||
| export declare const enUtf8: ($?: string) => Uint8Array<ArrayBuffer>; | ||
| /** Converts binary to UTF-8. */ | ||
| export declare const deUtf8: ($?: AllowSharedBufferSource, options?: TextDecodeOptions) => string; |
| "use strict"; | ||
| /** | ||
| * Aliases for built-in UTF-8 and UTF-16 APIs. | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * assertEquals(enUtf8("Hello :)"), binary); | ||
| * assertEquals(deUtf8(binary), "Hello :)"); | ||
| * | ||
| * assertEquals(en.call("Hello :)"), 72); | ||
| * assertEquals(en.call("Hello :)", 1), 101); | ||
| * assertEquals(de(...binary), "Hello :)"); | ||
| * ``` | ||
| * | ||
| * @module utf8 | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.deUtf8 = exports.enUtf8 = exports.de = exports.en = void 0; | ||
| /** Character code getter. */ | ||
| exports.en = | ||
| /* @__PURE__ */ (() => String.prototype.charCodeAt)(); | ||
| /** Character code setter. */ | ||
| exports.de = | ||
| /* @__PURE__ */ (() => String.fromCharCode)(); | ||
| /** Converts UTF-8 to binary. */ | ||
| exports.enUtf8 = | ||
| /* @__PURE__ */ TextEncoder.prototype.encode.bind( | ||
| /* @__PURE__ */ new TextEncoder()); | ||
| /** Converts binary to UTF-8. */ | ||
| exports.deUtf8 = TextDecoder.prototype.decode.bind( | ||
| /* @__PURE__ */ new TextDecoder("utf-8")); |
| /** | ||
| * [Z85](https://rfc.zeromq.org/spec/32) uses printable, non-whitespace ASCII | ||
| * characters, excluding '"', "'", ",", ";", "\", "_", "`", "|", and "~". | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals, assertMatch } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enZ85(binary), "nm=QNzY?7&"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deZ85("nm=QNzY?7&"), binary); | ||
| * ``` | ||
| * | ||
| * @module z85 | ||
| */ | ||
| import { type Decode, type Encode } from "./lib.js"; | ||
| /** Converts binary to Z85. */ | ||
| export declare const enZ85: Encode; | ||
| /** Converts Z85 to binary. */ | ||
| export declare const deZ85: Decode; | ||
| /** Decodable Z85. */ | ||
| export declare const Z85: RegExp; |
| "use strict"; | ||
| /** | ||
| * [Z85](https://rfc.zeromq.org/spec/32) uses printable, non-whitespace ASCII | ||
| * characters, excluding '"', "'", ",", ";", "\", "_", "`", "|", and "~". | ||
| * | ||
| * @example Usage | ||
| * ```ts | ||
| * import { assertEquals, assertMatch } from "@std/assert"; | ||
| * | ||
| * const binary = new TextEncoder().encode("Hello :)"); | ||
| * | ||
| * // Encode! | ||
| * assertEquals(enZ85(binary), "nm=QNzY?7&"); | ||
| * | ||
| * // Decode! | ||
| * assertEquals(deZ85("nm=QNzY?7&"), binary); | ||
| * ``` | ||
| * | ||
| * @module z85 | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Z85 = exports.deZ85 = exports.enZ85 = void 0; | ||
| const lib_js_1 = require("./lib.js"); | ||
| const Z85_STR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"; | ||
| /** Converts binary to Z85. */ | ||
| exports.enZ85 = lib_js_1.en85.bind(null, Z85_STR); | ||
| /** Converts Z85 to binary. */ | ||
| exports.deZ85 = lib_js_1.de85.bind(null, /* @__PURE__ */ (0, lib_js_1.map)(Z85_STR)); | ||
| /** Decodable Z85. */ | ||
| exports.Z85 = /^[!#-&(-+--:<-[\]^a-{}]*$/; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
145
625%35758
-31.18%4
Infinity%782
-48.45%1
Infinity%