@bouko/ts 0.1.8 → 0.1.9
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/types/generic.d.ts +1 -1
- package/dist/utils/formatters.d.ts +1 -0
- package/dist/utils/formatters.js +5 -0
- package/dist/utils/parsers.d.ts +2 -0
- package/dist/utils/parsers.js +12 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { JsonMap, JsonValue } from "./types/generic";
|
|
2
2
|
export * from "./types/generic";
|
|
3
3
|
export * from "./utils/checkers";
|
|
4
|
+
export * from "./utils/formatters";
|
|
4
5
|
export * from "./utils/parsers";
|
|
5
6
|
export declare const safely: <T>(action: () => T) => T | undefined;
|
|
6
7
|
export declare const safelyThru: <T>(arr: T[], action: (item: T) => void) => void;
|
package/dist/index.js
CHANGED
package/dist/types/generic.d.ts
CHANGED
|
@@ -12,4 +12,4 @@ export type StringMap = Record<string, string>;
|
|
|
12
12
|
export type JsonMap = {
|
|
13
13
|
[key: string]: JsonValue | JsonValue[];
|
|
14
14
|
};
|
|
15
|
-
export type JsonValue = string | number | boolean | null | undefined | JsonMap;
|
|
15
|
+
export type JsonValue = string | string[] | number | number[] | boolean | boolean[] | null | null[] | undefined | undefined[] | JsonMap | JsonMap[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const shortenStr: (str: string) => string;
|
package/dist/utils/parsers.d.ts
CHANGED
package/dist/utils/parsers.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
import { isNum, isBool } from "./checkers";
|
|
2
|
+
export const parseStr = (input) => {
|
|
3
|
+
if (isNum(input))
|
|
4
|
+
return parseNum(input);
|
|
5
|
+
else if (isBool(input))
|
|
6
|
+
return parseBool(input);
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(input);
|
|
9
|
+
}
|
|
10
|
+
catch { }
|
|
11
|
+
return input.trim();
|
|
12
|
+
};
|
|
1
13
|
export const parseNum = (input) => {
|
|
2
14
|
const num = Number(input.trim());
|
|
3
15
|
if (!isNaN(num))
|