@bouko/ts 0.3.3 → 0.3.4

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.
@@ -1,4 +1,4 @@
1
- export declare function bufferToBase64(uint8: Uint8Array): string;
1
+ export declare function bufferToData(uint8: Uint8Array, mimetype?: string): string;
2
2
  export declare function base64ToBuffer(base64: string): Uint8Array;
3
3
  export declare function base64ToFile(data: string, opts?: {
4
4
  name?: string;
@@ -1,10 +1,12 @@
1
- export function bufferToBase64(uint8) {
2
- let binary = "";
1
+ export function bufferToData(uint8, mimetype) {
3
2
  const len = uint8.byteLength;
4
- for (let i = 0; i < len; i++) {
3
+ let binary = "";
4
+ for (let i = 0; i < len; i++)
5
5
  binary += String.fromCharCode(uint8[i]);
6
- }
7
- return btoa(binary);
6
+ const decoded = btoa(binary);
7
+ if (mimetype)
8
+ return `data:${mimetype};base64,${decoded}`;
9
+ return decoded;
8
10
  }
9
11
  export function base64ToBuffer(base64) {
10
12
  const binaryString = atob(base64); // decode base64 into binary string
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  "name": "@bouko/ts",
4
4
 
5
- "version": "0.3.3",
5
+ "version": "0.3.4",
6
6
 
7
7
  "main": "./dist/index.js",
8
8