@bouko/ts 0.1.7 → 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 +3 -1
- package/dist/index.js +4 -3
- package/dist/types/generic.d.ts +1 -1
- package/dist/types.d.ts +15 -0
- package/dist/types.js +12 -0
- package/dist/utils/formatters.d.ts +1 -0
- package/dist/utils/formatters.js +5 -0
- package/dist/{core/parse.d.ts → utils/parsers.d.ts} +2 -0
- package/dist/{core/parse.js → utils/parsers.js} +12 -0
- package/package.json +1 -1
- package/dist/core/env.d.ts +0 -11
- package/dist/core/env.js +0 -24
- package/dist/types/env.d.ts +0 -1
- package/dist/types/env.js +0 -1
- /package/dist/{core/types.d.ts → utils/checkers.d.ts} +0 -0
- /package/dist/{core/types.js → utils/checkers.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { JsonMap, JsonValue } from "./types/generic";
|
|
2
2
|
export * from "./types/generic";
|
|
3
|
-
export * from "./
|
|
3
|
+
export * from "./utils/checkers";
|
|
4
|
+
export * from "./utils/formatters";
|
|
5
|
+
export * from "./utils/parsers";
|
|
4
6
|
export declare const safely: <T>(action: () => T) => T | undefined;
|
|
5
7
|
export declare const safelyThru: <T>(arr: T[], action: (item: T) => void) => void;
|
|
6
8
|
export declare const isJsonMap: (value: unknown) => value is JsonMap;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from "./types/generic";
|
|
2
|
-
export * from "./
|
|
2
|
+
export * from "./utils/checkers";
|
|
3
|
+
export * from "./utils/formatters";
|
|
4
|
+
export * from "./utils/parsers";
|
|
3
5
|
export const safely = (action) => {
|
|
4
6
|
try {
|
|
5
7
|
return action();
|
|
@@ -12,8 +14,7 @@ export const safelyThru = (arr, action) => {
|
|
|
12
14
|
try {
|
|
13
15
|
arr.forEach(action);
|
|
14
16
|
}
|
|
15
|
-
catch
|
|
16
|
-
console.error("Error in safelyForEach:", err);
|
|
17
|
+
catch {
|
|
17
18
|
}
|
|
18
19
|
};
|
|
19
20
|
export const isJsonMap = (value) => {
|
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[];
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for common data structures.
|
|
3
|
+
*
|
|
4
|
+
* - `StringMap`: Map of string keys to string values.
|
|
5
|
+
* - `JsonMap`: Object of primitives, arrays, or nested maps.
|
|
6
|
+
* - `JsonValue`: Union type representing a valid JSON value.
|
|
7
|
+
*
|
|
8
|
+
* They are intended to facilitate type-safe handling
|
|
9
|
+
* of generic objects (ex. forms)
|
|
10
|
+
**/
|
|
11
|
+
export type StringMap = Record<string, string>;
|
|
12
|
+
export type JsonMap = {
|
|
13
|
+
[key: string]: JsonValue | JsonValue[];
|
|
14
|
+
};
|
|
15
|
+
export type JsonValue = string | number | boolean | null | undefined | JsonMap;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for common data structures.
|
|
3
|
+
*
|
|
4
|
+
* - `StringMap`: Map of string keys to string values.
|
|
5
|
+
* - `JsonMap`: Object of primitives, arrays, or nested maps.
|
|
6
|
+
* - `JsonValue`: Union type representing a valid JSON value.
|
|
7
|
+
*
|
|
8
|
+
* They are intended to facilitate type-safe handling
|
|
9
|
+
* of generic objects (ex. forms)
|
|
10
|
+
**/
|
|
11
|
+
export {};
|
|
12
|
+
// clean
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const shortenStr: (str: string) => string;
|
|
@@ -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))
|
package/package.json
CHANGED
package/dist/core/env.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { EnvValue } from "../types/env";
|
|
2
|
-
export declare function getEnv<T extends EnvValue = string>(key: string, fallback?: T): T;
|
|
3
|
-
/**
|
|
4
|
-
* Problems:
|
|
5
|
-
*
|
|
6
|
-
* - Perfect `EnvValue`
|
|
7
|
-
* - Perfect `isNum`
|
|
8
|
-
* - Perfect `isBool`
|
|
9
|
-
* - Perfect `parseNum`
|
|
10
|
-
* - Perfect `parseBool`
|
|
11
|
-
**/
|
package/dist/core/env.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { isNum, isBool } from "./types";
|
|
2
|
-
import { parseNum, parseBool } from "./parse";
|
|
3
|
-
export function getEnv(key, fallback) {
|
|
4
|
-
const value = process.env[key]?.trim();
|
|
5
|
-
if (!value || value === "") {
|
|
6
|
-
if (fallback !== undefined)
|
|
7
|
-
return fallback;
|
|
8
|
-
throw new Error(`Missing ENV: '${key}'`);
|
|
9
|
-
}
|
|
10
|
-
if (isNum(value))
|
|
11
|
-
return parseNum(value);
|
|
12
|
-
if (isBool(value))
|
|
13
|
-
return parseBool(value);
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Problems:
|
|
18
|
-
*
|
|
19
|
-
* - Perfect `EnvValue`
|
|
20
|
-
* - Perfect `isNum`
|
|
21
|
-
* - Perfect `isBool`
|
|
22
|
-
* - Perfect `parseNum`
|
|
23
|
-
* - Perfect `parseBool`
|
|
24
|
-
**/
|
package/dist/types/env.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type EnvValue = string | number | boolean;
|
package/dist/types/env.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
File without changes
|