@bemoje/fs 0.0.12 → 0.0.13
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.cjs.js +6 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +6 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/types/index.d.ts +36 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/lib/AppData.d.ts +11 -0
- package/dist/types/lib/AppData.d.ts.map +1 -0
- package/dist/types/lib/JsonFile.d.ts +79 -0
- package/dist/types/lib/JsonFile.d.ts.map +1 -0
- package/dist/types/lib/LogFile.d.ts +51 -0
- package/dist/types/lib/LogFile.d.ts.map +1 -0
- package/{src/lib/absoluteToRelativePath.ts → dist/types/lib/absoluteToRelativePath.d.ts} +14 -20
- package/dist/types/lib/absoluteToRelativePath.d.ts.map +1 -0
- package/dist/types/lib/appendLineToFile.d.ts +12 -0
- package/dist/types/lib/appendLineToFile.d.ts.map +1 -0
- package/{src/lib/cleanDirectorySync.ts → dist/types/lib/cleanDirectorySync.d.ts} +17 -24
- package/dist/types/lib/cleanDirectorySync.d.ts.map +1 -0
- package/{src/lib/createDirectory.ts → dist/types/lib/createDirectory.d.ts} +2 -5
- package/dist/types/lib/createDirectory.d.ts.map +1 -0
- package/{src/lib/createDirectorySync.ts → dist/types/lib/createDirectorySync.d.ts} +2 -6
- package/dist/types/lib/createDirectorySync.d.ts.map +1 -0
- package/{src/lib/createFileExtensionFilter.ts → dist/types/lib/createFileExtensionFilter.d.ts} +2 -14
- package/dist/types/lib/createFileExtensionFilter.d.ts.map +1 -0
- package/{src/lib/cwdpath.ts → dist/types/lib/cwdpath.d.ts} +13 -16
- package/dist/types/lib/cwdpath.d.ts.map +1 -0
- package/{src/lib/deleteDirectory.ts → dist/types/lib/deleteDirectory.d.ts} +2 -5
- package/dist/types/lib/deleteDirectory.d.ts.map +1 -0
- package/{src/lib/deleteDirectorySafe.ts → dist/types/lib/deleteDirectorySafe.d.ts} +2 -5
- package/dist/types/lib/deleteDirectorySafe.d.ts.map +1 -0
- package/{src/lib/deleteDirectorySafeSync.ts → dist/types/lib/deleteDirectorySafeSync.d.ts} +2 -7
- package/dist/types/lib/deleteDirectorySafeSync.d.ts.map +1 -0
- package/{src/lib/deleteDirectorySync.ts → dist/types/lib/deleteDirectorySync.d.ts} +2 -6
- package/dist/types/lib/deleteDirectorySync.d.ts.map +1 -0
- package/{src/lib/ensureValidWindowsPath.ts → dist/types/lib/ensureValidWindowsPath.d.ts} +23 -57
- package/dist/types/lib/ensureValidWindowsPath.d.ts.map +1 -0
- package/dist/types/lib/getDiskDrivesWindows.d.ts +2 -0
- package/dist/types/lib/getDiskDrivesWindows.d.ts.map +1 -0
- package/dist/types/lib/getDownloadsDirectory.d.ts +2 -0
- package/dist/types/lib/getDownloadsDirectory.d.ts.map +1 -0
- package/dist/types/lib/getHomeDirectory.d.ts +2 -0
- package/dist/types/lib/getHomeDirectory.d.ts.map +1 -0
- package/dist/types/lib/getLastMofifiedFileIn.d.ts +2 -0
- package/dist/types/lib/getLastMofifiedFileIn.d.ts.map +1 -0
- package/dist/types/lib/getRootDir.d.ts +2 -0
- package/dist/types/lib/getRootDir.d.ts.map +1 -0
- package/dist/types/lib/isWindows.d.ts +2 -0
- package/dist/types/lib/isWindows.d.ts.map +1 -0
- package/{src/lib/normalizeFileExtension.ts → dist/types/lib/normalizeFileExtension.d.ts} +23 -29
- package/dist/types/lib/normalizeFileExtension.d.ts.map +1 -0
- package/{src/lib/readFileLastLines.ts → dist/types/lib/readFileLastLines.d.ts} +3 -5
- package/dist/types/lib/readFileLastLines.d.ts.map +1 -0
- package/{src/lib/readJsonFile.ts → dist/types/lib/readJsonFile.d.ts} +13 -16
- package/dist/types/lib/readJsonFile.d.ts.map +1 -0
- package/{src/lib/readJsonFileSync.ts → dist/types/lib/readJsonFileSync.d.ts} +13 -16
- package/dist/types/lib/readJsonFileSync.d.ts.map +1 -0
- package/dist/types/lib/readPackageJson.d.ts +2 -0
- package/dist/types/lib/readPackageJson.d.ts.map +1 -0
- package/dist/types/lib/removeIllegalFilenameCharacters.d.ts +2 -0
- package/dist/types/lib/removeIllegalFilenameCharacters.d.ts.map +1 -0
- package/dist/types/lib/tempFile.d.ts +7 -0
- package/dist/types/lib/tempFile.d.ts.map +1 -0
- package/dist/types/lib/types/IEnsureValidWindowsPathOptions.d.ts +11 -0
- package/dist/types/lib/types/IEnsureValidWindowsPathOptions.d.ts.map +1 -0
- package/dist/types/lib/types/ILogFileData.d.ts +6 -0
- package/dist/types/lib/types/ILogFileData.d.ts.map +1 -0
- package/dist/types/lib/unzipFile.d.ts +2 -0
- package/dist/types/lib/unzipFile.d.ts.map +1 -0
- package/dist/types/lib/unzipMergeFiles.d.ts +5 -0
- package/dist/types/lib/unzipMergeFiles.d.ts.map +1 -0
- package/dist/types/lib/wipeDirectorySafe.d.ts +2 -0
- package/dist/types/lib/wipeDirectorySafe.d.ts.map +1 -0
- package/{src/lib/writeJsonFile.ts → dist/types/lib/writeJsonFile.d.ts} +2 -5
- package/dist/types/lib/writeJsonFile.d.ts.map +1 -0
- package/{src/lib/writeJsonFileSync.ts → dist/types/lib/writeJsonFileSync.d.ts} +2 -5
- package/dist/types/lib/writeJsonFileSync.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +0 -35
- package/src/lib/AppData.ts +0 -25
- package/src/lib/JsonFile.ts +0 -158
- package/src/lib/LogFile.ts +0 -117
- package/src/lib/absoluteToRelativePath.test.ts +0 -11
- package/src/lib/appendLineToFile.test.ts +0 -49
- package/src/lib/appendLineToFile.ts +0 -21
- package/src/lib/cleanDirectorySync.test.ts +0 -57
- package/src/lib/createDirectory.test.ts +0 -14
- package/src/lib/createDirectorySync.test.ts +0 -14
- package/src/lib/createFileExtensionFilter.test.ts +0 -17
- package/src/lib/cwdpath.test.ts +0 -48
- package/src/lib/deleteDirectory.test.ts +0 -24
- package/src/lib/deleteDirectorySafe.test.ts +0 -40
- package/src/lib/deleteDirectorySafeSync.test.ts +0 -30
- package/src/lib/deleteDirectorySync.test.ts +0 -23
- package/src/lib/ensureValidWindowsPath.test.ts +0 -80
- package/src/lib/getDiskDrivesWindows.ts +0 -13
- package/src/lib/getDownloadsDirectory.ts +0 -6
- package/src/lib/getHomeDirectory.ts +0 -7
- package/src/lib/getLastMofifiedFileIn.ts +0 -15
- package/src/lib/getRootDir.ts +0 -5
- package/src/lib/isWindows.ts +0 -3
- package/src/lib/normalizeFileExtension.test.ts +0 -15
- package/src/lib/readJsonFile.test.ts +0 -34
- package/src/lib/readJsonFileSync.test.ts +0 -36
- package/src/lib/readPackageJson.ts +0 -9
- package/src/lib/removeIllegalFilenameCharacters.ts +0 -3
- package/src/lib/tempFile.ts +0 -20
- package/src/lib/types/IEnsureValidWindowsPathOptions.ts +0 -10
- package/src/lib/types/ILogFileData.ts +0 -5
- package/src/lib/unzipFile.ts +0 -5
- package/src/lib/unzipMergeFiles.ts +0 -20
- package/src/lib/wipeDirectorySafe.ts +0 -7
- package/src/lib/writeJsonFile.test.ts +0 -26
- package/src/lib/writeJsonFileSync.test.ts +0 -28
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export function cleanDirectorySync(dirpath: string, predicate: (filepath: string, stat: Stats) => boolean): void {
|
|
19
|
-
for (const filename of fs.readdirSync(dirpath)) {
|
|
20
|
-
const filepath = path.join(dirpath, filename)
|
|
21
|
-
const stat = fs.statSync(filepath)
|
|
22
|
-
if (predicate(filepath, stat)) fs.unlinkSync(filepath)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Stats } from 'fs';
|
|
3
|
+
/**
|
|
4
|
+
* Synchronously cleans a directory by removing files that satisfy a given predicate.
|
|
5
|
+
* @remarks This function is a part of the File System module.
|
|
6
|
+
* @param dirpath - The path to the directory that needs to be cleaned.
|
|
7
|
+
* @param predicate - A function that takes a filepath and its stats as arguments and returns a boolean. If the function returns true for a file, that file is removed from the directory.
|
|
8
|
+
* @throws If the directory at the provided path does not exist or cannot be read.
|
|
9
|
+
* @example ```ts
|
|
10
|
+
* import { Stats } from 'fs';
|
|
11
|
+
* const dirpath = './my-directory';
|
|
12
|
+
* const predicate = (filepath: string, stat: Stats) => stat.size > 1024;
|
|
13
|
+
* cleanDirectorySync(dirpath, predicate);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function cleanDirectorySync(dirpath: string, predicate: (filepath: string, stat: Stats) => boolean): void;
|
|
17
|
+
//# sourceMappingURL=cleanDirectorySync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanDirectorySync.d.ts","sourceRoot":"","sources":["../../../src/lib/cleanDirectorySync.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,IAAI,CAAA;AAI/B;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAM/G"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
1
|
/**
|
|
3
2
|
* Create a directory at a given path if it does not exist.
|
|
4
3
|
* Automatically creates parent directories if they do not exist.
|
|
@@ -11,7 +10,5 @@ import fs from 'fs'
|
|
|
11
10
|
* });
|
|
12
11
|
* ```
|
|
13
12
|
*/
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
return dirpath
|
|
17
|
-
}
|
|
13
|
+
export declare function createDirectory(dirpath: string): Promise<string>;
|
|
14
|
+
//# sourceMappingURL=createDirectory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDirectory.d.ts","sourceRoot":"","sources":["../../../src/lib/createDirectory.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGtE"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Create a directory at a given path if it does not exist.
|
|
5
3
|
* Automatically creates parent directories if they do not exist.
|
|
@@ -9,7 +7,5 @@ import fs from 'fs'
|
|
|
9
7
|
* createDirectorySync('/path/to/directory')
|
|
10
8
|
* ```
|
|
11
9
|
*/
|
|
12
|
-
export function createDirectorySync(dirpath: string): string
|
|
13
|
-
|
|
14
|
-
return dirpath
|
|
15
|
-
}
|
|
10
|
+
export declare function createDirectorySync(dirpath: string): string;
|
|
11
|
+
//# sourceMappingURL=createDirectorySync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDirectorySync.d.ts","sourceRoot":"","sources":["../../../src/lib/createDirectorySync.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG3D"}
|
package/{src/lib/createFileExtensionFilter.ts → dist/types/lib/createFileExtensionFilter.d.ts}
RENAMED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { normalizeFileExtension } from './normalizeFileExtension'
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* Takes a list of file extensions and returns a filter function that returns true if a filepath/filename passed to it contains one of the given file extensions.
|
|
6
3
|
* @remarks If no file extensions are provided, the filter will always return true.
|
|
@@ -13,14 +10,5 @@ import { normalizeFileExtension } from './normalizeFileExtension'
|
|
|
13
10
|
* //=> false
|
|
14
11
|
* ```
|
|
15
12
|
*/
|
|
16
|
-
export function createFileExtensionFilter(...fileExtensions: string[]): (filepath: string) => boolean
|
|
17
|
-
|
|
18
|
-
return (filepath: string) => {
|
|
19
|
-
for (const ext of fileExtensions.map(normalizeFileExtension)) {
|
|
20
|
-
if (path.extname(filepath) === ext) {
|
|
21
|
-
return true
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return false
|
|
25
|
-
}
|
|
26
|
-
}
|
|
13
|
+
export declare function createFileExtensionFilter(...fileExtensions: string[]): (filepath: string) => boolean;
|
|
14
|
+
//# sourceMappingURL=createFileExtensionFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFileExtensionFilter.d.ts","sourceRoot":"","sources":["../../../src/lib/createFileExtensionFilter.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,cAAc,EAAE,MAAM,EAAE,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAUpG"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* The
|
|
7
|
-
* @
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export function cwdpath(...paths: string[]): string {
|
|
15
|
-
return path.join(process.cwd(), ...paths)
|
|
16
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Joins the given path segments to the current working directory path, and normalizes the resulting path.
|
|
3
|
+
* @remarks
|
|
4
|
+
* The function uses the `path.join` method from the Node.js `path` module, and the `process.cwd` method from the Node.js `process` module.
|
|
5
|
+
* @param paths - The path segments to join to the current working directory path.
|
|
6
|
+
* @returns The resulting path.
|
|
7
|
+
* @example ```ts
|
|
8
|
+
* console.log(cwdpath('src', 'index.ts'));
|
|
9
|
+
* //=> '{working_directory}/src/index.ts'
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function cwdpath(...paths: string[]): string;
|
|
13
|
+
//# sourceMappingURL=cwdpath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cwdpath.d.ts","sourceRoot":"","sources":["../../../src/lib/cwdpath.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAElD"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Deletes a directory and all of its contents.
|
|
5
3
|
* @remarks This function uses Node.js's `fs.promises.rm` method with the `recursive` and `force` options set to `true`.
|
|
@@ -11,6 +9,5 @@ import fs from 'fs'
|
|
|
11
9
|
* deleteDirectory('/path/to/directory');
|
|
12
10
|
* ```
|
|
13
11
|
*/
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
}
|
|
12
|
+
export declare function deleteDirectory(dirpath: string): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=deleteDirectory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteDirectory.d.ts","sourceRoot":"","sources":["../../../src/lib/deleteDirectory.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEpE"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Deletes a directory safely if it exists.
|
|
5
3
|
* @remarks This function uses Node.js' `fs.promises.rm` method with the `recursive` and `force` options set to `true`.
|
|
@@ -12,6 +10,5 @@ import fs from 'fs'
|
|
|
12
10
|
* //=> undefined
|
|
13
11
|
* ```
|
|
14
12
|
*/
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
}
|
|
13
|
+
export declare function deleteDirectorySafe(dirpath: string): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=deleteDirectorySafe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteDirectorySafe.d.ts","sourceRoot":"","sources":["../../../src/lib/deleteDirectorySafe.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAExE"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Deletes a directory synchronously in a safe manner. If the directory does not exist, it will simply return the directory path without throwing an error.
|
|
5
3
|
* @param dirpath The path of the directory to be deleted.
|
|
@@ -10,8 +8,5 @@ import fs from 'fs'
|
|
|
10
8
|
* //=> undefined
|
|
11
9
|
* ```
|
|
12
10
|
*/
|
|
13
|
-
export function deleteDirectorySafeSync(dirpath: string): string
|
|
14
|
-
|
|
15
|
-
fs.rmSync(dirpath, { recursive: true, force: true })
|
|
16
|
-
return dirpath
|
|
17
|
-
}
|
|
11
|
+
export declare function deleteDirectorySafeSync(dirpath: string): string;
|
|
12
|
+
//# sourceMappingURL=deleteDirectorySafeSync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteDirectorySafeSync.d.ts","sourceRoot":"","sources":["../../../src/lib/deleteDirectorySafeSync.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI/D"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Deletes a directory synchronously.
|
|
5
3
|
* @remarks This function uses Node.js's `fs.rmSync` method with the options `{ recursive: true, force: true }`.
|
|
@@ -11,7 +9,5 @@ import fs from 'fs'
|
|
|
11
9
|
* //=> undefined
|
|
12
10
|
* ```
|
|
13
11
|
*/
|
|
14
|
-
export function deleteDirectorySync(dirpath: string): string
|
|
15
|
-
|
|
16
|
-
return dirpath
|
|
17
|
-
}
|
|
12
|
+
export declare function deleteDirectorySync(dirpath: string): string;
|
|
13
|
+
//# sourceMappingURL=deleteDirectorySync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteDirectorySync.d.ts","sourceRoot":"","sources":["../../../src/lib/deleteDirectorySync.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG3D"}
|
|
@@ -1,57 +1,23 @@
|
|
|
1
|
-
import { IEnsureValidWindowsPathOptions } from './types/IEnsureValidWindowsPathOptions'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
10
|
-
* - `
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const throwOrFalse = (msg: string) => {
|
|
25
|
-
if (options && options.assert === true) {
|
|
26
|
-
throw new Error(`Invalid windows path. ${msg} | input received: ${path}`)
|
|
27
|
-
}
|
|
28
|
-
return false
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (path.length === 0) {
|
|
32
|
-
return throwOrFalse('Path string is length 0.')
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (path.indexOf('/') !== -1 && path.indexOf('\\') !== -1) {
|
|
36
|
-
return throwOrFalse('Path contains both backslash and forward slash.')
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const maxLength = (options && options.extendedMaxLength ? 32767 : 260) - 12
|
|
40
|
-
if (path.length > maxLength) {
|
|
41
|
-
return throwOrFalse(`Maximum length of ${maxLength} exceeded`)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
let noDriveLetter = path
|
|
45
|
-
if (/^\w:(\\|\/)/g.test(path)) {
|
|
46
|
-
noDriveLetter = path.substring(2)
|
|
47
|
-
}
|
|
48
|
-
if (/[<>"|?*:]/g.test(noDriveLetter)) {
|
|
49
|
-
return throwOrFalse(`Illegal characters in: ${path} | Illegal characters are: <>"|?:*`)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (/(\\|\/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])((\\|\/)|$)/g.test(path)) {
|
|
53
|
-
return throwOrFalse('Illegal name in path string')
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return true
|
|
57
|
-
}
|
|
1
|
+
import { IEnsureValidWindowsPathOptions } from './types/IEnsureValidWindowsPathOptions';
|
|
2
|
+
/**
|
|
3
|
+
* Check whether a provided windows filesystem path string is valid according to:
|
|
4
|
+
* https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
|
|
5
|
+
* @param path The path to validate.
|
|
6
|
+
* @returns A boolean indicating whether the path is valid. If the `assert` option is true, the function will throw an error instead of returning false.
|
|
7
|
+
* @throws Will throw an error if the `assert` option is true and the path is invalid.
|
|
8
|
+
* @param options An optional object that may contain the following properties:
|
|
9
|
+
* - `assert`: If true, the function will throw an error if the path is invalid. Default is false.
|
|
10
|
+
* - `extendedMaxLength`: If true, the function will allow paths up to 32767 characters long. Default is false.
|
|
11
|
+
* @example ```ts
|
|
12
|
+
* ensureValidWindowsPath('C:\\Users\\User\\Documents\\file.txt');;
|
|
13
|
+
* //=> true
|
|
14
|
+
* ensureValidWindowsPath('C:/Users/User/Documents/file.txt');;
|
|
15
|
+
* //=> false
|
|
16
|
+
* ensureValidWindowsPath('C:\\Users\\User\\Documents\\file.txt', { assert: true });;
|
|
17
|
+
* //=> throws an error
|
|
18
|
+
* ensureValidWindowsPath('C:\\Users\\User\\Documents\\file.txt', { extendedMaxLength: true });;
|
|
19
|
+
* //=> true
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function ensureValidWindowsPath(path: string, options?: IEnsureValidWindowsPathOptions): boolean;
|
|
23
|
+
//# sourceMappingURL=ensureValidWindowsPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureValidWindowsPath.d.ts","sourceRoot":"","sources":["../../../src/lib/ensureValidWindowsPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAA;AAEvF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,8BAA8B,GAAG,OAAO,CAkCtG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDiskDrivesWindows.d.ts","sourceRoot":"","sources":["../../../src/lib/getDiskDrivesWindows.ts"],"names":[],"mappings":"AAIA,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAQ/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDownloadsDirectory.d.ts","sourceRoot":"","sources":["../../../src/lib/getDownloadsDirectory.ts"],"names":[],"mappings":"AAGA,wBAAgB,qBAAqB,WAEpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHomeDirectory.d.ts","sourceRoot":"","sources":["../../../src/lib/getHomeDirectory.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,IAAI,MAAM,CAIzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLastMofifiedFileIn.d.ts","sourceRoot":"","sources":["../../../src/lib/getLastMofifiedFileIn.ts"],"names":[],"mappings":"AAGA,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAW5E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRootDir.d.ts","sourceRoot":"","sources":["../../../src/lib/getRootDir.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,WAEzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isWindows.d.ts","sourceRoot":"","sources":["../../../src/lib/isWindows.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,YAExB"}
|
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalize a file extension to the form: .[ext]
|
|
3
|
-
* Anything before the last "." is not returned.
|
|
4
|
-
* @returns The normalized file extension.
|
|
5
|
-
* @throws If the extension contains illegal characters.
|
|
6
|
-
* @param ext file extension
|
|
7
|
-
* @example ```ts
|
|
8
|
-
* normalizeFileExtension('jpg');;
|
|
9
|
-
* //=> '.jpg'
|
|
10
|
-
* normalizeFileExtension('.jpg');;
|
|
11
|
-
* //=> '.jpg'
|
|
12
|
-
* normalizeFileExtension('..jpg');;
|
|
13
|
-
* //=> '.jpg'
|
|
14
|
-
* normalizeFileExtension('');;
|
|
15
|
-
* //=> ''
|
|
16
|
-
* normalizeFileExtension('.');;
|
|
17
|
-
* //=> ''
|
|
18
|
-
* normalizeFileExtension('jpg|png');;
|
|
19
|
-
* //=> Error
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export function normalizeFileExtension(ext: string): string
|
|
23
|
-
|
|
24
|
-
if (/[<>"|?*:]/g.test(ext)) {
|
|
25
|
-
throw new Error(`Illegal characters in file extension: ${ext} | Illegal characters are: <>"|?:*`)
|
|
26
|
-
}
|
|
27
|
-
if (!ext.includes('.')) return '.' + ext
|
|
28
|
-
return ext.substring(ext.lastIndexOf('.'))
|
|
29
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Normalize a file extension to the form: .[ext]
|
|
3
|
+
* Anything before the last "." is not returned.
|
|
4
|
+
* @returns The normalized file extension.
|
|
5
|
+
* @throws If the extension contains illegal characters.
|
|
6
|
+
* @param ext file extension
|
|
7
|
+
* @example ```ts
|
|
8
|
+
* normalizeFileExtension('jpg');;
|
|
9
|
+
* //=> '.jpg'
|
|
10
|
+
* normalizeFileExtension('.jpg');;
|
|
11
|
+
* //=> '.jpg'
|
|
12
|
+
* normalizeFileExtension('..jpg');;
|
|
13
|
+
* //=> '.jpg'
|
|
14
|
+
* normalizeFileExtension('');;
|
|
15
|
+
* //=> ''
|
|
16
|
+
* normalizeFileExtension('.');;
|
|
17
|
+
* //=> ''
|
|
18
|
+
* normalizeFileExtension('jpg|png');;
|
|
19
|
+
* //=> Error
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizeFileExtension(ext: string): string;
|
|
23
|
+
//# sourceMappingURL=normalizeFileExtension.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeFileExtension.d.ts","sourceRoot":"","sources":["../../../src/lib/normalizeFileExtension.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO1D"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
3
2
|
/**
|
|
4
3
|
* Read the last n lines of a file.
|
|
5
4
|
* @param filepath The path to the file.
|
|
@@ -7,6 +6,5 @@ import readLastLines from 'read-last-lines'
|
|
|
7
6
|
* @param encoding The encoding of the file.
|
|
8
7
|
* @example await readLastLines.read('path/to/file.log', 50)
|
|
9
8
|
*/
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
}
|
|
9
|
+
export declare function readFileLastLines(filepath: string, n: number, encoding?: NodeJS.BufferEncoding): Promise<string>;
|
|
10
|
+
//# sourceMappingURL=readFileLastLines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readFileLastLines.d.ts","sourceRoot":"","sources":["../../../src/lib/readFileLastLines.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,CAAC,cAAuB,mBAE5G"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export async function readJsonFile<T>(filepath: string): Promise<T> {
|
|
15
|
-
return JSON.parse(await fs.promises.readFile(filepath, 'utf8'))
|
|
16
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Reads a JSON file from the given filepath and returns its content as a Promise.
|
|
3
|
+
* The Promise will resolve with the parsed JSON content as an object of type T.
|
|
4
|
+
* @template T The expected return type of the JSON object.
|
|
5
|
+
* @param filepath The path to the JSON file to read.
|
|
6
|
+
* @returns A Promise that resolves with the parsed JSON content as an object of type T.
|
|
7
|
+
* @throws Will throw an error if reading the file fails for any reason.
|
|
8
|
+
* @example ```ts
|
|
9
|
+
* const data: MyType = await readJsonFile<MyType>('path/to/myfile.json');
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function readJsonFile<T>(filepath: string): Promise<T>;
|
|
13
|
+
//# sourceMappingURL=readJsonFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readJsonFile.d.ts","sourceRoot":"","sources":["../../../src/lib/readJsonFile.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAElE"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export function readJsonFileSync<T>(filepath: string): T {
|
|
15
|
-
return JSON.parse(fs.readFileSync(filepath, 'utf8'))
|
|
16
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Reads a JSON file synchronously and returns a Promise that resolves with the parsed JSON data.
|
|
3
|
+
* @template T The expected return type of the JSON data.
|
|
4
|
+
* @param filepath The path to the JSON file to read.
|
|
5
|
+
* @returns A Promise that resolves with the parsed JSON data.
|
|
6
|
+
* @throws If the file cannot be read or the content cannot be parsed as JSON.
|
|
7
|
+
* @example ```ts
|
|
8
|
+
* const data = await readJsonFileSync<MyType>('/path/to/file.json');
|
|
9
|
+
* console.log(data);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare function readJsonFileSync<T>(filepath: string): T;
|
|
13
|
+
//# sourceMappingURL=readJsonFileSync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readJsonFileSync.d.ts","sourceRoot":"","sources":["../../../src/lib/readJsonFileSync.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,CAEvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readPackageJson.d.ts","sourceRoot":"","sources":["../../../src/lib/readPackageJson.ts"],"names":[],"mappings":"AAIA,wBAAgB,eAAe,CAAC,WAAW,SAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAI5F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeIllegalFilenameCharacters.d.ts","sourceRoot":"","sources":["../../../src/lib/removeIllegalFilenameCharacters.ts"],"names":[],"mappings":"AAAA,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,UAE7D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a temporary file and deletes it after the callback has finished.
|
|
3
|
+
* @param fileExtension - The file extension to use for the temporary file.
|
|
4
|
+
* @param callback - The callback to execute with the temporary file path. The callback can return a promise and the temporary file will not be deleted until the promise has resolved or rejected.
|
|
5
|
+
*/
|
|
6
|
+
export declare function tempFile(fileExtension: string, callback: (fpath: string) => void | Promise<void>): void;
|
|
7
|
+
//# sourceMappingURL=tempFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tempFile.d.ts","sourceRoot":"","sources":["../../../src/lib/tempFile.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAWvG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface IEnsureValidWindowsPathOptions {
|
|
2
|
+
/**
|
|
3
|
+
* On most versions of windows, the max allowed length of paths has been raised.
|
|
4
|
+
*/
|
|
5
|
+
extendedMaxLength?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Throw if not valid, otherwise return false.
|
|
8
|
+
*/
|
|
9
|
+
assert?: boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=IEnsureValidWindowsPathOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IEnsureValidWindowsPathOptions.d.ts","sourceRoot":"","sources":["../../../../src/lib/types/IEnsureValidWindowsPathOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ILogFileData.d.ts","sourceRoot":"","sources":["../../../../src/lib/types/ILogFileData.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,CAAC,CAAA;CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unzipFile.d.ts","sourceRoot":"","sources":["../../../src/lib/unzipFile.ts"],"names":[],"mappings":"AAEA,wBAAsB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAE/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unzipMergeFiles.d.ts","sourceRoot":"","sources":["../../../src/lib/unzipMergeFiles.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,iBAY9E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wipeDirectorySafe.d.ts","sourceRoot":"","sources":["../../../src/lib/wipeDirectorySafe.ts"],"names":[],"mappings":"AAGA,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,MAAM,iBAGtD"}
|