@bemoje/fs 0.0.3 → 0.0.4

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 CHANGED
@@ -14,6 +14,8 @@ Tools for working with the local filesystem in nodejs.
14
14
  <span><a href="https://npmjs.org/@bemoje/fs" title="View this project on NPM"><img src="https://img.shields.io/npm/v/@bemoje/fs" alt="NPM Version" /></a></span>
15
15
  <span><a href="https://npmjs.org/@bemoje/fs" title="NPM Downloads"><img src="https://img.shields.io/npm/dt/@bemoje/fs" alt="NPM Downloads" /></a></span>
16
16
 
17
+ ## Documentation
18
+ [fs docs](https://bemoje.github.io/tsmono/html/fs/modules.html)
17
19
 
18
20
  ##### Donate
19
21
  <span><a href="https://www.patreon.com/user?u=40752770" title="Donate using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon Donation" /></a></span>
@@ -35,904 +37,3 @@ Contributors are welcome to open a [pull request](https://github.com/bemoje/http
35
37
 
36
38
  ## License
37
39
  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)
package/dist/index.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @bemoje/fs v0.0.2
2
+ * @bemoje/fs v0.0.3
3
3
  * (c) Benjamin Møller Jensen
4
4
  * Released under the MIT License.
5
5
  */"use strict";var string=require("@bemoje/string"),path=require("path"),fs=require("fs"),child_process=require("child_process"),extract=require("extract-zip");function absoluteToRelativePath(absolute,workingDirectory=process.cwd()){return path.normalize(absolute).replace(new RegExp(string.regexEscapeString(path.normalize(workingDirectory)+path.sep),"i"),"")}function __awaiter(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value)})}return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator["throw"](value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})}"function"==typeof SuppressedError?SuppressedError:function(error,suppressed,message){var e=new Error(message);return e.name="SuppressedError",e.error=error,e.suppressed=suppressed,e};function createDirectory(dirpath){return __awaiter(this,void 0,void 0,function*(){return yield fs.promises.mkdir(dirpath,{recursive:!0}),dirpath})}function appendLineToFile(filepath,line,linebreakBefore=!1){return __awaiter(this,void 0,void 0,function*(){fs.existsSync(filepath)||(yield createDirectory(path.dirname(filepath)),yield fs.promises.writeFile(filepath,"")),yield fs.promises.appendFile(filepath,linebreakBefore?"\n"+line:line+"\n")})}function cleanDirectorySync(dirpath,predicate){for(const filename of fs.readdirSync(dirpath)){const filepath=path.join(dirpath,filename),stat=fs.statSync(filepath);predicate(filepath,stat)&&fs.unlinkSync(filepath)}}function createDirectorySync(dirpath){return fs.mkdirSync(dirpath,{recursive:!0}),dirpath}function normalizeFileExtension(ext){if(""===ext||"."===ext)return"";if(/[<>"|?*:]/g.test(ext))throw new Error(`Illegal characters in file extension: ${ext} | Illegal characters are: <>"|?:*`);return ext.includes(".")?ext.substring(ext.lastIndexOf(".")):"."+ext}function createFileExtensionFilter(...fileExtensions){return fileExtensions.length?filepath=>{for(const ext of fileExtensions.map(normalizeFileExtension))if(path.extname(filepath)===ext)return!0;return!1}:()=>!0}function cwdpath(...paths){return path.join(process.cwd(),...paths)}function deleteDirectory(dirpath){return __awaiter(this,void 0,void 0,function*(){yield fs.promises.rm(dirpath,{recursive:!0,force:!0})})}function deleteDirectorySafe(dirpath){return __awaiter(this,void 0,void 0,function*(){fs.existsSync(dirpath)&&(yield fs.promises.rm(dirpath,{recursive:!0,force:!0}))})}function deleteDirectorySafeSync(dirpath){return fs.existsSync(dirpath)?(fs.rmSync(dirpath,{recursive:!0,force:!0}),dirpath):dirpath}function deleteDirectorySync(dirpath){return fs.rmSync(dirpath,{recursive:!0,force:!0}),dirpath}function ensureValidWindowsPath(path,options){const throwOrFalse=msg=>{if(options&&!0===options.assert)throw new Error(`Invalid windows path. ${msg} | input received: ${path}`);return!1};if(0===path.length)return throwOrFalse("Path string is length 0.");if(-1!==path.indexOf("/")&&-1!==path.indexOf("\\"))return throwOrFalse("Path contains both backslash and forward slash.");const maxLength=(options&&options.extendedMaxLength?32767:260)-12;if(path.length>maxLength)return throwOrFalse(`Maximum length of ${maxLength} exceeded`);let noDriveLetter=path;return /^\w:(\\|\/)/g.test(path)&&(noDriveLetter=path.substring(2)),/[<>"|?*:]/g.test(noDriveLetter)?throwOrFalse(`Illegal characters in: ${path} | Illegal characters are: <>"|?:*`):!/(\\|\/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])((\\|\/)|$)/g.test(path)||throwOrFalse("Illegal name in path string")}function isWindows(){return process.platform.includes("win")}function getDiskDrivesWindows(){if(!isWindows())throw new Error("This function is only available on Windows.");return child_process.execSync("wmic logicaldisk get name").toString().split("\n").map(s=>s.trim()).filter(s=>/^[a-z]:/i.test(s)).map(s=>s.substring(0,2)+path.sep)}function getHomeDirectory(){const home=path.resolve(process.env.HOME||process.env.USERPROFILE||"");if(!home)throw new Error("Home directory not found");return home}function getDownloadsDirectory(){return path.join(getHomeDirectory(),"Downloads")}function getLastMofifiedFileIn(dirpath){return __awaiter(this,void 0,void 0,function*(){const children=yield fs.promises.readdir(dirpath),filtered=children.map(fname=>{const fpath=path.join(dirpath,fname),stat=fs.statSync(fpath);return[fpath,stat.mtimeMs,stat.isFile()]}).filter(a=>a[2]),sorted=filtered.sort((a,b)=>b[1]-a[1]);return sorted[0][0]})}function getRootDir(){return path.parse(process.cwd()).root}function readJsonFile(filepath){return __awaiter(this,void 0,void 0,function*(){return JSON.parse(yield fs.promises.readFile(filepath,"utf8"))})}function readJsonFileSync(filepath){return JSON.parse(fs.readFileSync(filepath,"utf8"))}function readPackageJson(projectRoot=process.cwd()){const filepath=path.join(projectRoot,"package.json");return fs.existsSync(filepath)?readJsonFileSync(filepath):void 0}function removeIllegalFilenameCharacters(string){return string.replace(/[/\\?%*:|"<>]/g,"")}function unzipFile(filepath,outdir){return __awaiter(this,void 0,void 0,function*(){yield extract(filepath,{dir:outdir})})}function unzipMergeFiles(source,target){return __awaiter(this,void 0,void 0,function*(){"string"==typeof source&&(source=fs.readdirSync(source).map(filename=>path.join(source,filename)));for(const filepath of source){const stat=yield fs.promises.stat(filepath);stat.isDirectory()||filepath.endsWith(".zip")&&(yield extract(filepath,{dir:target}))}})}function wipeDirectorySafe(dirpath){return __awaiter(this,void 0,void 0,function*(){yield deleteDirectorySafe(dirpath),yield createDirectory(dirpath)})}function writeJsonFile(filepath,data,pretty=!1){return __awaiter(this,void 0,void 0,function*(){yield fs.promises.writeFile(filepath,JSON.stringify(data,null,pretty?2:void 0))})}function writeJsonFileSync(filepath,data,pretty=!1){fs.writeFileSync(filepath,JSON.stringify(data,null,pretty?2:void 0))}exports.absoluteToRelativePath=absoluteToRelativePath,exports.appendLineToFile=appendLineToFile,exports.cleanDirectorySync=cleanDirectorySync,exports.createDirectory=createDirectory,exports.createDirectorySync=createDirectorySync,exports.createFileExtensionFilter=createFileExtensionFilter,exports.cwdpath=cwdpath,exports.deleteDirectory=deleteDirectory,exports.deleteDirectorySafe=deleteDirectorySafe,exports.deleteDirectorySafeSync=deleteDirectorySafeSync,exports.deleteDirectorySync=deleteDirectorySync,exports.ensureValidWindowsPath=ensureValidWindowsPath,exports.getDiskDrivesWindows=getDiskDrivesWindows,exports.getDownloadsDirectory=getDownloadsDirectory,exports.getHomeDirectory=getHomeDirectory,exports.getLastMofifiedFileIn=getLastMofifiedFileIn,exports.getRootDir=getRootDir,exports.isWindows=isWindows,exports.normalizeFileExtension=normalizeFileExtension,exports.readJsonFile=readJsonFile,exports.readJsonFileSync=readJsonFileSync,exports.readPackageJson=readPackageJson,exports.removeIllegalFilenameCharacters=removeIllegalFilenameCharacters,exports.unzipFile=unzipFile,exports.unzipMergeFiles=unzipMergeFiles,exports.wipeDirectorySafe=wipeDirectorySafe,exports.writeJsonFile=writeJsonFile,exports.writeJsonFileSync=writeJsonFileSync;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @bemoje/fs v0.0.2
2
+ * @bemoje/fs v0.0.3
3
3
  * (c) Benjamin Møller Jensen
4
4
  * Released under the MIT License.
5
5
  */import{regexEscapeString}from"@bemoje/string";import path from"path";import fs from"fs";import{execSync}from"child_process";import extract from"extract-zip";function absoluteToRelativePath(absolute,workingDirectory=process.cwd()){return path.normalize(absolute).replace(new RegExp(regexEscapeString(path.normalize(workingDirectory)+path.sep),"i"),"")}function __awaiter(thisArg,_arguments,P,generator){function adopt(value){return value instanceof P?value:new P(function(resolve){resolve(value)})}return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator["throw"](value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})}"function"==typeof SuppressedError?SuppressedError:function(error,suppressed,message){var e=new Error(message);return e.name="SuppressedError",e.error=error,e.suppressed=suppressed,e};function createDirectory(dirpath){return __awaiter(this,void 0,void 0,function*(){return yield fs.promises.mkdir(dirpath,{recursive:!0}),dirpath})}function appendLineToFile(filepath,line,linebreakBefore=!1){return __awaiter(this,void 0,void 0,function*(){fs.existsSync(filepath)||(yield createDirectory(path.dirname(filepath)),yield fs.promises.writeFile(filepath,"")),yield fs.promises.appendFile(filepath,linebreakBefore?"\n"+line:line+"\n")})}function cleanDirectorySync(dirpath,predicate){for(const filename of fs.readdirSync(dirpath)){const filepath=path.join(dirpath,filename),stat=fs.statSync(filepath);predicate(filepath,stat)&&fs.unlinkSync(filepath)}}function createDirectorySync(dirpath){return fs.mkdirSync(dirpath,{recursive:!0}),dirpath}function normalizeFileExtension(ext){if(""===ext||"."===ext)return"";if(/[<>"|?*:]/g.test(ext))throw new Error(`Illegal characters in file extension: ${ext} | Illegal characters are: <>"|?:*`);return ext.includes(".")?ext.substring(ext.lastIndexOf(".")):"."+ext}function createFileExtensionFilter(...fileExtensions){return fileExtensions.length?filepath=>{for(const ext of fileExtensions.map(normalizeFileExtension))if(path.extname(filepath)===ext)return!0;return!1}:()=>!0}function cwdpath(...paths){return path.join(process.cwd(),...paths)}function deleteDirectory(dirpath){return __awaiter(this,void 0,void 0,function*(){yield fs.promises.rm(dirpath,{recursive:!0,force:!0})})}function deleteDirectorySafe(dirpath){return __awaiter(this,void 0,void 0,function*(){fs.existsSync(dirpath)&&(yield fs.promises.rm(dirpath,{recursive:!0,force:!0}))})}function deleteDirectorySafeSync(dirpath){return fs.existsSync(dirpath)?(fs.rmSync(dirpath,{recursive:!0,force:!0}),dirpath):dirpath}function deleteDirectorySync(dirpath){return fs.rmSync(dirpath,{recursive:!0,force:!0}),dirpath}function ensureValidWindowsPath(path,options){const throwOrFalse=msg=>{if(options&&!0===options.assert)throw new Error(`Invalid windows path. ${msg} | input received: ${path}`);return!1};if(0===path.length)return throwOrFalse("Path string is length 0.");if(-1!==path.indexOf("/")&&-1!==path.indexOf("\\"))return throwOrFalse("Path contains both backslash and forward slash.");const maxLength=(options&&options.extendedMaxLength?32767:260)-12;if(path.length>maxLength)return throwOrFalse(`Maximum length of ${maxLength} exceeded`);let noDriveLetter=path;return /^\w:(\\|\/)/g.test(path)&&(noDriveLetter=path.substring(2)),/[<>"|?*:]/g.test(noDriveLetter)?throwOrFalse(`Illegal characters in: ${path} | Illegal characters are: <>"|?:*`):!/(\\|\/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])((\\|\/)|$)/g.test(path)||throwOrFalse("Illegal name in path string")}function isWindows(){return process.platform.includes("win")}function getDiskDrivesWindows(){if(!isWindows())throw new Error("This function is only available on Windows.");return execSync("wmic logicaldisk get name").toString().split("\n").map(s=>s.trim()).filter(s=>/^[a-z]:/i.test(s)).map(s=>s.substring(0,2)+path.sep)}function getHomeDirectory(){const home=path.resolve(process.env.HOME||process.env.USERPROFILE||"");if(!home)throw new Error("Home directory not found");return home}function getDownloadsDirectory(){return path.join(getHomeDirectory(),"Downloads")}function getLastMofifiedFileIn(dirpath){return __awaiter(this,void 0,void 0,function*(){const children=yield fs.promises.readdir(dirpath),filtered=children.map(fname=>{const fpath=path.join(dirpath,fname),stat=fs.statSync(fpath);return[fpath,stat.mtimeMs,stat.isFile()]}).filter(a=>a[2]),sorted=filtered.sort((a,b)=>b[1]-a[1]);return sorted[0][0]})}function getRootDir(){return path.parse(process.cwd()).root}function readJsonFile(filepath){return __awaiter(this,void 0,void 0,function*(){return JSON.parse(yield fs.promises.readFile(filepath,"utf8"))})}function readJsonFileSync(filepath){return JSON.parse(fs.readFileSync(filepath,"utf8"))}function readPackageJson(projectRoot=process.cwd()){const filepath=path.join(projectRoot,"package.json");return fs.existsSync(filepath)?readJsonFileSync(filepath):void 0}function removeIllegalFilenameCharacters(string){return string.replace(/[/\\?%*:|"<>]/g,"")}function unzipFile(filepath,outdir){return __awaiter(this,void 0,void 0,function*(){yield extract(filepath,{dir:outdir})})}function unzipMergeFiles(source,target){return __awaiter(this,void 0,void 0,function*(){"string"==typeof source&&(source=fs.readdirSync(source).map(filename=>path.join(source,filename)));for(const filepath of source){const stat=yield fs.promises.stat(filepath);stat.isDirectory()||filepath.endsWith(".zip")&&(yield extract(filepath,{dir:target}))}})}function wipeDirectorySafe(dirpath){return __awaiter(this,void 0,void 0,function*(){yield deleteDirectorySafe(dirpath),yield createDirectory(dirpath)})}function writeJsonFile(filepath,data,pretty=!1){return __awaiter(this,void 0,void 0,function*(){yield fs.promises.writeFile(filepath,JSON.stringify(data,null,pretty?2:void 0))})}function writeJsonFileSync(filepath,data,pretty=!1){fs.writeFileSync(filepath,JSON.stringify(data,null,pretty?2:void 0))}export{absoluteToRelativePath,appendLineToFile,cleanDirectorySync,createDirectory,createDirectorySync,createFileExtensionFilter,cwdpath,deleteDirectory,deleteDirectorySafe,deleteDirectorySafeSync,deleteDirectorySync,ensureValidWindowsPath,getDiskDrivesWindows,getDownloadsDirectory,getHomeDirectory,getLastMofifiedFileIn,getRootDir,isWindows,normalizeFileExtension,readJsonFile,readJsonFileSync,readPackageJson,removeIllegalFilenameCharacters,unzipFile,unzipMergeFiles,wipeDirectorySafe,writeJsonFile,writeJsonFileSync};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bemoje/fs",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Tools for working with the local filesystem in nodejs.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -9,39 +9,8 @@
9
9
  "lint": "eslint \"*/**/*.{ts,js,json}\" --fix",
10
10
  "test": "jest --preset ts-jest",
11
11
  "build": "rimraf dist && rollup --config ./rollup.config.js --bundleConfigAsCjs",
12
- "docsmd": "rimraf docs/md && typedoc --out docs/md/ src/index.ts --readme none --plugin typedoc-plugin-markdown --theme markdown --entryDocument index.md --publicPath /docs/md/",
13
- "docshtml": "rimraf docs/html && typedoc --out docs/html --entryPoints src/index.ts",
14
- "prepub": "npm run lint && npm run build && npm run test && npm run docsmd && npm run docshtml",
15
- "viewdocs": "start docs/html/index.html"
16
- },
17
- "devDependencies": {
18
- "@rollup/plugin-commonjs": "^25.0.3",
19
- "@rollup/plugin-node-resolve": "^15.1.0",
20
- "@types/camel-case": "^1.2.1",
21
- "@types/commander": "^2.12.2",
22
- "@types/eslint-plugin-prettier": "^3.1.0",
23
- "@types/extract-zip": "^2.0.1",
24
- "@types/jest": "^29.5.3",
25
- "@types/node": "^20.4.8",
26
- "@types/rimraf": "^4.0.5",
27
- "@types/rollup": "^0.54.0",
28
- "@typescript-eslint/eslint-plugin": "^6.3.0",
29
- "@typescript-eslint/parser": "^6.3.0",
30
- "camel-case": "^4.1.2",
31
- "eslint": "^8.46.0",
32
- "eslint-config-prettier": "^9.0.0",
33
- "eslint-plugin-prettier": "^5.0.0",
34
- "jest": "^29.6.2",
35
- "jest-environment-node": "^29.6.2",
36
- "prettier": "^3.0.1",
37
- "rimraf": "^5.0.1",
38
- "rollup": "^3.27.2",
39
- "rollup-plugin-typescript2": "^0.35.0",
40
- "ts-jest": "^29.1.1",
41
- "ts-node": "^10.9.1",
42
- "tslib": "^2.6.1",
43
- "typedoc-plugin-markdown": "^3.15.4",
44
- "typescript": "^5.1.6"
12
+ "docs": "rimraf ../../docs/fs && typedoc --out ../../docs/fs --entryPoints src/index.ts",
13
+ "prepub": "npm run lint && npm run build && npm run test && npm run docs"
45
14
  },
46
15
  "author": {
47
16
  "name": "Benjamin Møller Jensen",
@@ -51,7 +20,8 @@
51
20
  "license": "MIT",
52
21
  "keywords": [],
53
22
  "dependencies": {
54
- "@bemoje/string": "latest"
23
+ "@bemoje/string": "latest",
24
+ "extract-zip": "^2.0.1"
55
25
  },
56
26
  "repository": {
57
27
  "type": "git",
@@ -64,5 +34,8 @@
64
34
  "bugs": {
65
35
  "url": "https://github.com/bemoje/tsmono/issues"
66
36
  },
67
- "homepage": "https://github.com/bemoje/tsmono"
37
+ "homepage": "https://github.com/bemoje/tsmono",
38
+ "devDependencies": {
39
+ "@types/extract-zip": "^2.0.1"
40
+ }
68
41
  }
package/project.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "fs",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "pkg/fs/src",
5
+ "projectType": "library",
6
+ "targets": {},
7
+ "tags": []
8
+ }