UNPKG

3.96 kBTypeScriptView Raw
1/**
2 * base64.ts
3 *
4 * Licensed under the BSD 3-Clause License.
5 * http://opensource.org/licenses/BSD-3-Clause
6 *
7 * References:
8 * http://en.wikipedia.org/wiki/Base64
9 *
10 * @author Dan Kogai (https://github.com/dankogai)
11 */
12declare const version = "3.7.2";
13/**
14 * @deprecated use lowercase `version`.
15 */
16declare const VERSION = "3.7.2";
17/**
18 * polyfill version of `btoa`
19 */
20declare const btoaPolyfill: (bin: string) => string;
21/**
22 * does what `window.btoa` of web browsers do.
23 * @param {String} bin binary string
24 * @returns {string} Base64-encoded string
25 */
26declare const _btoa: (bin: string) => string;
27/**
28 * converts a Uint8Array to a Base64 string.
29 * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
30 * @returns {string} Base64 string
31 */
32declare const fromUint8Array: (u8a: Uint8Array, urlsafe?: boolean) => string;
33/**
34 * @deprecated should have been internal use only.
35 * @param {string} src UTF-8 string
36 * @returns {string} UTF-16 string
37 */
38declare const utob: (u: string) => string;
39/**
40 * converts a UTF-8-encoded string to a Base64 string.
41 * @param {boolean} [urlsafe] if `true` make the result URL-safe
42 * @returns {string} Base64 string
43 */
44declare const encode: (src: string, urlsafe?: boolean) => string;
45/**
46 * converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5.
47 * @returns {string} Base64 string
48 */
49declare const encodeURI: (src: string) => string;
50/**
51 * @deprecated should have been internal use only.
52 * @param {string} src UTF-16 string
53 * @returns {string} UTF-8 string
54 */
55declare const btou: (b: string) => string;
56/**
57 * polyfill version of `atob`
58 */
59declare const atobPolyfill: (asc: string) => string;
60/**
61 * does what `window.atob` of web browsers do.
62 * @param {String} asc Base64-encoded string
63 * @returns {string} binary string
64 */
65declare const _atob: (asc: string) => string;
66/**
67 * converts a Base64 string to a Uint8Array.
68 */
69declare const toUint8Array: (a: string) => Uint8Array;
70/**
71 * converts a Base64 string to a UTF-8 string.
72 * @param {String} src Base64 string. Both normal and URL-safe are supported
73 * @returns {string} UTF-8 string
74 */
75declare const decode: (src: string) => string;
76/**
77 * check if a value is a valid Base64 string
78 * @param {String} src a value to check
79 */
80declare const isValid: (src: any) => boolean;
81/**
82 * extend String.prototype with relevant methods
83 */
84declare const extendString: () => void;
85/**
86 * extend Uint8Array.prototype with relevant methods
87 */
88declare const extendUint8Array: () => void;
89/**
90 * extend Builtin prototypes with relevant methods
91 */
92declare const extendBuiltins: () => void;
93declare const gBase64: {
94 version: string;
95 VERSION: string;
96 atob: (asc: string) => string;
97 atobPolyfill: (asc: string) => string;
98 btoa: (bin: string) => string;
99 btoaPolyfill: (bin: string) => string;
100 fromBase64: (src: string) => string;
101 toBase64: (src: string, urlsafe?: boolean) => string;
102 encode: (src: string, urlsafe?: boolean) => string;
103 encodeURI: (src: string) => string;
104 encodeURL: (src: string) => string;
105 utob: (u: string) => string;
106 btou: (b: string) => string;
107 decode: (src: string) => string;
108 isValid: (src: any) => boolean;
109 fromUint8Array: (u8a: Uint8Array, urlsafe?: boolean) => string;
110 toUint8Array: (a: string) => Uint8Array;
111 extendString: () => void;
112 extendUint8Array: () => void;
113 extendBuiltins: () => void;
114};
115export { version };
116export { VERSION };
117export { _atob as atob };
118export { atobPolyfill };
119export { _btoa as btoa };
120export { btoaPolyfill };
121export { decode as fromBase64 };
122export { encode as toBase64 };
123export { utob };
124export { encode };
125export { encodeURI };
126export { encodeURI as encodeURL };
127export { btou };
128export { decode };
129export { isValid };
130export { fromUint8Array };
131export { toUint8Array };
132export { extendString };
133export { extendUint8Array };
134export { extendBuiltins };
135export { gBase64 as Base64 };