UNPKG

1.33 kBJavaScriptView Raw
1import { utils } from '@scure/base';
2import { createDecode, createEncode, createIs, createValidate } from './helpers.js';
3const chars = 'abcdefghijklmnopqrstuvwxyz234567';
4const config = {
5 chars,
6 coder: utils.chain(
7 // We define our own chain, the default base32 has padding
8 utils.radix2(5), utils.alphabet(chars), {
9 decode: (input) => input.split(''),
10 encode: (input) => input.join('')
11 }),
12 ipfs: 'b',
13 type: 'base32'
14};
15/**
16 * @name base32Validate
17 * @summary Validates a base32 value.
18 * @description
19 * Validates that the supplied value is valid base32, throwing exceptions if not
20 */
21export const base32Validate = /*#__PURE__*/ createValidate(config);
22/**
23* @name isBase32
24* @description Checks if the input is in base32, returning true/false
25*/
26export const isBase32 = /*#__PURE__*/ createIs(base32Validate);
27/**
28 * @name base32Decode
29 * @summary Delookup a base32 value.
30 * @description
31 * From the provided input, decode the base32 and return the result as an `Uint8Array`.
32 */
33export const base32Decode = /*#__PURE__*/ createDecode(config, base32Validate);
34/**
35* @name base32Encode
36* @summary Creates a base32 value.
37* @description
38* From the provided input, create the base32 and return the result as a string.
39*/
40export const base32Encode = /*#__PURE__*/ createEncode(config);