UNPKG

1.14 kBJavaScriptView Raw
1import { base64 } from '@scure/base';
2import { createDecode, createEncode, createIs, createValidate } from '../base32/helpers.js';
3const config = {
4 chars: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
5 coder: base64,
6 type: 'base64',
7 withPadding: true
8};
9/**
10 * @name base64Validate
11 * @summary Validates a base64 value.
12 * @description
13 * Validates that the supplied value is valid base64
14 */
15export const base64Validate = /*#__PURE__*/ createValidate(config);
16/**
17 * @name isBase64
18 * @description Checks if the input is in base64, returning true/false
19 */
20export const isBase64 = /*#__PURE__*/ createIs(base64Validate);
21/**
22 * @name base64Decode
23 * @summary Decodes a base64 value.
24 * @description
25 * From the provided input, decode the base64 and return the result as an `Uint8Array`.
26 */
27export const base64Decode = /*#__PURE__*/ createDecode(config, base64Validate);
28/**
29 * @name base64Encode
30 * @summary Creates a base64 value.
31 * @description
32 * From the provided input, create the base64 and return the result as a string.
33 */
34export const base64Encode = /*#__PURE__*/ createEncode(config);