@eottabom/base64 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ export declare function encodeBase64(input: string): string;
2
+ export declare function decodeBase64(input: string): string;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA+BA,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWlD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQlD"}
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ const textEncoder = new TextEncoder();
2
+ const textDecoder = new TextDecoder();
3
+ function hasBuffer() {
4
+ return typeof Buffer !== "undefined";
5
+ }
6
+ function encodeBinaryToBase64(binary) {
7
+ if (typeof btoa === "function") {
8
+ return btoa(binary);
9
+ }
10
+ if (hasBuffer()) {
11
+ return Buffer.from(binary, "binary").toString("base64");
12
+ }
13
+ throw new Error("Base64 encoding is not supported in this runtime.");
14
+ }
15
+ function decodeBase64ToBinary(input) {
16
+ if (typeof atob === "function") {
17
+ return atob(input);
18
+ }
19
+ if (hasBuffer()) {
20
+ return Buffer.from(input, "base64").toString("binary");
21
+ }
22
+ throw new Error("Base64 decoding is not supported in this runtime.");
23
+ }
24
+ export function encodeBase64(input) {
25
+ if (hasBuffer()) {
26
+ return Buffer.from(input, "utf8").toString("base64");
27
+ }
28
+ const bytes = textEncoder.encode(input);
29
+ let binary = "";
30
+ bytes.forEach((byte) => {
31
+ binary += String.fromCharCode(byte);
32
+ });
33
+ return encodeBinaryToBase64(binary);
34
+ }
35
+ export function decodeBase64(input) {
36
+ if (hasBuffer()) {
37
+ return Buffer.from(input, "base64").toString("utf8");
38
+ }
39
+ const binary = decodeBase64ToBinary(input);
40
+ const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
41
+ return textDecoder.decode(bytes);
42
+ }
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AACtC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC,SAAS,SAAS;IACd,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC;AACzC,CAAC;AAED,SAAS,oBAAoB,CAAC,MAAc;IACxC,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,SAAS,EAAE,EAAE,CAAC;QACd,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAa;IACvC,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,SAAS,EAAE,EAAE,CAAC;QACd,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAa;IACtC,IAAI,SAAS,EAAE,EAAE,CAAC;QACd,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACxC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnB,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;IACH,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAa;IACtC,IAAI,SAAS,EAAE,EAAE,CAAC;QACd,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,MAAM,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACpE,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@eottabom/base64",
3
+ "version": "0.1.1",
4
+ "description": "UTF-8 safe Base64 encoding and decoding utilities.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc -p tsconfig.build.json"
20
+ },
21
+ "keywords": [
22
+ "base64",
23
+ "encoding",
24
+ "utf8"
25
+ ],
26
+ "license": "MIT"
27
+ }