@bouko/ts 0.4.5 → 0.4.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 +3 -0
- package/dist/index.js +42 -0
- package/dist/types/generic.d.ts +7 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,9 @@ export * from "./utils/log";
|
|
|
12
12
|
export * from "./utils/time";
|
|
13
13
|
export * from "./utils/sorters";
|
|
14
14
|
export declare const safely: <T>(action: () => T) => T | undefined;
|
|
15
|
+
export declare const createKey: (...params: (string | number)[]) => string;
|
|
16
|
+
export declare function mergeArrayMaps(defaults: Record<string, string[]>, disk: Record<string, string[]>): Record<string, string[]>;
|
|
17
|
+
export declare function sanitizeArrayMap(input: unknown): Record<string, string[]>;
|
|
15
18
|
export declare const safelyThru: <T>(arr: T[], action: (item: T) => void) => void;
|
|
16
19
|
export declare const isJsonMap: (value: unknown) => value is JsonMap;
|
|
17
20
|
export declare const isJsonValue: (value: unknown) => value is JsonValue;
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,48 @@ export const safely = (action) => {
|
|
|
18
18
|
return undefined;
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
+
export const createKey = (...params) => {
|
|
22
|
+
if (params.length === 0)
|
|
23
|
+
return "";
|
|
24
|
+
else if (params.length === 1)
|
|
25
|
+
return params[0].toString();
|
|
26
|
+
let str = "";
|
|
27
|
+
for (let i = 0; i < params.length; i++) {
|
|
28
|
+
str += params[i];
|
|
29
|
+
if (i < params.length - 1)
|
|
30
|
+
str += "::";
|
|
31
|
+
}
|
|
32
|
+
return str;
|
|
33
|
+
};
|
|
34
|
+
export function mergeArrayMaps(defaults, disk) {
|
|
35
|
+
const out = {};
|
|
36
|
+
const keys = new Set([
|
|
37
|
+
...Object.keys(defaults),
|
|
38
|
+
...Object.keys(disk)
|
|
39
|
+
]);
|
|
40
|
+
for (const key of keys) {
|
|
41
|
+
const d = defaults[key] ?? [];
|
|
42
|
+
const u = disk[key] ?? [];
|
|
43
|
+
out[key] = Array.from(new Set([...d, ...u]));
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
export function sanitizeArrayMap(input) {
|
|
48
|
+
if (!input || typeof input !== "object")
|
|
49
|
+
return {};
|
|
50
|
+
const out = {};
|
|
51
|
+
for (const [key, value] of Object.entries(input)) {
|
|
52
|
+
if (typeof key !== "string" ||
|
|
53
|
+
!Array.isArray(value))
|
|
54
|
+
continue;
|
|
55
|
+
const aliases = value
|
|
56
|
+
.filter(v => typeof v === "string")
|
|
57
|
+
.map(v => v.trim())
|
|
58
|
+
.filter(Boolean);
|
|
59
|
+
out[key] = aliases;
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
21
63
|
export const safelyThru = (arr, action) => {
|
|
22
64
|
try {
|
|
23
65
|
arr.forEach(action);
|
package/dist/types/generic.d.ts
CHANGED