1- import type {
2- Type_bytesToBase64 ,
3- Type_base64ToBytes ,
4- Type_encode ,
5- Type_decode ,
6- Type_decodeToString ,
7- } from '../type.d.ts'
8-
91import {
2+ type bytesToBase64Func ,
3+ type encodeFunc ,
4+ type decodeFunc ,
5+ type decodeToStringFunc ,
106 make_bytesToBase64 ,
11- make_base64ToBytes ,
12- make_base64ToBytes_NodeJS ,
13- make_encode ,
147 make_decode ,
8+ make_encode ,
159 make_decodeToString ,
1610} from './make.js'
1711
@@ -23,14 +17,15 @@ export const alphabeturl = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
2317 * A boolean specifying whether to omit padding characters (=) at the end of the base64 string.
2418 * The default is false.
2519 */
26- export const _bytesToBase64 : Type_bytesToBase64 = /*@__PURE__ */ (
27- typeof Uint8Array . prototype . toBase64 == 'function' // Node.js v25
20+ export const _bytesToBase64 : bytesToBase64Func = /*@__PURE__ */ (
21+ typeof Uint8Array . prototype . toBase64 == 'function' // ES2026, Node.js v25
2822 ? ( bytes , omitPadding ) => Uint8Array . prototype . toBase64 . call ( bytes , { omitPadding } )
2923 : typeof Buffer == 'function' && Buffer . prototype && typeof Buffer . prototype . base64Slice == 'function'
3024 ? ( bytes , omitPadding ) => {
3125 const out = Buffer . prototype . base64Slice . call ( bytes ) as string // has padding
3226 return omitPadding && out . charCodeAt ( out . length - 1 ) === 61
33- ? out . slice ( 0 , - 1 - ( ( out . charCodeAt ( out . length - 2 ) === 61 ) as any ) )
27+ //@ts -ignore
28+ ? out . slice ( 0 , - 1 - ( out . charCodeAt ( out . length - 2 ) === 61 ) )
3429 : out
3530 }
3631 : make_bytesToBase64 ( alphabet )
@@ -41,8 +36,8 @@ export const _bytesToBase64: Type_bytesToBase64 = /*@__PURE__*/ (
4136 * A boolean specifying whether to omit padding characters (=) at the end of the base64 string.
4237 * The default is false.
4338 */
44- export const _bytesToBase64url : Type_bytesToBase64 = /*@__PURE__ */ (
45- typeof Uint8Array . prototype . toBase64 == 'function' // Node.js v25
39+ export const _bytesToBase64url : bytesToBase64Func = /*@__PURE__ */ (
40+ typeof Uint8Array . prototype . toBase64 == 'function' // ES2026, Node.js v25
4641 ? ( bytes , omitPadding ) => Uint8Array . prototype . toBase64 . call ( bytes , { alphabet : 'base64url' , omitPadding } )
4742 : typeof Buffer == 'function' && Buffer . prototype && typeof Buffer . prototype . base64urlSlice == 'function'
4843 ? ( bytes , omitPadding ) => {
@@ -57,22 +52,6 @@ export const _bytesToBase64url: Type_bytesToBase64 = /*@__PURE__*/ (
5752 : make_bytesToBase64 ( alphabeturl )
5853)
5954
60- export const _base64ToBytes : Type_base64ToBytes = /*@__PURE__ */ (
61- typeof Uint8Array . fromBase64 == 'function' // Node.js v25
62- ? base64 => Uint8Array . fromBase64 ( base64 )
63- : typeof Buffer == 'function' && Buffer . prototype && typeof Buffer . prototype . base64Write == 'function'
64- ? make_base64ToBytes_NodeJS ( Buffer . prototype . base64Write )
65- : make_base64ToBytes ( alphabet )
66- )
67-
68- export const _base64urlToBytes : Type_base64ToBytes = /*@__PURE__ */ (
69- typeof Uint8Array . fromBase64 == 'function' // Node.js v25
70- ? base64 => Uint8Array . fromBase64 ( base64 , { alphabet : 'base64url' } )
71- : typeof Buffer == 'function' && Buffer . prototype && typeof Buffer . prototype . base64urlWrite == 'function'
72- ? make_base64ToBytes_NodeJS ( Buffer . prototype . base64urlWrite )
73- : make_base64ToBytes ( alphabeturl )
74- )
75-
7655/**
7756 * @param omitPadding
7857 * A boolean specifying whether to omit padding characters (=) at the end of the base64 string.
@@ -87,8 +66,17 @@ export const encode = /*@__PURE__*/ make_encode(_bytesToBase64)
8766 */
8867export const encodeurl = /*@__PURE__ */ make_encode ( _bytesToBase64url )
8968
90- export const decode = /*@__PURE__ */ make_decode ( _base64ToBytes )
91- export const decodeurl = /*@__PURE__ */ make_decode ( _base64urlToBytes )
69+ export const decode : decodeFunc = /*@__PURE__ */ (
70+ typeof Uint8Array . fromBase64 == 'function' // ES2026, Node.js v25
71+ ? base64 => Uint8Array . fromBase64 ( base64 )
72+ : make_decode ( alphabet )
73+ )
74+
75+ export const decodeurl : decodeFunc = /*@__PURE__ */ (
76+ typeof Uint8Array . fromBase64 == 'function' // ES2026, Node.js v25
77+ ? base64 => Uint8Array . fromBase64 ( base64 , { alphabet : 'base64url' } )
78+ : make_decode ( alphabeturl )
79+ )
9280
9381export const decodeToString = /*@__PURE__ */ make_decodeToString ( decode )
9482export const decodeurlToString = /*@__PURE__ */ make_decodeToString ( decodeurl )
@@ -98,8 +86,6 @@ const base64 = {
9886 alphabeturl : alphabeturl as typeof alphabeturl ,
9987 _bytesToBase64,
10088 _bytesToBase64url,
101- _base64ToBytes,
102- _base64urlToBytes,
10389 encode,
10490 encodeurl,
10591 decode,
0 commit comments