@bemoje/fs 0.0.2 → 0.0.3
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/README.md +901 -3
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/types/index.d.ts +30 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/lib/absoluteToRelativePath.d.ts +14 -0
- 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/dist/types/lib/cleanDirectorySync.d.ts +17 -0
- package/dist/types/lib/cleanDirectorySync.d.ts.map +1 -0
- package/dist/types/lib/createDirectory.d.ts +14 -0
- package/dist/types/lib/createDirectory.d.ts.map +1 -0
- package/dist/types/lib/createDirectorySync.d.ts +11 -0
- package/dist/types/lib/createDirectorySync.d.ts.map +1 -0
- package/dist/types/lib/createFileExtensionFilter.d.ts +14 -0
- package/dist/types/lib/createFileExtensionFilter.d.ts.map +1 -0
- package/dist/types/lib/cwdpath.d.ts +13 -0
- package/dist/types/lib/cwdpath.d.ts.map +1 -0
- package/dist/types/lib/deleteDirectory.d.ts +13 -0
- package/dist/types/lib/deleteDirectory.d.ts.map +1 -0
- package/dist/types/lib/deleteDirectorySafe.d.ts +14 -0
- package/dist/types/lib/deleteDirectorySafe.d.ts.map +1 -0
- package/dist/types/lib/deleteDirectorySafeSync.d.ts +12 -0
- package/dist/types/lib/deleteDirectorySafeSync.d.ts.map +1 -0
- package/dist/types/lib/deleteDirectorySync.d.ts +13 -0
- package/dist/types/lib/deleteDirectorySync.d.ts.map +1 -0
- package/dist/types/lib/ensureValidWindowsPath.d.ts +23 -0
- 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/dist/types/lib/normalizeFileExtension.d.ts +23 -0
- package/dist/types/lib/normalizeFileExtension.d.ts.map +1 -0
- package/dist/types/lib/readJsonFile.d.ts +13 -0
- package/dist/types/lib/readJsonFile.d.ts.map +1 -0
- package/dist/types/lib/readJsonFileSync.d.ts +13 -0
- 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/types/IEnsureValidWindowsPathOptions.d.ts +11 -0
- package/dist/types/lib/types/IEnsureValidWindowsPathOptions.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/dist/types/lib/writeJsonFile.d.ts +15 -0
- package/dist/types/lib/writeJsonFile.d.ts.map +1 -0
- package/dist/types/lib/writeJsonFileSync.d.ts +14 -0
- package/dist/types/lib/writeJsonFileSync.d.ts.map +1 -0
- package/package.json +4 -6
package/README.md
CHANGED
|
@@ -26,9 +26,6 @@ This library is published in the NPM registry and can be installed using any com
|
|
|
26
26
|
npm install @bemoje/fs
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
## Documentation
|
|
30
|
-
- [Markdown](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md)
|
|
31
|
-
- [HTML](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/html/index.html)
|
|
32
29
|
|
|
33
30
|
## Issues
|
|
34
31
|
Please let me know of any bugs or [issues](https://github.com/bemoje/https://github.com/bemoje/tsmono/issues).
|
|
@@ -38,3 +35,904 @@ Contributors are welcome to open a [pull request](https://github.com/bemoje/http
|
|
|
38
35
|
|
|
39
36
|
## License
|
|
40
37
|
Released under the [MIT License](./LICENSE).
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
- [HTML](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/html/index.html)
|
|
41
|
+
- [Markdown](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md)
|
|
42
|
+
|
|
43
|
+
### Interfaces
|
|
44
|
+
|
|
45
|
+
- [IEnsureValidWindowsPathOptions](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/interfaces/IEnsureValidWindowsPathOptions.md)
|
|
46
|
+
|
|
47
|
+
### Functions
|
|
48
|
+
|
|
49
|
+
- [absoluteToRelativePath](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#absolutetorelativepath)
|
|
50
|
+
- [appendLineToFile](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#appendlinetofile)
|
|
51
|
+
- [cleanDirectorySync](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#cleandirectorysync)
|
|
52
|
+
- [createDirectory](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#createdirectory)
|
|
53
|
+
- [createDirectorySync](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#createdirectorysync)
|
|
54
|
+
- [createFileExtensionFilter](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#createfileextensionfilter)
|
|
55
|
+
- [cwdpath](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#cwdpath)
|
|
56
|
+
- [deleteDirectory](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#deletedirectory)
|
|
57
|
+
- [deleteDirectorySafe](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#deletedirectorysafe)
|
|
58
|
+
- [deleteDirectorySafeSync](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#deletedirectorysafesync)
|
|
59
|
+
- [deleteDirectorySync](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#deletedirectorysync)
|
|
60
|
+
- [ensureValidWindowsPath](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#ensurevalidwindowspath)
|
|
61
|
+
- [getDiskDrivesWindows](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#getdiskdriveswindows)
|
|
62
|
+
- [getDownloadsDirectory](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#getdownloadsdirectory)
|
|
63
|
+
- [getHomeDirectory](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#gethomedirectory)
|
|
64
|
+
- [getLastMofifiedFileIn](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#getlastmofifiedfilein)
|
|
65
|
+
- [getRootDir](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#getrootdir)
|
|
66
|
+
- [isWindows](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#iswindows)
|
|
67
|
+
- [normalizeFileExtension](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#normalizefileextension)
|
|
68
|
+
- [readJsonFile](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#readjsonfile)
|
|
69
|
+
- [readJsonFileSync](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#readjsonfilesync)
|
|
70
|
+
- [readPackageJson](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#readpackagejson)
|
|
71
|
+
- [removeIllegalFilenameCharacters](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#removeillegalfilenamecharacters)
|
|
72
|
+
- [unzipFile](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#unzipfile)
|
|
73
|
+
- [unzipMergeFiles](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#unzipmergefiles)
|
|
74
|
+
- [wipeDirectorySafe](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#wipedirectorysafe)
|
|
75
|
+
- [writeJsonFile](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#writejsonfile)
|
|
76
|
+
- [writeJsonFileSync](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/index.md#writejsonfilesync)
|
|
77
|
+
|
|
78
|
+
## Functions
|
|
79
|
+
|
|
80
|
+
### absoluteToRelativePath
|
|
81
|
+
|
|
82
|
+
▸ **absoluteToRelativePath**(`absolute`, `workingDirectory?`): `string`
|
|
83
|
+
|
|
84
|
+
If the filepath is somewhere in the current working directory, it can be converted into a relative path.
|
|
85
|
+
|
|
86
|
+
#### Parameters
|
|
87
|
+
|
|
88
|
+
| Name | Type | Description |
|
|
89
|
+
| :------ | :------ | :------ |
|
|
90
|
+
| `absolute` | `string` | the absolute filepath to convert. |
|
|
91
|
+
| `workingDirectory` | `string` | The directory relative to which the path should be converted. Defaults to the current working directory. |
|
|
92
|
+
|
|
93
|
+
#### Returns
|
|
94
|
+
|
|
95
|
+
`string`
|
|
96
|
+
|
|
97
|
+
The relative path.
|
|
98
|
+
|
|
99
|
+
**`Remarks`**
|
|
100
|
+
|
|
101
|
+
This function takes an absolute path as input and returns a relative path. It replaces the current working directory in the path with an empty string,
|
|
102
|
+
replaces all backslashes with forward slashes, and removes any leading forward slashes.
|
|
103
|
+
|
|
104
|
+
**`Example`**
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
absoluteToRelativePath(__filename)
|
|
108
|
+
//=> 'src/absoluteToRelativePath.ts'
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### Defined in
|
|
112
|
+
|
|
113
|
+
[lib/absoluteToRelativePath.ts:16](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/absoluteToRelativePath.ts#L16)
|
|
114
|
+
|
|
115
|
+
___
|
|
116
|
+
|
|
117
|
+
### appendLineToFile
|
|
118
|
+
|
|
119
|
+
▸ **appendLineToFile**(`filepath`, `line`, `linebreakBefore?`): `Promise`<`void`\>
|
|
120
|
+
|
|
121
|
+
Append a line to a file. Creates the file if it does not exist.
|
|
122
|
+
|
|
123
|
+
#### Parameters
|
|
124
|
+
|
|
125
|
+
| Name | Type | Default value | Description |
|
|
126
|
+
| :------ | :------ | :------ | :------ |
|
|
127
|
+
| `filepath` | `string` | `undefined` | The path of the file. |
|
|
128
|
+
| `line` | `string` | `undefined` | The string data to append. |
|
|
129
|
+
| `linebreakBefore` | `boolean` | `false` | - |
|
|
130
|
+
|
|
131
|
+
#### Returns
|
|
132
|
+
|
|
133
|
+
`Promise`<`void`\>
|
|
134
|
+
|
|
135
|
+
A Promise that resolves when the line has been appended to the file.
|
|
136
|
+
|
|
137
|
+
**`Throws`**
|
|
138
|
+
|
|
139
|
+
Will throw an error if the operation fails.
|
|
140
|
+
|
|
141
|
+
**`Example`**
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
await appendLineToFile('/path/to/file', 'This is a new line')
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Defined in
|
|
148
|
+
|
|
149
|
+
[lib/appendLineToFile.ts:15](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/appendLineToFile.ts#L15)
|
|
150
|
+
|
|
151
|
+
___
|
|
152
|
+
|
|
153
|
+
### cleanDirectorySync
|
|
154
|
+
|
|
155
|
+
▸ **cleanDirectorySync**(`dirpath`, `predicate`): `void`
|
|
156
|
+
|
|
157
|
+
Synchronously cleans a directory by removing files that satisfy a given predicate.
|
|
158
|
+
|
|
159
|
+
#### Parameters
|
|
160
|
+
|
|
161
|
+
| Name | Type | Description |
|
|
162
|
+
| :------ | :------ | :------ |
|
|
163
|
+
| `dirpath` | `string` | The path to the directory that needs to be cleaned. |
|
|
164
|
+
| `predicate` | (`filepath`: `string`, `stat`: `Stats`) => `boolean` | 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. |
|
|
165
|
+
|
|
166
|
+
#### Returns
|
|
167
|
+
|
|
168
|
+
`void`
|
|
169
|
+
|
|
170
|
+
**`Remarks`**
|
|
171
|
+
|
|
172
|
+
This function is a part of the File System module.
|
|
173
|
+
|
|
174
|
+
**`Throws`**
|
|
175
|
+
|
|
176
|
+
If the directory at the provided path does not exist or cannot be read.
|
|
177
|
+
|
|
178
|
+
**`Example`**
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
import { Stats } from 'fs';
|
|
182
|
+
const dirpath = './my-directory';
|
|
183
|
+
const predicate = (filepath: string, stat: Stats) => stat.size > 1024;
|
|
184
|
+
cleanDirectorySync(dirpath, predicate);
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### Defined in
|
|
188
|
+
|
|
189
|
+
[lib/cleanDirectorySync.ts:18](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/cleanDirectorySync.ts#L18)
|
|
190
|
+
|
|
191
|
+
___
|
|
192
|
+
|
|
193
|
+
### createDirectory
|
|
194
|
+
|
|
195
|
+
▸ **createDirectory**(`dirpath`): `Promise`<`string`\>
|
|
196
|
+
|
|
197
|
+
Create a directory at a given path if it does not exist.
|
|
198
|
+
Automatically creates parent directories if they do not exist.
|
|
199
|
+
|
|
200
|
+
#### Parameters
|
|
201
|
+
|
|
202
|
+
| Name | Type | Description |
|
|
203
|
+
| :------ | :------ | :------ |
|
|
204
|
+
| `dirpath` | `string` | The path where the directory should be created. |
|
|
205
|
+
|
|
206
|
+
#### Returns
|
|
207
|
+
|
|
208
|
+
`Promise`<`string`\>
|
|
209
|
+
|
|
210
|
+
The path of the directory.
|
|
211
|
+
|
|
212
|
+
**`Throws`**
|
|
213
|
+
|
|
214
|
+
Will throw an error if the directory cannot be created.
|
|
215
|
+
|
|
216
|
+
**`Example`**
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
createDirectory('/path/to/directory').then((dirpath) => {
|
|
220
|
+
//=> `Directory created at ${dirpath}`
|
|
221
|
+
});
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### Defined in
|
|
225
|
+
|
|
226
|
+
[lib/createDirectory.ts:14](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/createDirectory.ts#L14)
|
|
227
|
+
|
|
228
|
+
___
|
|
229
|
+
|
|
230
|
+
### createDirectorySync
|
|
231
|
+
|
|
232
|
+
▸ **createDirectorySync**(`dirpath`): `string`
|
|
233
|
+
|
|
234
|
+
Create a directory at a given path if it does not exist.
|
|
235
|
+
Automatically creates parent directories if they do not exist.
|
|
236
|
+
|
|
237
|
+
#### Parameters
|
|
238
|
+
|
|
239
|
+
| Name | Type | Description |
|
|
240
|
+
| :------ | :------ | :------ |
|
|
241
|
+
| `dirpath` | `string` | The path where the directory should be created. |
|
|
242
|
+
|
|
243
|
+
#### Returns
|
|
244
|
+
|
|
245
|
+
`string`
|
|
246
|
+
|
|
247
|
+
The path of the directory.
|
|
248
|
+
|
|
249
|
+
**`Example`**
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
createDirectorySync('/path/to/directory')
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
#### Defined in
|
|
256
|
+
|
|
257
|
+
[lib/createDirectorySync.ts:12](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/createDirectorySync.ts#L12)
|
|
258
|
+
|
|
259
|
+
___
|
|
260
|
+
|
|
261
|
+
### createFileExtensionFilter
|
|
262
|
+
|
|
263
|
+
▸ **createFileExtensionFilter**(`...fileExtensions`): (`filepath`: `string`) => `boolean`
|
|
264
|
+
|
|
265
|
+
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.
|
|
266
|
+
|
|
267
|
+
#### Parameters
|
|
268
|
+
|
|
269
|
+
| Name | Type | Description |
|
|
270
|
+
| :------ | :------ | :------ |
|
|
271
|
+
| `...fileExtensions` | `string`[] | file extensions |
|
|
272
|
+
|
|
273
|
+
#### Returns
|
|
274
|
+
|
|
275
|
+
`fn`
|
|
276
|
+
|
|
277
|
+
A function that takes a filepath and returns true if the filepath has one of the specified file extensions, false otherwise.
|
|
278
|
+
|
|
279
|
+
▸ (`filepath`): `boolean`
|
|
280
|
+
|
|
281
|
+
##### Parameters
|
|
282
|
+
|
|
283
|
+
| Name | Type |
|
|
284
|
+
| :------ | :------ |
|
|
285
|
+
| `filepath` | `string` |
|
|
286
|
+
|
|
287
|
+
##### Returns
|
|
288
|
+
|
|
289
|
+
`boolean`
|
|
290
|
+
|
|
291
|
+
**`Remarks`**
|
|
292
|
+
|
|
293
|
+
If no file extensions are provided, the filter will always return true.
|
|
294
|
+
|
|
295
|
+
**`Example`**
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
createFileExtensionFilter('.ts', '.tsx')('index.ts');;
|
|
299
|
+
//=> true
|
|
300
|
+
createFileExtensionFilter('.ts', '.tsx')('index.js');;
|
|
301
|
+
//=> false
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
#### Defined in
|
|
305
|
+
|
|
306
|
+
[lib/createFileExtensionFilter.ts:16](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/createFileExtensionFilter.ts#L16)
|
|
307
|
+
|
|
308
|
+
___
|
|
309
|
+
|
|
310
|
+
### cwdpath
|
|
311
|
+
|
|
312
|
+
▸ **cwdpath**(`...paths`): `string`
|
|
313
|
+
|
|
314
|
+
Joins the given path segments to the current working directory path, and normalizes the resulting path.
|
|
315
|
+
|
|
316
|
+
#### Parameters
|
|
317
|
+
|
|
318
|
+
| Name | Type | Description |
|
|
319
|
+
| :------ | :------ | :------ |
|
|
320
|
+
| `...paths` | `string`[] | The path segments to join to the current working directory path. |
|
|
321
|
+
|
|
322
|
+
#### Returns
|
|
323
|
+
|
|
324
|
+
`string`
|
|
325
|
+
|
|
326
|
+
The resulting path.
|
|
327
|
+
|
|
328
|
+
**`Remarks`**
|
|
329
|
+
|
|
330
|
+
The function uses the `path.join` method from the Node.js `path` module, and the `process.cwd` method from the Node.js `process` module.
|
|
331
|
+
|
|
332
|
+
**`Example`**
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
console.log(cwdpath('src', 'index.ts'));
|
|
336
|
+
//=> '{working_directory}/src/index.ts'
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
#### Defined in
|
|
340
|
+
|
|
341
|
+
[lib/cwdpath.ts:14](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/cwdpath.ts#L14)
|
|
342
|
+
|
|
343
|
+
___
|
|
344
|
+
|
|
345
|
+
### deleteDirectory
|
|
346
|
+
|
|
347
|
+
▸ **deleteDirectory**(`dirpath`): `Promise`<`void`\>
|
|
348
|
+
|
|
349
|
+
Deletes a directory and all of its contents.
|
|
350
|
+
|
|
351
|
+
#### Parameters
|
|
352
|
+
|
|
353
|
+
| Name | Type | Description |
|
|
354
|
+
| :------ | :------ | :------ |
|
|
355
|
+
| `dirpath` | `string` | The path to the directory to delete. |
|
|
356
|
+
|
|
357
|
+
#### Returns
|
|
358
|
+
|
|
359
|
+
`Promise`<`void`\>
|
|
360
|
+
|
|
361
|
+
A Promise that resolves when the directory has been deleted.
|
|
362
|
+
|
|
363
|
+
**`Remarks`**
|
|
364
|
+
|
|
365
|
+
This function uses Node.js's `fs.promises.rm` method with the `recursive` and `force` options set to `true`.
|
|
366
|
+
This means it will delete the directory and all of its contents, even if the directory is not empty.
|
|
367
|
+
|
|
368
|
+
**`Throws`**
|
|
369
|
+
|
|
370
|
+
Will throw an error if the directory does not exist, or if there was a problem deleting the directory.
|
|
371
|
+
|
|
372
|
+
**`Example`**
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
deleteDirectory('/path/to/directory');
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
#### Defined in
|
|
379
|
+
|
|
380
|
+
[lib/deleteDirectory.ts:14](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/deleteDirectory.ts#L14)
|
|
381
|
+
|
|
382
|
+
___
|
|
383
|
+
|
|
384
|
+
### deleteDirectorySafe
|
|
385
|
+
|
|
386
|
+
▸ **deleteDirectorySafe**(`dirpath`): `Promise`<`void`\>
|
|
387
|
+
|
|
388
|
+
Deletes a directory safely if it exists.
|
|
389
|
+
|
|
390
|
+
#### Parameters
|
|
391
|
+
|
|
392
|
+
| Name | Type | Description |
|
|
393
|
+
| :------ | :------ | :------ |
|
|
394
|
+
| `dirpath` | `string` | The path of the directory to delete. |
|
|
395
|
+
|
|
396
|
+
#### Returns
|
|
397
|
+
|
|
398
|
+
`Promise`<`void`\>
|
|
399
|
+
|
|
400
|
+
A promise that resolves to `void` when the directory has been deleted.
|
|
401
|
+
|
|
402
|
+
**`Remarks`**
|
|
403
|
+
|
|
404
|
+
This function uses Node.js' `fs.promises.rm` method with the `recursive` and `force` options set to `true`.
|
|
405
|
+
This means it will delete the directory and all its contents, even if the directory is not empty.
|
|
406
|
+
|
|
407
|
+
**`Throws`**
|
|
408
|
+
|
|
409
|
+
Will throw an error if the `fs.promises.rm` operation fails.
|
|
410
|
+
|
|
411
|
+
**`Example`**
|
|
412
|
+
|
|
413
|
+
```ts
|
|
414
|
+
deleteDirectorySafe('/path/to/directory');;
|
|
415
|
+
//=> undefined
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
#### Defined in
|
|
419
|
+
|
|
420
|
+
[lib/deleteDirectorySafe.ts:15](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/deleteDirectorySafe.ts#L15)
|
|
421
|
+
|
|
422
|
+
___
|
|
423
|
+
|
|
424
|
+
### deleteDirectorySafeSync
|
|
425
|
+
|
|
426
|
+
▸ **deleteDirectorySafeSync**(`dirpath`): `string`
|
|
427
|
+
|
|
428
|
+
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.
|
|
429
|
+
|
|
430
|
+
#### Parameters
|
|
431
|
+
|
|
432
|
+
| Name | Type | Description |
|
|
433
|
+
| :------ | :------ | :------ |
|
|
434
|
+
| `dirpath` | `string` | The path of the directory to be deleted. |
|
|
435
|
+
|
|
436
|
+
#### Returns
|
|
437
|
+
|
|
438
|
+
`string`
|
|
439
|
+
|
|
440
|
+
The path of the directory that was intended to be deleted.
|
|
441
|
+
|
|
442
|
+
**`Throws`**
|
|
443
|
+
|
|
444
|
+
Will throw an error if the operation fails for reasons other than the directory not existing.
|
|
445
|
+
|
|
446
|
+
**`Example`**
|
|
447
|
+
|
|
448
|
+
```ts
|
|
449
|
+
deleteDirectorySafeSync('/path/to/directory');;
|
|
450
|
+
//=> undefined
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
#### Defined in
|
|
454
|
+
|
|
455
|
+
[lib/deleteDirectorySafeSync.ts:13](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/deleteDirectorySafeSync.ts#L13)
|
|
456
|
+
|
|
457
|
+
___
|
|
458
|
+
|
|
459
|
+
### deleteDirectorySync
|
|
460
|
+
|
|
461
|
+
▸ **deleteDirectorySync**(`dirpath`): `string`
|
|
462
|
+
|
|
463
|
+
Deletes a directory synchronously.
|
|
464
|
+
|
|
465
|
+
#### Parameters
|
|
466
|
+
|
|
467
|
+
| Name | Type | Description |
|
|
468
|
+
| :------ | :------ | :------ |
|
|
469
|
+
| `dirpath` | `string` | The path of the directory to delete. |
|
|
470
|
+
|
|
471
|
+
#### Returns
|
|
472
|
+
|
|
473
|
+
`string`
|
|
474
|
+
|
|
475
|
+
The path of the deleted directory.
|
|
476
|
+
|
|
477
|
+
**`Remarks`**
|
|
478
|
+
|
|
479
|
+
This function uses Node.js's `fs.rmSync` method with the options `{ recursive: true, force: true }`.
|
|
480
|
+
|
|
481
|
+
**`Throws`**
|
|
482
|
+
|
|
483
|
+
Will throw an error if the directory does not exist or if the process lacks permissions to delete it.
|
|
484
|
+
|
|
485
|
+
**`Example`**
|
|
486
|
+
|
|
487
|
+
```ts
|
|
488
|
+
deleteDirectorySync('/path/to/directory');;
|
|
489
|
+
//=> undefined
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
#### Defined in
|
|
493
|
+
|
|
494
|
+
[lib/deleteDirectorySync.ts:14](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/deleteDirectorySync.ts#L14)
|
|
495
|
+
|
|
496
|
+
___
|
|
497
|
+
|
|
498
|
+
### ensureValidWindowsPath
|
|
499
|
+
|
|
500
|
+
▸ **ensureValidWindowsPath**(`path`, `options?`): `boolean`
|
|
501
|
+
|
|
502
|
+
Check whether a provided windows filesystem path string is valid according to:
|
|
503
|
+
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
|
|
504
|
+
|
|
505
|
+
#### Parameters
|
|
506
|
+
|
|
507
|
+
| Name | Type | Description |
|
|
508
|
+
| :------ | :------ | :------ |
|
|
509
|
+
| `path` | `string` | The path to validate. |
|
|
510
|
+
| `options?` | [`IEnsureValidWindowsPathOptions`](https://github.com/bemoje/tsmono/blob/main/pkg/fs/docs/md/interfaces/IEnsureValidWindowsPathOptions.md) | An optional object that may contain the following properties: - `assert`: If true, the function will throw an error if the path is invalid. Default is false. - `extendedMaxLength`: If true, the function will allow paths up to 32767 characters long. Default is false. |
|
|
511
|
+
|
|
512
|
+
#### Returns
|
|
513
|
+
|
|
514
|
+
`boolean`
|
|
515
|
+
|
|
516
|
+
A boolean indicating whether the path is valid. If the `assert` option is true, the function will throw an error instead of returning false.
|
|
517
|
+
|
|
518
|
+
**`Throws`**
|
|
519
|
+
|
|
520
|
+
Will throw an error if the `assert` option is true and the path is invalid.
|
|
521
|
+
|
|
522
|
+
**`Example`**
|
|
523
|
+
|
|
524
|
+
```ts
|
|
525
|
+
ensureValidWindowsPath('C:\\Users\\User\\Documents\\file.txt');;
|
|
526
|
+
//=> true
|
|
527
|
+
ensureValidWindowsPath('C:/Users/User/Documents/file.txt');;
|
|
528
|
+
//=> false
|
|
529
|
+
ensureValidWindowsPath('C:\\Users\\User\\Documents\\file.txt', { assert: true });;
|
|
530
|
+
//=> throws an error
|
|
531
|
+
ensureValidWindowsPath('C:\\Users\\User\\Documents\\file.txt', { extendedMaxLength: true });;
|
|
532
|
+
//=> true
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
#### Defined in
|
|
536
|
+
|
|
537
|
+
[lib/ensureValidWindowsPath.ts:23](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/ensureValidWindowsPath.ts#L23)
|
|
538
|
+
|
|
539
|
+
___
|
|
540
|
+
|
|
541
|
+
### getDiskDrivesWindows
|
|
542
|
+
|
|
543
|
+
▸ **getDiskDrivesWindows**(): `string`[]
|
|
544
|
+
|
|
545
|
+
#### Returns
|
|
546
|
+
|
|
547
|
+
`string`[]
|
|
548
|
+
|
|
549
|
+
#### Defined in
|
|
550
|
+
|
|
551
|
+
[lib/getDiskDrivesWindows.ts:5](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/getDiskDrivesWindows.ts#L5)
|
|
552
|
+
|
|
553
|
+
___
|
|
554
|
+
|
|
555
|
+
### getDownloadsDirectory
|
|
556
|
+
|
|
557
|
+
▸ **getDownloadsDirectory**(): `string`
|
|
558
|
+
|
|
559
|
+
#### Returns
|
|
560
|
+
|
|
561
|
+
`string`
|
|
562
|
+
|
|
563
|
+
#### Defined in
|
|
564
|
+
|
|
565
|
+
[lib/getDownloadsDirectory.ts:4](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/getDownloadsDirectory.ts#L4)
|
|
566
|
+
|
|
567
|
+
___
|
|
568
|
+
|
|
569
|
+
### getHomeDirectory
|
|
570
|
+
|
|
571
|
+
▸ **getHomeDirectory**(): `string`
|
|
572
|
+
|
|
573
|
+
#### Returns
|
|
574
|
+
|
|
575
|
+
`string`
|
|
576
|
+
|
|
577
|
+
#### Defined in
|
|
578
|
+
|
|
579
|
+
[lib/getHomeDirectory.ts:3](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/getHomeDirectory.ts#L3)
|
|
580
|
+
|
|
581
|
+
___
|
|
582
|
+
|
|
583
|
+
### getLastMofifiedFileIn
|
|
584
|
+
|
|
585
|
+
▸ **getLastMofifiedFileIn**(`dirpath`): `Promise`<`string`\>
|
|
586
|
+
|
|
587
|
+
#### Parameters
|
|
588
|
+
|
|
589
|
+
| Name | Type |
|
|
590
|
+
| :------ | :------ |
|
|
591
|
+
| `dirpath` | `string` |
|
|
592
|
+
|
|
593
|
+
#### Returns
|
|
594
|
+
|
|
595
|
+
`Promise`<`string`\>
|
|
596
|
+
|
|
597
|
+
#### Defined in
|
|
598
|
+
|
|
599
|
+
[lib/getLastMofifiedFileIn.ts:4](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/getLastMofifiedFileIn.ts#L4)
|
|
600
|
+
|
|
601
|
+
___
|
|
602
|
+
|
|
603
|
+
### getRootDir
|
|
604
|
+
|
|
605
|
+
▸ **getRootDir**(): `string`
|
|
606
|
+
|
|
607
|
+
#### Returns
|
|
608
|
+
|
|
609
|
+
`string`
|
|
610
|
+
|
|
611
|
+
#### Defined in
|
|
612
|
+
|
|
613
|
+
[lib/getRootDir.ts:3](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/getRootDir.ts#L3)
|
|
614
|
+
|
|
615
|
+
___
|
|
616
|
+
|
|
617
|
+
### isWindows
|
|
618
|
+
|
|
619
|
+
▸ **isWindows**(): `boolean`
|
|
620
|
+
|
|
621
|
+
#### Returns
|
|
622
|
+
|
|
623
|
+
`boolean`
|
|
624
|
+
|
|
625
|
+
#### Defined in
|
|
626
|
+
|
|
627
|
+
[lib/isWindows.ts:1](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/isWindows.ts#L1)
|
|
628
|
+
|
|
629
|
+
___
|
|
630
|
+
|
|
631
|
+
### normalizeFileExtension
|
|
632
|
+
|
|
633
|
+
▸ **normalizeFileExtension**(`ext`): `string`
|
|
634
|
+
|
|
635
|
+
Normalize a file extension to the form: .[ext]
|
|
636
|
+
Anything before the last "." is not returned.
|
|
637
|
+
|
|
638
|
+
#### Parameters
|
|
639
|
+
|
|
640
|
+
| Name | Type | Description |
|
|
641
|
+
| :------ | :------ | :------ |
|
|
642
|
+
| `ext` | `string` | file extension |
|
|
643
|
+
|
|
644
|
+
#### Returns
|
|
645
|
+
|
|
646
|
+
`string`
|
|
647
|
+
|
|
648
|
+
The normalized file extension.
|
|
649
|
+
|
|
650
|
+
**`Throws`**
|
|
651
|
+
|
|
652
|
+
If the extension contains illegal characters.
|
|
653
|
+
|
|
654
|
+
**`Example`**
|
|
655
|
+
|
|
656
|
+
```ts
|
|
657
|
+
normalizeFileExtension('jpg');;
|
|
658
|
+
//=> '.jpg'
|
|
659
|
+
normalizeFileExtension('.jpg');;
|
|
660
|
+
//=> '.jpg'
|
|
661
|
+
normalizeFileExtension('..jpg');;
|
|
662
|
+
//=> '.jpg'
|
|
663
|
+
normalizeFileExtension('');;
|
|
664
|
+
//=> ''
|
|
665
|
+
normalizeFileExtension('.');;
|
|
666
|
+
//=> ''
|
|
667
|
+
normalizeFileExtension('jpg|png');;
|
|
668
|
+
//=> Error
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
#### Defined in
|
|
672
|
+
|
|
673
|
+
[lib/normalizeFileExtension.ts:22](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/normalizeFileExtension.ts#L22)
|
|
674
|
+
|
|
675
|
+
___
|
|
676
|
+
|
|
677
|
+
### readJsonFile
|
|
678
|
+
|
|
679
|
+
▸ **readJsonFile**<`T`\>(`filepath`): `Promise`<`T`\>
|
|
680
|
+
|
|
681
|
+
Reads a JSON file from the given filepath and returns its content as a Promise.
|
|
682
|
+
The Promise will resolve with the parsed JSON content as an object of type T.
|
|
683
|
+
|
|
684
|
+
#### Type parameters
|
|
685
|
+
|
|
686
|
+
| Name | Description |
|
|
687
|
+
| :------ | :------ |
|
|
688
|
+
| `T` | The expected return type of the JSON object. |
|
|
689
|
+
|
|
690
|
+
#### Parameters
|
|
691
|
+
|
|
692
|
+
| Name | Type | Description |
|
|
693
|
+
| :------ | :------ | :------ |
|
|
694
|
+
| `filepath` | `string` | The path to the JSON file to read. |
|
|
695
|
+
|
|
696
|
+
#### Returns
|
|
697
|
+
|
|
698
|
+
`Promise`<`T`\>
|
|
699
|
+
|
|
700
|
+
A Promise that resolves with the parsed JSON content as an object of type T.
|
|
701
|
+
|
|
702
|
+
**`Throws`**
|
|
703
|
+
|
|
704
|
+
Will throw an error if reading the file fails for any reason.
|
|
705
|
+
|
|
706
|
+
**`Example`**
|
|
707
|
+
|
|
708
|
+
```ts
|
|
709
|
+
const data: MyType = await readJsonFile<MyType>('path/to/myfile.json');
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
#### Defined in
|
|
713
|
+
|
|
714
|
+
[lib/readJsonFile.ts:14](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/readJsonFile.ts#L14)
|
|
715
|
+
|
|
716
|
+
___
|
|
717
|
+
|
|
718
|
+
### readJsonFileSync
|
|
719
|
+
|
|
720
|
+
▸ **readJsonFileSync**<`T`\>(`filepath`): `T`
|
|
721
|
+
|
|
722
|
+
Reads a JSON file synchronously and returns a Promise that resolves with the parsed JSON data.
|
|
723
|
+
|
|
724
|
+
#### Type parameters
|
|
725
|
+
|
|
726
|
+
| Name | Description |
|
|
727
|
+
| :------ | :------ |
|
|
728
|
+
| `T` | The expected return type of the JSON data. |
|
|
729
|
+
|
|
730
|
+
#### Parameters
|
|
731
|
+
|
|
732
|
+
| Name | Type | Description |
|
|
733
|
+
| :------ | :------ | :------ |
|
|
734
|
+
| `filepath` | `string` | The path to the JSON file to read. |
|
|
735
|
+
|
|
736
|
+
#### Returns
|
|
737
|
+
|
|
738
|
+
`T`
|
|
739
|
+
|
|
740
|
+
A Promise that resolves with the parsed JSON data.
|
|
741
|
+
|
|
742
|
+
**`Throws`**
|
|
743
|
+
|
|
744
|
+
If the file cannot be read or the content cannot be parsed as JSON.
|
|
745
|
+
|
|
746
|
+
**`Example`**
|
|
747
|
+
|
|
748
|
+
```ts
|
|
749
|
+
const data = await readJsonFileSync<MyType>('/path/to/file.json');
|
|
750
|
+
console.log(data);
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
#### Defined in
|
|
754
|
+
|
|
755
|
+
[lib/readJsonFileSync.ts:14](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/readJsonFileSync.ts#L14)
|
|
756
|
+
|
|
757
|
+
___
|
|
758
|
+
|
|
759
|
+
### readPackageJson
|
|
760
|
+
|
|
761
|
+
▸ **readPackageJson**(`projectRoot?`): `Record`<`string`, `any`\> \| `undefined`
|
|
762
|
+
|
|
763
|
+
#### Parameters
|
|
764
|
+
|
|
765
|
+
| Name | Type |
|
|
766
|
+
| :------ | :------ |
|
|
767
|
+
| `projectRoot` | `string` |
|
|
768
|
+
|
|
769
|
+
#### Returns
|
|
770
|
+
|
|
771
|
+
`Record`<`string`, `any`\> \| `undefined`
|
|
772
|
+
|
|
773
|
+
#### Defined in
|
|
774
|
+
|
|
775
|
+
[lib/readPackageJson.ts:5](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/readPackageJson.ts#L5)
|
|
776
|
+
|
|
777
|
+
___
|
|
778
|
+
|
|
779
|
+
### removeIllegalFilenameCharacters
|
|
780
|
+
|
|
781
|
+
▸ **removeIllegalFilenameCharacters**(`string`): `string`
|
|
782
|
+
|
|
783
|
+
#### Parameters
|
|
784
|
+
|
|
785
|
+
| Name | Type |
|
|
786
|
+
| :------ | :------ |
|
|
787
|
+
| `string` | `string` |
|
|
788
|
+
|
|
789
|
+
#### Returns
|
|
790
|
+
|
|
791
|
+
`string`
|
|
792
|
+
|
|
793
|
+
#### Defined in
|
|
794
|
+
|
|
795
|
+
[lib/removeIllegalFilenameCharacters.ts:1](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/removeIllegalFilenameCharacters.ts#L1)
|
|
796
|
+
|
|
797
|
+
___
|
|
798
|
+
|
|
799
|
+
### unzipFile
|
|
800
|
+
|
|
801
|
+
▸ **unzipFile**(`filepath`, `outdir`): `Promise`<`void`\>
|
|
802
|
+
|
|
803
|
+
#### Parameters
|
|
804
|
+
|
|
805
|
+
| Name | Type |
|
|
806
|
+
| :------ | :------ |
|
|
807
|
+
| `filepath` | `string` |
|
|
808
|
+
| `outdir` | `string` |
|
|
809
|
+
|
|
810
|
+
#### Returns
|
|
811
|
+
|
|
812
|
+
`Promise`<`void`\>
|
|
813
|
+
|
|
814
|
+
#### Defined in
|
|
815
|
+
|
|
816
|
+
[lib/unzipFile.ts:3](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/unzipFile.ts#L3)
|
|
817
|
+
|
|
818
|
+
___
|
|
819
|
+
|
|
820
|
+
### unzipMergeFiles
|
|
821
|
+
|
|
822
|
+
▸ **unzipMergeFiles**(`source`, `target`): `Promise`<`void`\>
|
|
823
|
+
|
|
824
|
+
#### Parameters
|
|
825
|
+
|
|
826
|
+
| Name | Type | Description |
|
|
827
|
+
| :------ | :------ | :------ |
|
|
828
|
+
| `source` | `string` \| `string`[] | Either a directory containing zip files or an array of zip file paths. |
|
|
829
|
+
| `target` | `string` | - |
|
|
830
|
+
|
|
831
|
+
#### Returns
|
|
832
|
+
|
|
833
|
+
`Promise`<`void`\>
|
|
834
|
+
|
|
835
|
+
#### Defined in
|
|
836
|
+
|
|
837
|
+
[lib/unzipMergeFiles.ts:8](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/unzipMergeFiles.ts#L8)
|
|
838
|
+
|
|
839
|
+
___
|
|
840
|
+
|
|
841
|
+
### wipeDirectorySafe
|
|
842
|
+
|
|
843
|
+
▸ **wipeDirectorySafe**(`dirpath`): `Promise`<`void`\>
|
|
844
|
+
|
|
845
|
+
#### Parameters
|
|
846
|
+
|
|
847
|
+
| Name | Type |
|
|
848
|
+
| :------ | :------ |
|
|
849
|
+
| `dirpath` | `string` |
|
|
850
|
+
|
|
851
|
+
#### Returns
|
|
852
|
+
|
|
853
|
+
`Promise`<`void`\>
|
|
854
|
+
|
|
855
|
+
#### Defined in
|
|
856
|
+
|
|
857
|
+
[lib/wipeDirectorySafe.ts:4](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/wipeDirectorySafe.ts#L4)
|
|
858
|
+
|
|
859
|
+
___
|
|
860
|
+
|
|
861
|
+
### writeJsonFile
|
|
862
|
+
|
|
863
|
+
▸ **writeJsonFile**<`T`\>(`filepath`, `data`, `pretty?`): `Promise`<`void`\>
|
|
864
|
+
|
|
865
|
+
Writes a JSON file to the specified filepath. The data to be written is passed as an argument.
|
|
866
|
+
If the 'pretty' argument is set to true, the JSON data will be formatted in a more human-readable way.
|
|
867
|
+
|
|
868
|
+
#### Type parameters
|
|
869
|
+
|
|
870
|
+
| Name | Description |
|
|
871
|
+
| :------ | :------ |
|
|
872
|
+
| `T` | The type of the data to be written to the file. |
|
|
873
|
+
|
|
874
|
+
#### Parameters
|
|
875
|
+
|
|
876
|
+
| Name | Type | Default value | Description |
|
|
877
|
+
| :------ | :------ | :------ | :------ |
|
|
878
|
+
| `filepath` | `string` | `undefined` | The path to the file where the data should be written. |
|
|
879
|
+
| `data` | `T` | `undefined` | The data to be written to the file. |
|
|
880
|
+
| `pretty` | `boolean` | `false` | Optional. If set to true, formats the JSON data in a more human-readable way. Default is false. |
|
|
881
|
+
|
|
882
|
+
#### Returns
|
|
883
|
+
|
|
884
|
+
`Promise`<`void`\>
|
|
885
|
+
|
|
886
|
+
A Promise that resolves when the file has been successfully written.
|
|
887
|
+
|
|
888
|
+
**`Example`**
|
|
889
|
+
|
|
890
|
+
```ts
|
|
891
|
+
const data = { name: 'John', age: 30 };
|
|
892
|
+
await writeJsonFile('./data.json', data, true);
|
|
893
|
+
```
|
|
894
|
+
|
|
895
|
+
#### Defined in
|
|
896
|
+
|
|
897
|
+
[lib/writeJsonFile.ts:16](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/writeJsonFile.ts#L16)
|
|
898
|
+
|
|
899
|
+
___
|
|
900
|
+
|
|
901
|
+
### writeJsonFileSync
|
|
902
|
+
|
|
903
|
+
▸ **writeJsonFileSync**<`T`\>(`filepath`, `data`, `pretty?`): `void`
|
|
904
|
+
|
|
905
|
+
Writes a JSON object to a file synchronously.
|
|
906
|
+
|
|
907
|
+
#### Type parameters
|
|
908
|
+
|
|
909
|
+
| Name | Description |
|
|
910
|
+
| :------ | :------ |
|
|
911
|
+
| `T` | The type of the JSON object. |
|
|
912
|
+
|
|
913
|
+
#### Parameters
|
|
914
|
+
|
|
915
|
+
| Name | Type | Default value | Description |
|
|
916
|
+
| :------ | :------ | :------ | :------ |
|
|
917
|
+
| `filepath` | `string` | `undefined` | The path of the file where the JSON object will be written. |
|
|
918
|
+
| `data` | `T` | `undefined` | The JSON object that will be written to the file. |
|
|
919
|
+
| `pretty` | `boolean` | `false` | If true, the JSON object will be formatted with indentation and line breaks. Default is false. |
|
|
920
|
+
|
|
921
|
+
#### Returns
|
|
922
|
+
|
|
923
|
+
`void`
|
|
924
|
+
|
|
925
|
+
**`Throws`**
|
|
926
|
+
|
|
927
|
+
If the file cannot be written.
|
|
928
|
+
|
|
929
|
+
**`Example`**
|
|
930
|
+
|
|
931
|
+
```ts
|
|
932
|
+
const data = { name: 'John', age: 30 };
|
|
933
|
+
writeJsonFileSync('./data.json', data, true);
|
|
934
|
+
```
|
|
935
|
+
|
|
936
|
+
#### Defined in
|
|
937
|
+
|
|
938
|
+
[lib/writeJsonFileSync.ts:15](https://github.com/bemoje/tsmono/blob/ad6c8c6/pkg/fs/src/lib/writeJsonFileSync.ts#L15)
|