@nu-art/ts-common 0.400.6 → 0.400.8
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/package.json
CHANGED
|
@@ -7,8 +7,12 @@ export declare const FileSystemUtils: {
|
|
|
7
7
|
isFile: (pathToFile: string) => Promise<boolean>;
|
|
8
8
|
exists: (pathToFile: string) => Promise<boolean>;
|
|
9
9
|
delete: (pathToFile: string, mustExist?: boolean) => Promise<void>;
|
|
10
|
-
write: (pathToFile: string, content: string) => Promise<void
|
|
11
|
-
|
|
10
|
+
write: ((pathToFile: string, content: string) => Promise<void>) & {
|
|
11
|
+
json: <T>(pathToFile: string, value: T) => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
read: ((pathToFile: string) => Promise<string>) & {
|
|
14
|
+
json: <T>(pathToFile: string, defaultValue?: T) => Promise<T>;
|
|
15
|
+
};
|
|
12
16
|
copy: (sourcePath: string, targetPath: string) => Promise<void>;
|
|
13
17
|
template: {
|
|
14
18
|
read: (pathToFile: string, params: StringMap, pattern?: RegExp) => Promise<string>;
|
package/utils/FileSystemUtils.js
CHANGED
|
@@ -54,14 +54,29 @@ export const FileSystemUtils = {
|
|
|
54
54
|
await assertFile(pathToFile);
|
|
55
55
|
return _fs.rm(pathToFile);
|
|
56
56
|
},
|
|
57
|
-
write: async (pathToFile, content) => {
|
|
57
|
+
write: Object.assign(async (pathToFile, content) => {
|
|
58
58
|
await FileSystemUtils.folder.create(resolve(pathToFile, '..'));
|
|
59
59
|
return _fs.writeFile(pathToFile, content, 'utf-8');
|
|
60
|
-
},
|
|
61
|
-
|
|
60
|
+
}, {
|
|
61
|
+
json: async (pathToFile, value) => {
|
|
62
|
+
return await FileSystemUtils.file.write(pathToFile, JSON.stringify(value, null, 2));
|
|
63
|
+
}
|
|
64
|
+
}),
|
|
65
|
+
read: Object.assign(async (pathToFile) => {
|
|
62
66
|
await assertFile(pathToFile);
|
|
63
67
|
return _fs.readFile(pathToFile, 'utf-8');
|
|
64
|
-
},
|
|
68
|
+
}, {
|
|
69
|
+
json: async (pathToFile, defaultValue) => {
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(await FileSystemUtils.file.read(pathToFile));
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
if (!exists(defaultValue))
|
|
75
|
+
throw e;
|
|
76
|
+
return defaultValue;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}),
|
|
65
80
|
copy: async (sourcePath, targetPath) => {
|
|
66
81
|
await assertExists(targetPath, false, 'File');
|
|
67
82
|
await assertFile(sourcePath);
|
package/utils/array-tools.d.ts
CHANGED
|
@@ -49,13 +49,7 @@ export declare function filterFalsy<T>(array?: (T | undefined | null | void)[]):
|
|
|
49
49
|
/**
|
|
50
50
|
* receives array and builds hashmap whom keys are decided via function and values are from array
|
|
51
51
|
* */
|
|
52
|
-
export declare function arrayToMap<T>(array: T[] | Readonly<T[]>, getKey: (item: T, index: number, map:
|
|
53
|
-
[k: string]: T;
|
|
54
|
-
}) => string | number | (string | number)[], map?: {
|
|
55
|
-
[k: string]: T;
|
|
56
|
-
}): {
|
|
57
|
-
[k: string]: T;
|
|
58
|
-
};
|
|
52
|
+
export declare function arrayToMap<T>(array: T[] | Readonly<T[]>, getKey: (item: T, index: number, map: TypedMap<T>) => string | number | (string | number)[], map?: TypedMap<T>): TypedMap<T>;
|
|
59
53
|
type KeyResolver<Input, Output = Input> = (item: Input, index: number, map: {
|
|
60
54
|
[k: string]: Output;
|
|
61
55
|
}) => string | number | (string | number)[];
|