@bouko/ts 0.2.5 → 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 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
@@ -5,6 +5,7 @@ export * from "./utils/checkers";
5
5
  export * from "./utils/env";
6
6
  export * from "./utils/formatters";
7
7
  export * from "./utils/parsers";
8
+ export * from "./utils/converters";
8
9
  export const safely = (action) => {
9
10
  try {
10
11
  return action();
@@ -12,4 +12,4 @@ export declare type StringMap = Record<string, string>;
12
12
  export declare type JsonMap = {
13
13
  [key: string]: JsonValue | JsonValue[];
14
14
  };
15
- export declare type JsonValue = string | string[] | number | number[] | boolean | boolean[] | null | null[] | undefined | undefined[] | JsonMap | JsonMap[];
15
+ export declare type JsonValue = string | number | boolean | null | undefined | JsonMap | JsonValue[];
@@ -0,0 +1,2 @@
1
+ export declare function bufferToBase64(uint8: Uint8Array): string;
2
+ export declare function base64ToBuffer(base64: string): Uint8Array;
@@ -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
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/ts",
4
- "version": "0.2.5",
4
+ "version": "0.2.7",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",