@bouko/ts 0.2.6 → 0.2.7
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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utils/converters.d.ts +2 -0
- package/dist/utils/converters.js +17 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./utils/checkers";
|
|
|
6
6
|
export * from "./utils/env";
|
|
7
7
|
export * from "./utils/formatters";
|
|
8
8
|
export * from "./utils/parsers";
|
|
9
|
+
export * from "./utils/converters";
|
|
9
10
|
export declare const safely: <T>(action: () => T) => T | undefined;
|
|
10
11
|
export declare const safelyThru: <T>(arr: T[], action: (item: T) => void) => void;
|
|
11
12
|
export declare const isJsonMap: (value: unknown) => value is JsonMap;
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function bufferToBase64(uint8) {
|
|
2
|
+
let binary = "";
|
|
3
|
+
const len = uint8.byteLength;
|
|
4
|
+
for (let i = 0; i < len; i++) {
|
|
5
|
+
binary += String.fromCharCode(uint8[i]);
|
|
6
|
+
}
|
|
7
|
+
return btoa(binary);
|
|
8
|
+
}
|
|
9
|
+
export function base64ToBuffer(base64) {
|
|
10
|
+
const binaryString = atob(base64); // decode base64 into binary string
|
|
11
|
+
const len = binaryString.length;
|
|
12
|
+
const bytes = new Uint8Array(len);
|
|
13
|
+
for (let i = 0; i < len; i++) {
|
|
14
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
15
|
+
}
|
|
16
|
+
return bytes;
|
|
17
|
+
}
|