@bemoje/fs 0.0.13 → 0.2.0

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.
Files changed (154) hide show
  1. package/README.md +6 -34
  2. package/package.json +10 -10
  3. package/{dist/types → src}/index.d.ts +0 -1
  4. package/src/index.js +39 -0
  5. package/src/index.js.map +1 -0
  6. package/{dist/types → src}/lib/AppData.d.ts +0 -1
  7. package/src/lib/AppData.js +24 -0
  8. package/src/lib/AppData.js.map +1 -0
  9. package/{dist/types → src}/lib/JsonFile.d.ts +0 -1
  10. package/src/lib/JsonFile.js +146 -0
  11. package/src/lib/JsonFile.js.map +1 -0
  12. package/{dist/types → src}/lib/LogFile.d.ts +0 -1
  13. package/src/lib/LogFile.js +158 -0
  14. package/src/lib/LogFile.js.map +1 -0
  15. package/{dist/types → src}/lib/absoluteToRelativePath.d.ts +0 -1
  16. package/src/lib/absoluteToRelativePath.js +25 -0
  17. package/src/lib/absoluteToRelativePath.js.map +1 -0
  18. package/{dist/types → src}/lib/appendLineToFile.d.ts +0 -1
  19. package/src/lib/appendLineToFile.js +28 -0
  20. package/src/lib/appendLineToFile.js.map +1 -0
  21. package/{dist/types → src}/lib/cleanDirectorySync.d.ts +0 -1
  22. package/src/lib/cleanDirectorySync.js +29 -0
  23. package/src/lib/cleanDirectorySync.js.map +1 -0
  24. package/{dist/types → src}/lib/createDirectory.d.ts +0 -1
  25. package/src/lib/createDirectory.js +25 -0
  26. package/src/lib/createDirectory.js.map +1 -0
  27. package/{dist/types → src}/lib/createDirectorySync.d.ts +0 -1
  28. package/src/lib/createDirectorySync.js +20 -0
  29. package/src/lib/createDirectorySync.js.map +1 -0
  30. package/{dist/types → src}/lib/createFileExtensionFilter.d.ts +0 -1
  31. package/src/lib/createFileExtensionFilter.js +32 -0
  32. package/src/lib/createFileExtensionFilter.js.map +1 -0
  33. package/{dist/types → src}/lib/cwdpath.d.ts +0 -1
  34. package/src/lib/cwdpath.js +21 -0
  35. package/src/lib/cwdpath.js.map +1 -0
  36. package/{dist/types → src}/lib/deleteDirectory.d.ts +0 -1
  37. package/src/lib/deleteDirectory.js +23 -0
  38. package/src/lib/deleteDirectory.js.map +1 -0
  39. package/{dist/types → src}/lib/deleteDirectorySafe.d.ts +0 -1
  40. package/src/lib/deleteDirectorySafe.js +25 -0
  41. package/src/lib/deleteDirectorySafe.js.map +1 -0
  42. package/{dist/types → src}/lib/deleteDirectorySafeSync.d.ts +0 -1
  43. package/src/lib/deleteDirectorySafeSync.js +23 -0
  44. package/src/lib/deleteDirectorySafeSync.js.map +1 -0
  45. package/{dist/types → src}/lib/deleteDirectorySync.d.ts +0 -1
  46. package/src/lib/deleteDirectorySync.js +22 -0
  47. package/src/lib/deleteDirectorySync.js.map +1 -0
  48. package/{dist/types → src}/lib/ensureValidWindowsPath.d.ts +0 -1
  49. package/src/lib/ensureValidWindowsPath.js +54 -0
  50. package/src/lib/ensureValidWindowsPath.js.map +1 -0
  51. package/{dist/types → src}/lib/getDiskDrivesWindows.d.ts +0 -1
  52. package/src/lib/getDiskDrivesWindows.js +19 -0
  53. package/src/lib/getDiskDrivesWindows.js.map +1 -0
  54. package/{dist/types → src}/lib/getDownloadsDirectory.d.ts +0 -1
  55. package/src/lib/getDownloadsDirectory.js +11 -0
  56. package/src/lib/getDownloadsDirectory.js.map +1 -0
  57. package/{dist/types → src}/lib/getHomeDirectory.d.ts +0 -1
  58. package/src/lib/getHomeDirectory.js +13 -0
  59. package/src/lib/getHomeDirectory.js.map +1 -0
  60. package/{dist/types → src}/lib/getLastMofifiedFileIn.d.ts +0 -1
  61. package/src/lib/getLastMofifiedFileIn.js +22 -0
  62. package/src/lib/getLastMofifiedFileIn.js.map +1 -0
  63. package/{dist/types → src}/lib/getRootDir.d.ts +0 -1
  64. package/src/lib/getRootDir.js +10 -0
  65. package/src/lib/getRootDir.js.map +1 -0
  66. package/{dist/types → src}/lib/isWindows.d.ts +0 -1
  67. package/src/lib/isWindows.js +8 -0
  68. package/src/lib/isWindows.js.map +1 -0
  69. package/{dist/types → src}/lib/normalizeFileExtension.d.ts +0 -1
  70. package/src/lib/normalizeFileExtension.js +36 -0
  71. package/src/lib/normalizeFileExtension.js.map +1 -0
  72. package/{dist/types → src}/lib/readFileLastLines.d.ts +1 -4
  73. package/src/lib/readFileLastLines.js +18 -0
  74. package/src/lib/readFileLastLines.js.map +1 -0
  75. package/{dist/types → src}/lib/readJsonFile.d.ts +0 -1
  76. package/src/lib/readJsonFile.js +23 -0
  77. package/src/lib/readJsonFile.js.map +1 -0
  78. package/{dist/types → src}/lib/readJsonFileSync.d.ts +0 -1
  79. package/src/lib/readJsonFileSync.js +21 -0
  80. package/src/lib/readJsonFileSync.js.map +1 -0
  81. package/{dist/types → src}/lib/readPackageJson.d.ts +0 -1
  82. package/src/lib/readPackageJson.js +15 -0
  83. package/src/lib/readPackageJson.js.map +1 -0
  84. package/{dist/types → src}/lib/removeIllegalFilenameCharacters.d.ts +0 -1
  85. package/src/lib/removeIllegalFilenameCharacters.js +8 -0
  86. package/src/lib/removeIllegalFilenameCharacters.js.map +1 -0
  87. package/{dist/types → src}/lib/tempFile.d.ts +0 -1
  88. package/src/lib/tempFile.js +26 -0
  89. package/src/lib/tempFile.js.map +1 -0
  90. package/{dist/types → src}/lib/types/IEnsureValidWindowsPathOptions.d.ts +0 -1
  91. package/src/lib/types/IEnsureValidWindowsPathOptions.js +3 -0
  92. package/src/lib/types/IEnsureValidWindowsPathOptions.js.map +1 -0
  93. package/{dist/types → src}/lib/types/ILogFileData.d.ts +0 -1
  94. package/src/lib/types/ILogFileData.js +3 -0
  95. package/src/lib/types/ILogFileData.js.map +1 -0
  96. package/{dist/types → src}/lib/unzipFile.d.ts +0 -1
  97. package/src/lib/unzipFile.js +12 -0
  98. package/src/lib/unzipFile.js.map +1 -0
  99. package/{dist/types → src}/lib/unzipMergeFiles.d.ts +0 -1
  100. package/src/lib/unzipMergeFiles.js +29 -0
  101. package/src/lib/unzipMergeFiles.js.map +1 -0
  102. package/{dist/types → src}/lib/wipeDirectorySafe.d.ts +0 -1
  103. package/src/lib/wipeDirectorySafe.js +14 -0
  104. package/src/lib/wipeDirectorySafe.js.map +1 -0
  105. package/{dist/types → src}/lib/writeJsonFile.d.ts +0 -1
  106. package/src/lib/writeJsonFile.js +25 -0
  107. package/src/lib/writeJsonFile.js.map +1 -0
  108. package/{dist/types → src}/lib/writeJsonFileSync.d.ts +0 -1
  109. package/src/lib/writeJsonFileSync.js +22 -0
  110. package/src/lib/writeJsonFileSync.js.map +1 -0
  111. package/LICENSE +0 -21
  112. package/dist/index.cjs.js +0 -6
  113. package/dist/index.cjs.js.map +0 -1
  114. package/dist/index.esm.js +0 -6
  115. package/dist/index.esm.js.map +0 -1
  116. package/dist/types/index.d.ts.map +0 -1
  117. package/dist/types/lib/AppData.d.ts.map +0 -1
  118. package/dist/types/lib/JsonFile.d.ts.map +0 -1
  119. package/dist/types/lib/LogFile.d.ts.map +0 -1
  120. package/dist/types/lib/absoluteToRelativePath.d.ts.map +0 -1
  121. package/dist/types/lib/appendLineToFile.d.ts.map +0 -1
  122. package/dist/types/lib/cleanDirectorySync.d.ts.map +0 -1
  123. package/dist/types/lib/createDirectory.d.ts.map +0 -1
  124. package/dist/types/lib/createDirectorySync.d.ts.map +0 -1
  125. package/dist/types/lib/createFileExtensionFilter.d.ts.map +0 -1
  126. package/dist/types/lib/cwdpath.d.ts.map +0 -1
  127. package/dist/types/lib/deleteDirectory.d.ts.map +0 -1
  128. package/dist/types/lib/deleteDirectorySafe.d.ts.map +0 -1
  129. package/dist/types/lib/deleteDirectorySafeSync.d.ts.map +0 -1
  130. package/dist/types/lib/deleteDirectorySync.d.ts.map +0 -1
  131. package/dist/types/lib/ensureValidWindowsPath.d.ts.map +0 -1
  132. package/dist/types/lib/getDiskDrivesWindows.d.ts.map +0 -1
  133. package/dist/types/lib/getDownloadsDirectory.d.ts.map +0 -1
  134. package/dist/types/lib/getHomeDirectory.d.ts.map +0 -1
  135. package/dist/types/lib/getLastMofifiedFileIn.d.ts.map +0 -1
  136. package/dist/types/lib/getRootDir.d.ts.map +0 -1
  137. package/dist/types/lib/isWindows.d.ts.map +0 -1
  138. package/dist/types/lib/normalizeFileExtension.d.ts.map +0 -1
  139. package/dist/types/lib/readFileLastLines.d.ts.map +0 -1
  140. package/dist/types/lib/readJsonFile.d.ts.map +0 -1
  141. package/dist/types/lib/readJsonFileSync.d.ts.map +0 -1
  142. package/dist/types/lib/readPackageJson.d.ts.map +0 -1
  143. package/dist/types/lib/removeIllegalFilenameCharacters.d.ts.map +0 -1
  144. package/dist/types/lib/tempFile.d.ts.map +0 -1
  145. package/dist/types/lib/types/IEnsureValidWindowsPathOptions.d.ts.map +0 -1
  146. package/dist/types/lib/types/ILogFileData.d.ts.map +0 -1
  147. package/dist/types/lib/unzipFile.d.ts.map +0 -1
  148. package/dist/types/lib/unzipMergeFiles.d.ts.map +0 -1
  149. package/dist/types/lib/wipeDirectorySafe.d.ts.map +0 -1
  150. package/dist/types/lib/writeJsonFile.d.ts.map +0 -1
  151. package/dist/types/lib/writeJsonFileSync.d.ts.map +0 -1
  152. package/jest.config.ts +0 -13
  153. package/project.json +0 -30
  154. package/tsconfig.spec.json +0 -9
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDirectory = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ /**
7
+ * Create a directory at a given path if it does not exist.
8
+ * Automatically creates parent directories if they do not exist.
9
+ * @param dirpath The path where the directory should be created.
10
+ * @returns The path of the directory.
11
+ * @throws Will throw an error if the directory cannot be created.
12
+ * @example ```ts
13
+ * createDirectory('/path/to/directory').then((dirpath) => {
14
+ * //=> `Directory created at ${dirpath}`
15
+ * });
16
+ * ```
17
+ */
18
+ function createDirectory(dirpath) {
19
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
20
+ yield fs_1.default.promises.mkdir(dirpath, { recursive: true });
21
+ return dirpath;
22
+ });
23
+ }
24
+ exports.createDirectory = createDirectory;
25
+ //# sourceMappingURL=createDirectory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDirectory.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/createDirectory.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AACnB;;;;;;;;;;;GAWG;AACH,SAAsB,eAAe,CAAC,OAAe;;QACnD,MAAM,YAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QACrD,OAAO,OAAO,CAAA;IAChB,CAAC;CAAA;AAHD,0CAGC"}
@@ -8,4 +8,3 @@
8
8
  * ```
9
9
  */
10
10
  export declare function createDirectorySync(dirpath: string): string;
11
- //# sourceMappingURL=createDirectorySync.d.ts.map
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDirectorySync = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ /**
7
+ * Create a directory at a given path if it does not exist.
8
+ * Automatically creates parent directories if they do not exist.
9
+ * @param dirpath The path where the directory should be created.
10
+ * @returns The path of the directory.
11
+ * @example ```ts
12
+ * createDirectorySync('/path/to/directory')
13
+ * ```
14
+ */
15
+ function createDirectorySync(dirpath) {
16
+ fs_1.default.mkdirSync(dirpath, { recursive: true });
17
+ return dirpath;
18
+ }
19
+ exports.createDirectorySync = createDirectorySync;
20
+ //# sourceMappingURL=createDirectorySync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDirectorySync.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/createDirectorySync.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AAEnB;;;;;;;;GAQG;AACH,SAAgB,mBAAmB,CAAC,OAAe;IACjD,YAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAC1C,OAAO,OAAO,CAAA;AAChB,CAAC;AAHD,kDAGC"}
@@ -11,4 +11,3 @@
11
11
  * ```
12
12
  */
13
13
  export declare function createFileExtensionFilter(...fileExtensions: string[]): (filepath: string) => boolean;
14
- //# sourceMappingURL=createFileExtensionFilter.d.ts.map
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFileExtensionFilter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const normalizeFileExtension_1 = require("./normalizeFileExtension");
7
+ /**
8
+ * 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.
9
+ * @remarks If no file extensions are provided, the filter will always return true.
10
+ * @returns A function that takes a filepath and returns true if the filepath has one of the specified file extensions, false otherwise.
11
+ * @param fileExtensions file extensions
12
+ * @example ```ts
13
+ * createFileExtensionFilter('.ts', '.tsx')('index.ts');;
14
+ * //=> true
15
+ * createFileExtensionFilter('.ts', '.tsx')('index.js');;
16
+ * //=> false
17
+ * ```
18
+ */
19
+ function createFileExtensionFilter(...fileExtensions) {
20
+ if (!fileExtensions.length)
21
+ return () => true;
22
+ return (filepath) => {
23
+ for (const ext of fileExtensions.map(normalizeFileExtension_1.normalizeFileExtension)) {
24
+ if (path_1.default.extname(filepath) === ext) {
25
+ return true;
26
+ }
27
+ }
28
+ return false;
29
+ };
30
+ }
31
+ exports.createFileExtensionFilter = createFileExtensionFilter;
32
+ //# sourceMappingURL=createFileExtensionFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFileExtensionFilter.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/createFileExtensionFilter.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,qEAAiE;AAEjE;;;;;;;;;;;GAWG;AACH,SAAgB,yBAAyB,CAAC,GAAG,cAAwB;IACnE,IAAI,CAAC,cAAc,CAAC,MAAM;QAAE,OAAO,GAAG,EAAE,CAAC,IAAI,CAAA;IAC7C,OAAO,CAAC,QAAgB,EAAE,EAAE;QAC1B,KAAK,MAAM,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,+CAAsB,CAAC,EAAE;YAC5D,IAAI,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,GAAG,EAAE;gBAClC,OAAO,IAAI,CAAA;aACZ;SACF;QACD,OAAO,KAAK,CAAA;IACd,CAAC,CAAA;AACH,CAAC;AAVD,8DAUC"}
@@ -10,4 +10,3 @@
10
10
  * ```
11
11
  */
12
12
  export declare function cwdpath(...paths: string[]): string;
13
- //# sourceMappingURL=cwdpath.d.ts.map
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cwdpath = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ /**
7
+ * Joins the given path segments to the current working directory path, and normalizes the resulting path.
8
+ * @remarks
9
+ * The function uses the `path.join` method from the Node.js `path` module, and the `process.cwd` method from the Node.js `process` module.
10
+ * @param paths - The path segments to join to the current working directory path.
11
+ * @returns The resulting path.
12
+ * @example ```ts
13
+ * console.log(cwdpath('src', 'index.ts'));
14
+ * //=> '{working_directory}/src/index.ts'
15
+ * ```
16
+ */
17
+ function cwdpath(...paths) {
18
+ return path_1.default.join(process.cwd(), ...paths);
19
+ }
20
+ exports.cwdpath = cwdpath;
21
+ //# sourceMappingURL=cwdpath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cwdpath.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/cwdpath.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AAEvB;;;;;;;;;;GAUG;AACH,SAAgB,OAAO,CAAC,GAAG,KAAe;IACxC,OAAO,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC,CAAA;AAC3C,CAAC;AAFD,0BAEC"}
@@ -10,4 +10,3 @@
10
10
  * ```
11
11
  */
12
12
  export declare function deleteDirectory(dirpath: string): Promise<void>;
13
- //# sourceMappingURL=deleteDirectory.d.ts.map
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteDirectory = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ /**
7
+ * Deletes a directory and all of its contents.
8
+ * @remarks This function uses Node.js's `fs.promises.rm` method with the `recursive` and `force` options set to `true`.
9
+ * This means it will delete the directory and all of its contents, even if the directory is not empty.
10
+ * @param dirpath The path to the directory to delete.
11
+ * @returns A Promise that resolves when the directory has been deleted.
12
+ * @throws Will throw an error if the directory does not exist, or if there was a problem deleting the directory.
13
+ * @example ```ts
14
+ * deleteDirectory('/path/to/directory');
15
+ * ```
16
+ */
17
+ function deleteDirectory(dirpath) {
18
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
19
+ yield fs_1.default.promises.rm(dirpath, { recursive: true, force: true });
20
+ });
21
+ }
22
+ exports.deleteDirectory = deleteDirectory;
23
+ //# sourceMappingURL=deleteDirectory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteDirectory.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/deleteDirectory.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AAEnB;;;;;;;;;;GAUG;AACH,SAAsB,eAAe,CAAC,OAAe;;QACnD,MAAM,YAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IACjE,CAAC;CAAA;AAFD,0CAEC"}
@@ -11,4 +11,3 @@
11
11
  * ```
12
12
  */
13
13
  export declare function deleteDirectorySafe(dirpath: string): Promise<void>;
14
- //# sourceMappingURL=deleteDirectorySafe.d.ts.map
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteDirectorySafe = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ /**
7
+ * Deletes a directory safely if it exists.
8
+ * @remarks This function uses Node.js' `fs.promises.rm` method with the `recursive` and `force` options set to `true`.
9
+ * This means it will delete the directory and all its contents, even if the directory is not empty.
10
+ * @param dirpath The path of the directory to delete.
11
+ * @returns A promise that resolves to `void` when the directory has been deleted.
12
+ * @throws Will throw an error if the `fs.promises.rm` operation fails.
13
+ * @example ```ts
14
+ * deleteDirectorySafe('/path/to/directory');;
15
+ * //=> undefined
16
+ * ```
17
+ */
18
+ function deleteDirectorySafe(dirpath) {
19
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
20
+ if (fs_1.default.existsSync(dirpath))
21
+ yield fs_1.default.promises.rm(dirpath, { recursive: true, force: true });
22
+ });
23
+ }
24
+ exports.deleteDirectorySafe = deleteDirectorySafe;
25
+ //# sourceMappingURL=deleteDirectorySafe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteDirectorySafe.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/deleteDirectorySafe.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AAEnB;;;;;;;;;;;GAWG;AACH,SAAsB,mBAAmB,CAAC,OAAe;;QACvD,IAAI,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC;YAAE,MAAM,YAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAC7F,CAAC;CAAA;AAFD,kDAEC"}
@@ -9,4 +9,3 @@
9
9
  * ```
10
10
  */
11
11
  export declare function deleteDirectorySafeSync(dirpath: string): string;
12
- //# sourceMappingURL=deleteDirectorySafeSync.d.ts.map
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteDirectorySafeSync = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ /**
7
+ * 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.
8
+ * @param dirpath The path of the directory to be deleted.
9
+ * @returns The path of the directory that was intended to be deleted.
10
+ * @throws Will throw an error if the operation fails for reasons other than the directory not existing.
11
+ * @example ```ts
12
+ * deleteDirectorySafeSync('/path/to/directory');;
13
+ * //=> undefined
14
+ * ```
15
+ */
16
+ function deleteDirectorySafeSync(dirpath) {
17
+ if (!fs_1.default.existsSync(dirpath))
18
+ return dirpath;
19
+ fs_1.default.rmSync(dirpath, { recursive: true, force: true });
20
+ return dirpath;
21
+ }
22
+ exports.deleteDirectorySafeSync = deleteDirectorySafeSync;
23
+ //# sourceMappingURL=deleteDirectorySafeSync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteDirectorySafeSync.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/deleteDirectorySafeSync.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AAEnB;;;;;;;;;GASG;AACH,SAAgB,uBAAuB,CAAC,OAAe;IACrD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAA;IAC3C,YAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IACpD,OAAO,OAAO,CAAA;AAChB,CAAC;AAJD,0DAIC"}
@@ -10,4 +10,3 @@
10
10
  * ```
11
11
  */
12
12
  export declare function deleteDirectorySync(dirpath: string): string;
13
- //# sourceMappingURL=deleteDirectorySync.d.ts.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteDirectorySync = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ /**
7
+ * Deletes a directory synchronously.
8
+ * @remarks This function uses Node.js's `fs.rmSync` method with the options `{ recursive: true, force: true }`.
9
+ * @param dirpath The path of the directory to delete.
10
+ * @returns The path of the deleted directory.
11
+ * @throws Will throw an error if the directory does not exist or if the process lacks permissions to delete it.
12
+ * @example ```ts
13
+ * deleteDirectorySync('/path/to/directory');;
14
+ * //=> undefined
15
+ * ```
16
+ */
17
+ function deleteDirectorySync(dirpath) {
18
+ fs_1.default.rmSync(dirpath, { recursive: true, force: true });
19
+ return dirpath;
20
+ }
21
+ exports.deleteDirectorySync = deleteDirectorySync;
22
+ //# sourceMappingURL=deleteDirectorySync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteDirectorySync.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/deleteDirectorySync.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AAEnB;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CAAC,OAAe;IACjD,YAAE,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IACpD,OAAO,OAAO,CAAA;AAChB,CAAC;AAHD,kDAGC"}
@@ -20,4 +20,3 @@ import { IEnsureValidWindowsPathOptions } from './types/IEnsureValidWindowsPathO
20
20
  * ```
21
21
  */
22
22
  export declare function ensureValidWindowsPath(path: string, options?: IEnsureValidWindowsPathOptions): boolean;
23
- //# sourceMappingURL=ensureValidWindowsPath.d.ts.map
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureValidWindowsPath = void 0;
4
+ /**
5
+ * Check whether a provided windows filesystem path string is valid according to:
6
+ * https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
7
+ * @param path The path to validate.
8
+ * @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.
9
+ * @throws Will throw an error if the `assert` option is true and the path is invalid.
10
+ * @param options An optional object that may contain the following properties:
11
+ * - `assert`: If true, the function will throw an error if the path is invalid. Default is false.
12
+ * - `extendedMaxLength`: If true, the function will allow paths up to 32767 characters long. Default is false.
13
+ * @example ```ts
14
+ * ensureValidWindowsPath('C:\\Users\\User\\Documents\\file.txt');;
15
+ * //=> true
16
+ * ensureValidWindowsPath('C:/Users/User/Documents/file.txt');;
17
+ * //=> false
18
+ * ensureValidWindowsPath('C:\\Users\\User\\Documents\\file.txt', { assert: true });;
19
+ * //=> throws an error
20
+ * ensureValidWindowsPath('C:\\Users\\User\\Documents\\file.txt', { extendedMaxLength: true });;
21
+ * //=> true
22
+ * ```
23
+ */
24
+ function ensureValidWindowsPath(path, options) {
25
+ const throwOrFalse = (msg) => {
26
+ if (options && options.assert === true) {
27
+ throw new Error(`Invalid windows path. ${msg} | input received: ${path}`);
28
+ }
29
+ return false;
30
+ };
31
+ if (path.length === 0) {
32
+ return throwOrFalse('Path string is length 0.');
33
+ }
34
+ if (path.indexOf('/') !== -1 && path.indexOf('\\') !== -1) {
35
+ return throwOrFalse('Path contains both backslash and forward slash.');
36
+ }
37
+ const maxLength = (options && options.extendedMaxLength ? 32767 : 260) - 12;
38
+ if (path.length > maxLength) {
39
+ return throwOrFalse(`Maximum length of ${maxLength} exceeded`);
40
+ }
41
+ let noDriveLetter = path;
42
+ if (/^\w:(\\|\/)/g.test(path)) {
43
+ noDriveLetter = path.substring(2);
44
+ }
45
+ if (/[<>"|?*:]/g.test(noDriveLetter)) {
46
+ return throwOrFalse(`Illegal characters in: ${path} | Illegal characters are: <>"|?:*`);
47
+ }
48
+ if (/(\\|\/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])((\\|\/)|$)/g.test(path)) {
49
+ return throwOrFalse('Illegal name in path string');
50
+ }
51
+ return true;
52
+ }
53
+ exports.ensureValidWindowsPath = ensureValidWindowsPath;
54
+ //# sourceMappingURL=ensureValidWindowsPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureValidWindowsPath.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/ensureValidWindowsPath.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,sBAAsB,CAAC,IAAY,EAAE,OAAwC;IAC3F,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,EAAE;QACnC,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,IAAI,EAAE;YACtC,MAAM,IAAI,KAAK,CAAC,yBAAyB,GAAG,wBAAwB,IAAI,EAAE,CAAC,CAAA;SAC5E;QACD,OAAO,KAAK,CAAA;IACd,CAAC,CAAA;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACrB,OAAO,YAAY,CAAC,0BAA0B,CAAC,CAAA;KAChD;IAED,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE;QACzD,OAAO,YAAY,CAAC,iDAAiD,CAAC,CAAA;KACvE;IAED,MAAM,SAAS,GAAG,CAAC,OAAO,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;IAC3E,IAAI,IAAI,CAAC,MAAM,GAAG,SAAS,EAAE;QAC3B,OAAO,YAAY,CAAC,qBAAqB,SAAS,WAAW,CAAC,CAAA;KAC/D;IAED,IAAI,aAAa,GAAG,IAAI,CAAA;IACxB,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC7B,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;KAClC;IACD,IAAI,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE;QACpC,OAAO,YAAY,CAAC,0BAA0B,IAAI,sCAAsC,CAAC,CAAA;KAC1F;IAED,IAAI,wDAAwD,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACvE,OAAO,YAAY,CAAC,6BAA6B,CAAC,CAAA;KACnD;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAlCD,wDAkCC"}
@@ -1,2 +1 @@
1
1
  export declare function getDiskDrivesWindows(): string[];
2
- //# sourceMappingURL=getDiskDrivesWindows.d.ts.map
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDiskDrivesWindows = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const child_process_1 = require("child_process");
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const isWindows_1 = require("./isWindows");
8
+ function getDiskDrivesWindows() {
9
+ if (!(0, isWindows_1.isWindows)())
10
+ throw new Error('This function is only available on Windows.');
11
+ return (0, child_process_1.execSync)('wmic logicaldisk get name')
12
+ .toString()
13
+ .split('\n')
14
+ .map((s) => s.trim())
15
+ .filter((s) => /^[a-z]:/i.test(s))
16
+ .map((s) => s.substring(0, 2) + path_1.default.sep);
17
+ }
18
+ exports.getDiskDrivesWindows = getDiskDrivesWindows;
19
+ //# sourceMappingURL=getDiskDrivesWindows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDiskDrivesWindows.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/getDiskDrivesWindows.ts"],"names":[],"mappings":";;;;AAAA,iDAAwC;AACxC,wDAAuB;AACvB,2CAAuC;AAEvC,SAAgB,oBAAoB;IAClC,IAAI,CAAC,IAAA,qBAAS,GAAE;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAChF,OAAO,IAAA,wBAAQ,EAAC,2BAA2B,CAAC;SACzC,QAAQ,EAAE;SACV,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,cAAI,CAAC,GAAG,CAAC,CAAA;AAC7C,CAAC;AARD,oDAQC"}
@@ -1,2 +1 @@
1
1
  export declare function getDownloadsDirectory(): string;
2
- //# sourceMappingURL=getDownloadsDirectory.d.ts.map
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDownloadsDirectory = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const getHomeDirectory_1 = require("./getHomeDirectory");
7
+ function getDownloadsDirectory() {
8
+ return path_1.default.join((0, getHomeDirectory_1.getHomeDirectory)(), 'Downloads');
9
+ }
10
+ exports.getDownloadsDirectory = getDownloadsDirectory;
11
+ //# sourceMappingURL=getDownloadsDirectory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDownloadsDirectory.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/getDownloadsDirectory.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AACvB,yDAAqD;AAErD,SAAgB,qBAAqB;IACnC,OAAO,cAAI,CAAC,IAAI,CAAC,IAAA,mCAAgB,GAAE,EAAE,WAAW,CAAC,CAAA;AACnD,CAAC;AAFD,sDAEC"}
@@ -1,2 +1 @@
1
1
  export declare function getHomeDirectory(): string;
2
- //# sourceMappingURL=getHomeDirectory.d.ts.map
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHomeDirectory = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ function getHomeDirectory() {
7
+ const home = path_1.default.resolve(process.env['HOME'] || process.env['USERPROFILE'] || '');
8
+ if (!home)
9
+ throw new Error('Home directory not found');
10
+ return home;
11
+ }
12
+ exports.getHomeDirectory = getHomeDirectory;
13
+ //# sourceMappingURL=getHomeDirectory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getHomeDirectory.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/getHomeDirectory.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AAEvB,SAAgB,gBAAgB;IAC9B,MAAM,IAAI,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAA;IAClF,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;IACtD,OAAO,IAAI,CAAA;AACb,CAAC;AAJD,4CAIC"}
@@ -1,2 +1 @@
1
1
  export declare function getLastMofifiedFileIn(dirpath: string): Promise<string>;
2
- //# sourceMappingURL=getLastMofifiedFileIn.d.ts.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLastMofifiedFileIn = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ function getLastMofifiedFileIn(dirpath) {
8
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
+ const children = yield fs_1.default.promises.readdir(dirpath);
10
+ const filtered = children
11
+ .map((fname) => {
12
+ const fpath = path_1.default.join(dirpath, fname);
13
+ const stat = fs_1.default.statSync(fpath);
14
+ return [fpath, stat.mtimeMs, stat.isFile()];
15
+ })
16
+ .filter((a) => a[2]);
17
+ const sorted = filtered.sort((a, b) => b[1] - a[1]);
18
+ return sorted[0][0];
19
+ });
20
+ }
21
+ exports.getLastMofifiedFileIn = getLastMofifiedFileIn;
22
+ //# sourceMappingURL=getLastMofifiedFileIn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLastMofifiedFileIn.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/getLastMofifiedFileIn.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AACnB,wDAAuB;AAEvB,SAAsB,qBAAqB,CAAC,OAAe;;QACzD,MAAM,QAAQ,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QACnD,MAAM,QAAQ,GAAG,QAAQ;aACtB,GAAG,CAAC,CAAC,KAAa,EAAE,EAAE;YACrB,MAAM,KAAK,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;YACvC,MAAM,IAAI,GAAG,YAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;YAC/B,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;QAC7C,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAgC,CAAA;QACrD,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACnD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACrB,CAAC;CAAA;AAXD,sDAWC"}
@@ -1,2 +1 @@
1
1
  export declare function getRootDir(): string;
2
- //# sourceMappingURL=getRootDir.d.ts.map
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRootDir = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ function getRootDir() {
7
+ return path_1.default.parse(process.cwd()).root;
8
+ }
9
+ exports.getRootDir = getRootDir;
10
+ //# sourceMappingURL=getRootDir.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRootDir.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/getRootDir.ts"],"names":[],"mappings":";;;;AAAA,wDAAuB;AAEvB,SAAgB,UAAU;IACxB,OAAO,cAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAA;AACvC,CAAC;AAFD,gCAEC"}
@@ -1,2 +1 @@
1
1
  export declare function isWindows(): boolean;
2
- //# sourceMappingURL=isWindows.d.ts.map
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWindows = void 0;
4
+ function isWindows() {
5
+ return process.platform.includes('win');
6
+ }
7
+ exports.isWindows = isWindows;
8
+ //# sourceMappingURL=isWindows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isWindows.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/isWindows.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS;IACvB,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AACzC,CAAC;AAFD,8BAEC"}
@@ -20,4 +20,3 @@
20
20
  * ```
21
21
  */
22
22
  export declare function normalizeFileExtension(ext: string): string;
23
- //# sourceMappingURL=normalizeFileExtension.d.ts.map
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeFileExtension = void 0;
4
+ /**
5
+ * Normalize a file extension to the form: .[ext]
6
+ * Anything before the last "." is not returned.
7
+ * @returns The normalized file extension.
8
+ * @throws If the extension contains illegal characters.
9
+ * @param ext file extension
10
+ * @example ```ts
11
+ * normalizeFileExtension('jpg');;
12
+ * //=> '.jpg'
13
+ * normalizeFileExtension('.jpg');;
14
+ * //=> '.jpg'
15
+ * normalizeFileExtension('..jpg');;
16
+ * //=> '.jpg'
17
+ * normalizeFileExtension('');;
18
+ * //=> ''
19
+ * normalizeFileExtension('.');;
20
+ * //=> ''
21
+ * normalizeFileExtension('jpg|png');;
22
+ * //=> Error
23
+ * ```
24
+ */
25
+ function normalizeFileExtension(ext) {
26
+ if (ext === '' || ext === '.')
27
+ return '';
28
+ if (/[<>"|?*:]/g.test(ext)) {
29
+ throw new Error(`Illegal characters in file extension: ${ext} | Illegal characters are: <>"|?:*`);
30
+ }
31
+ if (!ext.includes('.'))
32
+ return '.' + ext;
33
+ return ext.substring(ext.lastIndexOf('.'));
34
+ }
35
+ exports.normalizeFileExtension = normalizeFileExtension;
36
+ //# sourceMappingURL=normalizeFileExtension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeFileExtension.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/normalizeFileExtension.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,sBAAsB,CAAC,GAAW;IAChD,IAAI,GAAG,KAAK,EAAE,IAAI,GAAG,KAAK,GAAG;QAAE,OAAO,EAAE,CAAA;IACxC,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,yCAAyC,GAAG,sCAAsC,CAAC,CAAA;KACpG;IACD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,GAAG,GAAG,CAAA;IACxC,OAAO,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAA;AAC5C,CAAC;AAPD,wDAOC"}
@@ -1,10 +1,7 @@
1
- /// <reference types="node" />
2
1
  /**
3
2
  * Read the last n lines of a file.
4
3
  * @param filepath The path to the file.
5
4
  * @param n The number of lines to read.
6
- * @param encoding The encoding of the file.
7
5
  * @example await readLastLines.read('path/to/file.log', 50)
8
6
  */
9
- export declare function readFileLastLines(filepath: string, n: number, encoding?: NodeJS.BufferEncoding): Promise<string>;
10
- //# sourceMappingURL=readFileLastLines.d.ts.map
7
+ export declare function readFileLastLines(filepath: string, n: number): Promise<string>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readFileLastLines = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const read_last_lines_1 = tslib_1.__importDefault(require("read-last-lines"));
6
+ /**
7
+ * Read the last n lines of a file.
8
+ * @param filepath The path to the file.
9
+ * @param n The number of lines to read.
10
+ * @example await readLastLines.read('path/to/file.log', 50)
11
+ */
12
+ function readFileLastLines(filepath, n) {
13
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
+ return yield read_last_lines_1.default.read(filepath, n, 'utf8');
15
+ });
16
+ }
17
+ exports.readFileLastLines = readFileLastLines;
18
+ //# sourceMappingURL=readFileLastLines.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readFileLastLines.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/readFileLastLines.ts"],"names":[],"mappings":";;;;AAAA,8EAA2C;AAE3C;;;;;GAKG;AACH,SAAsB,iBAAiB,CAAC,QAAgB,EAAE,CAAS;;QACjE,OAAO,MAAM,yBAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;IACtD,CAAC;CAAA;AAFD,8CAEC"}
@@ -10,4 +10,3 @@
10
10
  * ```
11
11
  */
12
12
  export declare function readJsonFile<T>(filepath: string): Promise<T>;
13
- //# sourceMappingURL=readJsonFile.d.ts.map
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readJsonFile = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ /**
7
+ * Reads a JSON file from the given filepath and returns its content as a Promise.
8
+ * The Promise will resolve with the parsed JSON content as an object of type T.
9
+ * @template T The expected return type of the JSON object.
10
+ * @param filepath The path to the JSON file to read.
11
+ * @returns A Promise that resolves with the parsed JSON content as an object of type T.
12
+ * @throws Will throw an error if reading the file fails for any reason.
13
+ * @example ```ts
14
+ * const data: MyType = await readJsonFile<MyType>('path/to/myfile.json');
15
+ * ```
16
+ */
17
+ function readJsonFile(filepath) {
18
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
19
+ return JSON.parse(yield fs_1.default.promises.readFile(filepath, 'utf8'));
20
+ });
21
+ }
22
+ exports.readJsonFile = readJsonFile;
23
+ //# sourceMappingURL=readJsonFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readJsonFile.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/readJsonFile.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AAEnB;;;;;;;;;;GAUG;AACH,SAAsB,YAAY,CAAI,QAAgB;;QACpD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;IACjE,CAAC;CAAA;AAFD,oCAEC"}
@@ -10,4 +10,3 @@
10
10
  * ```
11
11
  */
12
12
  export declare function readJsonFileSync<T>(filepath: string): T;
13
- //# sourceMappingURL=readJsonFileSync.d.ts.map