@visulima/fs 3.1.3 → 3.1.5
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/CHANGELOG.md +23 -0
- package/README.md +2114 -346
- package/dist/{packem_shared/LF-bB2qO80j.cjs → eol.cjs} +4 -4
- package/dist/eol.d.cts +7 -0
- package/dist/eol.d.mts +7 -0
- package/dist/eol.d.ts +7 -0
- package/dist/{packem_shared/LF-CU3KsvZC.mjs → eol.mjs} +4 -4
- package/dist/error.cjs +2 -2
- package/dist/error.mjs +2 -2
- package/dist/index.cjs +13 -13
- package/dist/index.d.cts +8 -19
- package/dist/index.d.mts +8 -19
- package/dist/index.d.ts +8 -19
- package/dist/index.mjs +8 -8
- package/dist/packem_shared/{JSONError-gkXvBSar.cjs → JSONError-5-wHnrxX.cjs} +4 -0
- package/dist/packem_shared/{JSONError-BCIIHvzq.mjs → JSONError-CaKt7MhC.mjs} +4 -0
- package/dist/packem_shared/{WalkError-B7_AVs7d.cjs → WalkError-B4-yr8Kk.cjs} +5 -1
- package/dist/packem_shared/{WalkError-H9EuRv7O.mjs → WalkError-DvEBTTaj.mjs} +5 -1
- package/dist/packem_shared/{collect-B615pR8z.mjs → collect-3Paj1Vqw.mjs} +1 -1
- package/dist/packem_shared/{collect-DHldhy_s.cjs → collect-DnfQeSOL.cjs} +1 -1
- package/dist/packem_shared/{collectSync-zahGoTi-.cjs → collectSync-D4vym4QD.cjs} +1 -1
- package/dist/packem_shared/{collectSync-CYuBdXWI.mjs → collectSync-DwJLL8SD.mjs} +1 -1
- package/dist/packem_shared/{emptyDirSync-BoknkGUe.cjs → emptyDirSync-BWA4n6TB.cjs} +3 -3
- package/dist/packem_shared/{emptyDirSync-DTGPXQ3v.mjs → emptyDirSync-DMAaCiC_.mjs} +3 -3
- package/dist/packem_shared/{parseJson-D7XcVuDD.mjs → parseJson-BA7Xrggq.mjs} +1 -1
- package/dist/packem_shared/{parseJson-5geAXtlm.cjs → parseJson-LgPGI5ic.cjs} +1 -1
- package/dist/packem_shared/{readJson-CG6Pm3bL.cjs → readJson-CEBHyuYq.cjs} +1 -1
- package/dist/packem_shared/{readJson-Ddq4aS0W.mjs → readJson-Ce9b06cu.mjs} +1 -1
- package/dist/packem_shared/{readJsonSync-DXVlgWNf.cjs → readJsonSync-B22hej0y.cjs} +1 -1
- package/dist/packem_shared/{readJsonSync-C1IyJccj.mjs → readJsonSync-CkUI9_z5.mjs} +1 -1
- package/dist/packem_shared/{types-Crz-rGlC.d.cts → types-BaMGfHdp.d.cts} +7 -3
- package/dist/packem_shared/{types-Crz-rGlC.d.mts → types-BaMGfHdp.d.mts} +7 -3
- package/dist/packem_shared/{types-Crz-rGlC.d.ts → types-BaMGfHdp.d.ts} +7 -3
- package/dist/packem_shared/{walk-PpNwjtjX.cjs → walk-CI3ygmrw.cjs} +1 -1
- package/dist/packem_shared/{walk-BIh3_ljI.mjs → walk-D7YA43g8.mjs} +1 -1
- package/dist/packem_shared/{walkSync-CFwkbDz9.mjs → walkSync-DLTsnwuJ.mjs} +1 -1
- package/dist/packem_shared/{walkSync-BidUqvMI.cjs → walkSync-oXkmn9ZA.cjs} +1 -1
- package/dist/packem_shared/writeYaml-3XQT2qtb.cjs +29 -0
- package/dist/packem_shared/writeYaml-BSFEuWp2.mjs +27 -0
- package/dist/packem_shared/writeYamlSync-B6VcXXIb.mjs +27 -0
- package/dist/packem_shared/writeYamlSync-BZR3If9v.cjs +29 -0
- package/dist/utils.cjs +2 -2
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.mjs +2 -2
- package/dist/yaml.cjs +2 -2
- package/dist/yaml.d.cts +6 -8
- package/dist/yaml.d.mts +6 -8
- package/dist/yaml.d.ts +6 -8
- package/dist/yaml.mjs +2 -2
- package/package.json +15 -2
- package/dist/packem_shared/writeYaml-C0YnZ1bp.cjs +0 -14
- package/dist/packem_shared/writeYaml-Cuj4H9ut.mjs +0 -12
- package/dist/packem_shared/writeYamlSync-BBNLBbQK.cjs +0 -14
- package/dist/packem_shared/writeYamlSync-cL8f07FV.mjs +0 -12
package/README.md
CHANGED
|
@@ -453,15 +453,152 @@ The printable section of the JSON which produces the error.
|
|
|
453
453
|
|
|
454
454
|
<!-- TYPEDOC -->
|
|
455
455
|
|
|
456
|
+
# eol
|
|
457
|
+
|
|
458
|
+
## Functions
|
|
459
|
+
|
|
460
|
+
### detect()
|
|
461
|
+
|
|
462
|
+
```ts
|
|
463
|
+
function detect(content): "\n" | "\r\n";
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
Defined in: [packages/fs/src/eol.ts:29](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/eol.ts#L29)
|
|
467
|
+
|
|
468
|
+
Detect the EOL character for string input.
|
|
469
|
+
Returns null if no newline.
|
|
470
|
+
|
|
471
|
+
#### Parameters
|
|
472
|
+
|
|
473
|
+
##### content
|
|
474
|
+
|
|
475
|
+
`string`
|
|
476
|
+
|
|
477
|
+
The string content to detect the EOL from.
|
|
478
|
+
|
|
479
|
+
#### Returns
|
|
480
|
+
|
|
481
|
+
"\n" \| "\r\n"
|
|
482
|
+
|
|
483
|
+
#### Example
|
|
484
|
+
|
|
485
|
+
```javascript
|
|
486
|
+
import { detect } from "@visulima/fs/eol";
|
|
487
|
+
|
|
488
|
+
detect("Hello\r\nWorld"); // "\r\n"
|
|
489
|
+
detect("Hello\nWorld"); // "\n"
|
|
490
|
+
detect("HelloWorld"); // null
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
***
|
|
494
|
+
|
|
495
|
+
### format()
|
|
496
|
+
|
|
497
|
+
```ts
|
|
498
|
+
function format(content, eol): string;
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
Defined in: [packages/fs/src/eol.ts:54](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/eol.ts#L54)
|
|
502
|
+
|
|
503
|
+
Format the file to the targeted EOL.
|
|
504
|
+
|
|
505
|
+
#### Parameters
|
|
506
|
+
|
|
507
|
+
##### content
|
|
508
|
+
|
|
509
|
+
`string`
|
|
510
|
+
|
|
511
|
+
The string content to format.
|
|
512
|
+
|
|
513
|
+
##### eol
|
|
514
|
+
|
|
515
|
+
The target EOL character.
|
|
516
|
+
|
|
517
|
+
"\n" | "\r\n"
|
|
518
|
+
|
|
519
|
+
#### Returns
|
|
520
|
+
|
|
521
|
+
`string`
|
|
522
|
+
|
|
523
|
+
#### Example
|
|
524
|
+
|
|
525
|
+
```javascript
|
|
526
|
+
import { format, LF, CRLF } from "@visulima/fs/eol";
|
|
527
|
+
|
|
528
|
+
format("Hello\r\nWorld\nUnix", LF); // "Hello\nWorld\nUnix"
|
|
529
|
+
format("Hello\nWorld\r\nWindows", CRLF); // "Hello\r\nWorld\r\nWindows"
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
## Variables
|
|
533
|
+
|
|
534
|
+
### CRLF
|
|
535
|
+
|
|
536
|
+
```ts
|
|
537
|
+
const CRLF: "\r\n";
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
Defined in: [packages/fs/src/eol.ts:9](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/eol.ts#L9)
|
|
541
|
+
|
|
542
|
+
End-of-line character for Windows platforms.
|
|
543
|
+
|
|
544
|
+
***
|
|
545
|
+
|
|
546
|
+
### EOL
|
|
547
|
+
|
|
548
|
+
```ts
|
|
549
|
+
const EOL: "\n" | "\r\n";
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
Defined in: [packages/fs/src/eol.ts:14](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/eol.ts#L14)
|
|
553
|
+
|
|
554
|
+
End-of-line character evaluated for the current platform.
|
|
555
|
+
|
|
556
|
+
***
|
|
557
|
+
|
|
558
|
+
### LF
|
|
559
|
+
|
|
560
|
+
```ts
|
|
561
|
+
const LF: "\n";
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
Defined in: [packages/fs/src/eol.ts:6](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/eol.ts#L6)
|
|
565
|
+
|
|
566
|
+
End-of-line character for POSIX platforms such as macOS and Linux.
|
|
456
567
|
# error
|
|
457
568
|
|
|
458
569
|
## Classes
|
|
459
570
|
|
|
460
571
|
### AlreadyExistsError
|
|
461
572
|
|
|
462
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:
|
|
573
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:28](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/already-exists-error.ts#L28)
|
|
574
|
+
|
|
575
|
+
Error thrown when a file or directory already exists at a specified path, and an operation was expecting it not to.
|
|
576
|
+
|
|
577
|
+
#### Example
|
|
463
578
|
|
|
464
|
-
|
|
579
|
+
```javascript
|
|
580
|
+
import { AlreadyExistsError } from "@visulima/fs/error"; // Assuming it's exported from an index or directly
|
|
581
|
+
import { ensureSymlinkSync } from "@visulima/fs"; // Or any function that might throw this
|
|
582
|
+
import { join } from "node:path";
|
|
583
|
+
|
|
584
|
+
try {
|
|
585
|
+
// Example: ensureSymlinkSync might throw this if a file (not a symlink) already exists at linkName
|
|
586
|
+
// For demonstration, let's assume someFunction internally throws it:
|
|
587
|
+
const someFunctionThatMightThrow = (path) => {
|
|
588
|
+
if (path === "/tmp/existing-file.txt") { // Simulate a check
|
|
589
|
+
throw new AlreadyExistsError(`file already exists at '/tmp/existing-file.txt'`);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
someFunctionThatMightThrow("/tmp/existing-file.txt");
|
|
593
|
+
} catch (error) {
|
|
594
|
+
if (error instanceof AlreadyExistsError) {
|
|
595
|
+
console.error(`Operation failed because path exists: ${error.message}`);
|
|
596
|
+
console.error(`Error code: ${error.code}`); // EEXIST
|
|
597
|
+
} else {
|
|
598
|
+
console.error("An unexpected error occurred:", error);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
```
|
|
465
602
|
|
|
466
603
|
#### Extends
|
|
467
604
|
|
|
@@ -475,7 +612,7 @@ Error thrown when file already exists.
|
|
|
475
612
|
new AlreadyExistsError(message): AlreadyExistsError;
|
|
476
613
|
```
|
|
477
614
|
|
|
478
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:
|
|
615
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:33](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/already-exists-error.ts#L33)
|
|
479
616
|
|
|
480
617
|
Creates a new instance.
|
|
481
618
|
|
|
@@ -507,7 +644,7 @@ Error.constructor
|
|
|
507
644
|
get code(): string;
|
|
508
645
|
```
|
|
509
646
|
|
|
510
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:
|
|
647
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:38](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/already-exists-error.ts#L38)
|
|
511
648
|
|
|
512
649
|
###### Returns
|
|
513
650
|
|
|
@@ -519,7 +656,7 @@ Defined in: [packages/fs/src/error/already-exists-error.ts:14](https://github.co
|
|
|
519
656
|
set code(_name): void;
|
|
520
657
|
```
|
|
521
658
|
|
|
522
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:
|
|
659
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:43](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/already-exists-error.ts#L43)
|
|
523
660
|
|
|
524
661
|
###### Parameters
|
|
525
662
|
|
|
@@ -539,7 +676,7 @@ Defined in: [packages/fs/src/error/already-exists-error.ts:19](https://github.co
|
|
|
539
676
|
get name(): string;
|
|
540
677
|
```
|
|
541
678
|
|
|
542
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:
|
|
679
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:48](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/already-exists-error.ts#L48)
|
|
543
680
|
|
|
544
681
|
###### Returns
|
|
545
682
|
|
|
@@ -551,7 +688,7 @@ Defined in: [packages/fs/src/error/already-exists-error.ts:24](https://github.co
|
|
|
551
688
|
set name(_name): void;
|
|
552
689
|
```
|
|
553
690
|
|
|
554
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:
|
|
691
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:53](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/already-exists-error.ts#L53)
|
|
555
692
|
|
|
556
693
|
###### Parameters
|
|
557
694
|
|
|
@@ -697,9 +834,43 @@ Error.stackTraceLimit
|
|
|
697
834
|
|
|
698
835
|
### DirectoryError
|
|
699
836
|
|
|
700
|
-
Defined in: [packages/fs/src/error/directory-error.ts:
|
|
837
|
+
Defined in: [packages/fs/src/error/directory-error.ts:36](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/directory-error.ts#L36)
|
|
838
|
+
|
|
839
|
+
Error thrown when an operation that is not allowed on a directory is attempted.
|
|
840
|
+
This typically occurs when a file-specific operation is used on a directory path.
|
|
841
|
+
|
|
842
|
+
#### Example
|
|
701
843
|
|
|
702
|
-
|
|
844
|
+
```javascript
|
|
845
|
+
import { DirectoryError } from "@visulima/fs/error";
|
|
846
|
+
import { readFile } from "@visulima/fs"; // Or any function that might throw this
|
|
847
|
+
import { join } from "node:path";
|
|
848
|
+
|
|
849
|
+
const attemptToReadFileFromDir = async () => {
|
|
850
|
+
try {
|
|
851
|
+
// Attempting to read a directory as if it were a file
|
|
852
|
+
// This is a conceptual example; readFile might throw a different error first
|
|
853
|
+
// depending on its internal checks, but EISDIR is the underlying system error.
|
|
854
|
+
// Forcing the scenario:
|
|
855
|
+
const pretendReadFileOnDir = (path) => {
|
|
856
|
+
if (path === "/tmp/my-directory") { // Simulate a directory path
|
|
857
|
+
throw new DirectoryError(`read '/tmp/my-directory'`);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
pretendReadFileOnDir("/tmp/my-directory");
|
|
861
|
+
// await readFile(join("/tmp", "my-directory"));
|
|
862
|
+
} catch (error) {
|
|
863
|
+
if (error instanceof DirectoryError) {
|
|
864
|
+
console.error(`Operation failed, path is a directory: ${error.message}`);
|
|
865
|
+
console.error(`Error code: ${error.code}`); // EISDIR
|
|
866
|
+
} else {
|
|
867
|
+
console.error("An unexpected error occurred:", error);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
attemptToReadFileFromDir();
|
|
873
|
+
```
|
|
703
874
|
|
|
704
875
|
#### Extends
|
|
705
876
|
|
|
@@ -713,7 +884,7 @@ Error thrown when an operation is not allowed on a directory.
|
|
|
713
884
|
new DirectoryError(message): DirectoryError;
|
|
714
885
|
```
|
|
715
886
|
|
|
716
|
-
Defined in: [packages/fs/src/error/directory-error.ts:
|
|
887
|
+
Defined in: [packages/fs/src/error/directory-error.ts:41](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/directory-error.ts#L41)
|
|
717
888
|
|
|
718
889
|
Creates a new instance.
|
|
719
890
|
|
|
@@ -745,7 +916,7 @@ Error.constructor
|
|
|
745
916
|
get code(): string;
|
|
746
917
|
```
|
|
747
918
|
|
|
748
|
-
Defined in: [packages/fs/src/error/directory-error.ts:
|
|
919
|
+
Defined in: [packages/fs/src/error/directory-error.ts:46](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/directory-error.ts#L46)
|
|
749
920
|
|
|
750
921
|
###### Returns
|
|
751
922
|
|
|
@@ -757,7 +928,7 @@ Defined in: [packages/fs/src/error/directory-error.ts:14](https://github.com/vis
|
|
|
757
928
|
set code(_name): void;
|
|
758
929
|
```
|
|
759
930
|
|
|
760
|
-
Defined in: [packages/fs/src/error/directory-error.ts:
|
|
931
|
+
Defined in: [packages/fs/src/error/directory-error.ts:51](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/directory-error.ts#L51)
|
|
761
932
|
|
|
762
933
|
###### Parameters
|
|
763
934
|
|
|
@@ -777,7 +948,7 @@ Defined in: [packages/fs/src/error/directory-error.ts:19](https://github.com/vis
|
|
|
777
948
|
get name(): string;
|
|
778
949
|
```
|
|
779
950
|
|
|
780
|
-
Defined in: [packages/fs/src/error/directory-error.ts:
|
|
951
|
+
Defined in: [packages/fs/src/error/directory-error.ts:56](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/directory-error.ts#L56)
|
|
781
952
|
|
|
782
953
|
###### Returns
|
|
783
954
|
|
|
@@ -789,7 +960,7 @@ Defined in: [packages/fs/src/error/directory-error.ts:24](https://github.com/vis
|
|
|
789
960
|
set name(_name): void;
|
|
790
961
|
```
|
|
791
962
|
|
|
792
|
-
Defined in: [packages/fs/src/error/directory-error.ts:
|
|
963
|
+
Defined in: [packages/fs/src/error/directory-error.ts:61](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/directory-error.ts#L61)
|
|
793
964
|
|
|
794
965
|
###### Parameters
|
|
795
966
|
|
|
@@ -935,10 +1106,48 @@ Error.stackTraceLimit
|
|
|
935
1106
|
|
|
936
1107
|
### NotEmptyError
|
|
937
1108
|
|
|
938
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:
|
|
1109
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:40](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-empty-error.ts#L40)
|
|
939
1110
|
|
|
940
1111
|
Error thrown when a directory is not empty.
|
|
941
1112
|
|
|
1113
|
+
#### Example
|
|
1114
|
+
|
|
1115
|
+
```javascript
|
|
1116
|
+
import { NotEmptyError } from "@visulima/fs/error";
|
|
1117
|
+
import { rmdir } from "node:fs/promises"; // Or any fs function that might throw this system error
|
|
1118
|
+
import { join } from "node:path";
|
|
1119
|
+
|
|
1120
|
+
const attemptToRemoveNonEmptyDir = async () => {
|
|
1121
|
+
const dirPath = join("/tmp", "my-non-empty-dir"); // Assume this directory exists and has files
|
|
1122
|
+
try {
|
|
1123
|
+
// Forcing the scenario for demonstration, as rmdir might throw its own specific error.
|
|
1124
|
+
// Node.js fs operations that encounter a non-empty directory when expecting an empty one
|
|
1125
|
+
// typically throw an error with code ENOTEMPTY.
|
|
1126
|
+
const simulateNotEmpty = (path) => {
|
|
1127
|
+
if (path === dirPath) { // Simulate check for non-empty
|
|
1128
|
+
throw new NotEmptyError(`rmdir '${dirPath}'`);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
simulateNotEmpty(dirPath);
|
|
1132
|
+
// await rmdir(dirPath); // This would likely throw an error with code ENOTEMPTY
|
|
1133
|
+
} catch (error) {
|
|
1134
|
+
if (error instanceof NotEmptyError) {
|
|
1135
|
+
console.error(`Operation failed, directory is not empty: ${error.message}`);
|
|
1136
|
+
console.error(`Error code: ${error.code}`); // ENOTEMPTY
|
|
1137
|
+
} else {
|
|
1138
|
+
console.error("An unexpected error occurred:", error);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
|
|
1143
|
+
// You would need to set up a non-empty directory at /tmp/my-non-empty-dir for a real test
|
|
1144
|
+
// import { ensureDirSync, writeFileSync } from "@visulima/fs";
|
|
1145
|
+
// ensureDirSync(dirPath);
|
|
1146
|
+
// writeFileSync(join(dirPath, "somefile.txt"), "content");
|
|
1147
|
+
|
|
1148
|
+
attemptToRemoveNonEmptyDir();
|
|
1149
|
+
```
|
|
1150
|
+
|
|
942
1151
|
#### Extends
|
|
943
1152
|
|
|
944
1153
|
- `Error`
|
|
@@ -951,7 +1160,7 @@ Error thrown when a directory is not empty.
|
|
|
951
1160
|
new NotEmptyError(message): NotEmptyError;
|
|
952
1161
|
```
|
|
953
1162
|
|
|
954
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:
|
|
1163
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:45](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-empty-error.ts#L45)
|
|
955
1164
|
|
|
956
1165
|
Creates a new instance.
|
|
957
1166
|
|
|
@@ -983,7 +1192,7 @@ Error.constructor
|
|
|
983
1192
|
get code(): string;
|
|
984
1193
|
```
|
|
985
1194
|
|
|
986
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:
|
|
1195
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:50](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-empty-error.ts#L50)
|
|
987
1196
|
|
|
988
1197
|
###### Returns
|
|
989
1198
|
|
|
@@ -995,7 +1204,7 @@ Defined in: [packages/fs/src/error/not-empty-error.ts:14](https://github.com/vis
|
|
|
995
1204
|
set code(_name): void;
|
|
996
1205
|
```
|
|
997
1206
|
|
|
998
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:
|
|
1207
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:55](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-empty-error.ts#L55)
|
|
999
1208
|
|
|
1000
1209
|
###### Parameters
|
|
1001
1210
|
|
|
@@ -1015,7 +1224,7 @@ Defined in: [packages/fs/src/error/not-empty-error.ts:19](https://github.com/vis
|
|
|
1015
1224
|
get name(): string;
|
|
1016
1225
|
```
|
|
1017
1226
|
|
|
1018
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:
|
|
1227
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:60](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-empty-error.ts#L60)
|
|
1019
1228
|
|
|
1020
1229
|
###### Returns
|
|
1021
1230
|
|
|
@@ -1027,7 +1236,7 @@ Defined in: [packages/fs/src/error/not-empty-error.ts:24](https://github.com/vis
|
|
|
1027
1236
|
set name(_name): void;
|
|
1028
1237
|
```
|
|
1029
1238
|
|
|
1030
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:
|
|
1239
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:65](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-empty-error.ts#L65)
|
|
1031
1240
|
|
|
1032
1241
|
###### Parameters
|
|
1033
1242
|
|
|
@@ -1173,9 +1382,40 @@ Error.stackTraceLimit
|
|
|
1173
1382
|
|
|
1174
1383
|
### NotFoundError
|
|
1175
1384
|
|
|
1176
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:
|
|
1385
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:33](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-found-error.ts#L33)
|
|
1386
|
+
|
|
1387
|
+
Error thrown when a file or directory is not found at a specified path.
|
|
1388
|
+
|
|
1389
|
+
#### Example
|
|
1177
1390
|
|
|
1178
|
-
|
|
1391
|
+
```javascript
|
|
1392
|
+
import { NotFoundError } from "@visulima/fs/error";
|
|
1393
|
+
import { readFile } from "@visulima/fs"; // Or any function that might throw this
|
|
1394
|
+
import { join } from "node:path";
|
|
1395
|
+
|
|
1396
|
+
const tryReadingNonExistentFile = async () => {
|
|
1397
|
+
const filePath = join("/tmp", "this-file-does-not-exist.txt");
|
|
1398
|
+
try {
|
|
1399
|
+
// Forcing the scenario for demonstration, as readFile itself would throw this.
|
|
1400
|
+
const simulateNotFound = (path) => {
|
|
1401
|
+
if (path === filePath) {
|
|
1402
|
+
throw new NotFoundError(`no such file or directory, open '${filePath}'`);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
simulateNotFound(filePath);
|
|
1406
|
+
// await readFile(filePath);
|
|
1407
|
+
} catch (error) {
|
|
1408
|
+
if (error instanceof NotFoundError) {
|
|
1409
|
+
console.error(`Operation failed, path not found: ${error.message}`);
|
|
1410
|
+
console.error(`Error code: ${error.code}`); // ENOENT
|
|
1411
|
+
} else {
|
|
1412
|
+
console.error("An unexpected error occurred:", error);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
|
|
1417
|
+
tryReadingNonExistentFile();
|
|
1418
|
+
```
|
|
1179
1419
|
|
|
1180
1420
|
#### Extends
|
|
1181
1421
|
|
|
@@ -1189,7 +1429,7 @@ Error thrown when a file or directory is not found.
|
|
|
1189
1429
|
new NotFoundError(message): NotFoundError;
|
|
1190
1430
|
```
|
|
1191
1431
|
|
|
1192
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:
|
|
1432
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:38](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-found-error.ts#L38)
|
|
1193
1433
|
|
|
1194
1434
|
Creates a new instance.
|
|
1195
1435
|
|
|
@@ -1221,7 +1461,7 @@ Error.constructor
|
|
|
1221
1461
|
get code(): string;
|
|
1222
1462
|
```
|
|
1223
1463
|
|
|
1224
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:
|
|
1464
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:43](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-found-error.ts#L43)
|
|
1225
1465
|
|
|
1226
1466
|
###### Returns
|
|
1227
1467
|
|
|
@@ -1233,7 +1473,7 @@ Defined in: [packages/fs/src/error/not-found-error.ts:14](https://github.com/vis
|
|
|
1233
1473
|
set code(_name): void;
|
|
1234
1474
|
```
|
|
1235
1475
|
|
|
1236
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:
|
|
1476
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:48](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-found-error.ts#L48)
|
|
1237
1477
|
|
|
1238
1478
|
###### Parameters
|
|
1239
1479
|
|
|
@@ -1253,7 +1493,7 @@ Defined in: [packages/fs/src/error/not-found-error.ts:19](https://github.com/vis
|
|
|
1253
1493
|
get name(): string;
|
|
1254
1494
|
```
|
|
1255
1495
|
|
|
1256
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:
|
|
1496
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:53](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-found-error.ts#L53)
|
|
1257
1497
|
|
|
1258
1498
|
###### Returns
|
|
1259
1499
|
|
|
@@ -1265,7 +1505,7 @@ Defined in: [packages/fs/src/error/not-found-error.ts:24](https://github.com/vis
|
|
|
1265
1505
|
set name(_name): void;
|
|
1266
1506
|
```
|
|
1267
1507
|
|
|
1268
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:
|
|
1508
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:58](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/not-found-error.ts#L58)
|
|
1269
1509
|
|
|
1270
1510
|
###### Parameters
|
|
1271
1511
|
|
|
@@ -1411,9 +1651,41 @@ Error.stackTraceLimit
|
|
|
1411
1651
|
|
|
1412
1652
|
### PermissionError
|
|
1413
1653
|
|
|
1414
|
-
Defined in: [packages/fs/src/error/permission-error.ts:
|
|
1654
|
+
Defined in: [packages/fs/src/error/permission-error.ts:34](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/permission-error.ts#L34)
|
|
1655
|
+
|
|
1656
|
+
Error thrown when an operation is not permitted due to insufficient privileges
|
|
1657
|
+
or other access control restrictions.
|
|
1658
|
+
|
|
1659
|
+
#### Example
|
|
1415
1660
|
|
|
1416
|
-
|
|
1661
|
+
```javascript
|
|
1662
|
+
import { PermissionError } from "@visulima/fs/error";
|
|
1663
|
+
import { writeFile } from "@visulima/fs"; // Or any function that might throw this
|
|
1664
|
+
import { join } from "node:path";
|
|
1665
|
+
|
|
1666
|
+
const tryWritingToProtectedFile = async () => {
|
|
1667
|
+
const filePath = join("/root", "protected-file.txt"); // A path that typically requires root privileges
|
|
1668
|
+
try {
|
|
1669
|
+
// Forcing the scenario for demonstration, as writeFile itself would throw this.
|
|
1670
|
+
const simulatePermissionError = (path) => {
|
|
1671
|
+
if (path === filePath) {
|
|
1672
|
+
throw new PermissionError(`open '${filePath}'`);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
simulatePermissionError(filePath);
|
|
1676
|
+
// await writeFile(filePath, "test content");
|
|
1677
|
+
} catch (error) {
|
|
1678
|
+
if (error instanceof PermissionError) {
|
|
1679
|
+
console.error(`Operation not permitted: ${error.message}`);
|
|
1680
|
+
console.error(`Error code: ${error.code}`); // EPERM
|
|
1681
|
+
} else {
|
|
1682
|
+
console.error("An unexpected error occurred:", error);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
};
|
|
1686
|
+
|
|
1687
|
+
tryWritingToProtectedFile();
|
|
1688
|
+
```
|
|
1417
1689
|
|
|
1418
1690
|
#### Extends
|
|
1419
1691
|
|
|
@@ -1427,7 +1699,7 @@ Error thrown when an operation is not permitted.
|
|
|
1427
1699
|
new PermissionError(message): PermissionError;
|
|
1428
1700
|
```
|
|
1429
1701
|
|
|
1430
|
-
Defined in: [packages/fs/src/error/permission-error.ts:
|
|
1702
|
+
Defined in: [packages/fs/src/error/permission-error.ts:39](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/permission-error.ts#L39)
|
|
1431
1703
|
|
|
1432
1704
|
Creates a new instance.
|
|
1433
1705
|
|
|
@@ -1459,7 +1731,7 @@ Error.constructor
|
|
|
1459
1731
|
get code(): string;
|
|
1460
1732
|
```
|
|
1461
1733
|
|
|
1462
|
-
Defined in: [packages/fs/src/error/permission-error.ts:
|
|
1734
|
+
Defined in: [packages/fs/src/error/permission-error.ts:44](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/permission-error.ts#L44)
|
|
1463
1735
|
|
|
1464
1736
|
###### Returns
|
|
1465
1737
|
|
|
@@ -1471,7 +1743,7 @@ Defined in: [packages/fs/src/error/permission-error.ts:14](https://github.com/vi
|
|
|
1471
1743
|
set code(_name): void;
|
|
1472
1744
|
```
|
|
1473
1745
|
|
|
1474
|
-
Defined in: [packages/fs/src/error/permission-error.ts:
|
|
1746
|
+
Defined in: [packages/fs/src/error/permission-error.ts:49](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/permission-error.ts#L49)
|
|
1475
1747
|
|
|
1476
1748
|
###### Parameters
|
|
1477
1749
|
|
|
@@ -1491,7 +1763,7 @@ Defined in: [packages/fs/src/error/permission-error.ts:19](https://github.com/vi
|
|
|
1491
1763
|
get name(): string;
|
|
1492
1764
|
```
|
|
1493
1765
|
|
|
1494
|
-
Defined in: [packages/fs/src/error/permission-error.ts:
|
|
1766
|
+
Defined in: [packages/fs/src/error/permission-error.ts:54](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/permission-error.ts#L54)
|
|
1495
1767
|
|
|
1496
1768
|
###### Returns
|
|
1497
1769
|
|
|
@@ -1503,7 +1775,7 @@ Defined in: [packages/fs/src/error/permission-error.ts:24](https://github.com/vi
|
|
|
1503
1775
|
set name(_name): void;
|
|
1504
1776
|
```
|
|
1505
1777
|
|
|
1506
|
-
Defined in: [packages/fs/src/error/permission-error.ts:
|
|
1778
|
+
Defined in: [packages/fs/src/error/permission-error.ts:59](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/permission-error.ts#L59)
|
|
1507
1779
|
|
|
1508
1780
|
###### Parameters
|
|
1509
1781
|
|
|
@@ -1649,10 +1921,47 @@ Error.stackTraceLimit
|
|
|
1649
1921
|
|
|
1650
1922
|
### WalkError
|
|
1651
1923
|
|
|
1652
|
-
Defined in: [packages/fs/src/error/walk-error.ts:
|
|
1924
|
+
Defined in: [packages/fs/src/error/walk-error.ts:43](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/walk-error.ts#L43)
|
|
1653
1925
|
|
|
1654
1926
|
Error thrown in walk or walkSync during iteration.
|
|
1655
1927
|
|
|
1928
|
+
#### Example
|
|
1929
|
+
|
|
1930
|
+
```javascript
|
|
1931
|
+
import { WalkError } from "@visulima/fs/error";
|
|
1932
|
+
import { walk } from "@visulima/fs";
|
|
1933
|
+
import { join } from "node:path";
|
|
1934
|
+
|
|
1935
|
+
const processDirectory = async () => {
|
|
1936
|
+
const dirToWalk = join("/tmp", "non-existent-or-permission-denied-dir");
|
|
1937
|
+
try {
|
|
1938
|
+
// Forcing the scenario: walk might throw a WalkError if it encounters an issue
|
|
1939
|
+
// like a directory it cannot read during the walk process.
|
|
1940
|
+
const simulateWalkError = async (rootDir) => {
|
|
1941
|
+
// Let's say readdir inside walk fails for a subdirectory.
|
|
1942
|
+
const underlyingError = new Error("Permission denied reading subdirectory");
|
|
1943
|
+
throw new WalkError(underlyingError, rootDir);
|
|
1944
|
+
}
|
|
1945
|
+
// This is conceptual. In a real scenario, 'walk' itself would throw.
|
|
1946
|
+
// for await (const entry of walk(dirToWalk)) {
|
|
1947
|
+
// console.log(entry.path);
|
|
1948
|
+
// }
|
|
1949
|
+
await simulateWalkError(dirToWalk);
|
|
1950
|
+
} catch (error) {
|
|
1951
|
+
if (error instanceof WalkError) {
|
|
1952
|
+
console.error(`Error during directory walk of "${error.root}": ${error.message}`);
|
|
1953
|
+
if (error.cause) {
|
|
1954
|
+
console.error(`Underlying cause: ${error.cause}`);
|
|
1955
|
+
}
|
|
1956
|
+
} else {
|
|
1957
|
+
console.error("An unexpected error occurred:", error);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
|
|
1962
|
+
processDirectory();
|
|
1963
|
+
```
|
|
1964
|
+
|
|
1656
1965
|
#### Extends
|
|
1657
1966
|
|
|
1658
1967
|
- `Error`
|
|
@@ -1665,7 +1974,7 @@ Error thrown in walk or walkSync during iteration.
|
|
|
1665
1974
|
new WalkError(cause, root): WalkError;
|
|
1666
1975
|
```
|
|
1667
1976
|
|
|
1668
|
-
Defined in: [packages/fs/src/error/walk-error.ts:
|
|
1977
|
+
Defined in: [packages/fs/src/error/walk-error.ts:52](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/walk-error.ts#L52)
|
|
1669
1978
|
|
|
1670
1979
|
Constructs a new instance.
|
|
1671
1980
|
|
|
@@ -1675,10 +1984,14 @@ Constructs a new instance.
|
|
|
1675
1984
|
|
|
1676
1985
|
`unknown`
|
|
1677
1986
|
|
|
1987
|
+
The underlying error or reason for the walk failure.
|
|
1988
|
+
|
|
1678
1989
|
###### root
|
|
1679
1990
|
|
|
1680
1991
|
`string`
|
|
1681
1992
|
|
|
1993
|
+
The root directory path where the walk operation started or encountered the error.
|
|
1994
|
+
|
|
1682
1995
|
###### Returns
|
|
1683
1996
|
|
|
1684
1997
|
[`WalkError`](#walkerror)
|
|
@@ -1699,7 +2012,7 @@ Error.constructor
|
|
|
1699
2012
|
get name(): string;
|
|
1700
2013
|
```
|
|
1701
2014
|
|
|
1702
|
-
Defined in: [packages/fs/src/error/walk-error.ts:
|
|
2015
|
+
Defined in: [packages/fs/src/error/walk-error.ts:61](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/walk-error.ts#L61)
|
|
1703
2016
|
|
|
1704
2017
|
###### Returns
|
|
1705
2018
|
|
|
@@ -1711,7 +2024,7 @@ Defined in: [packages/fs/src/error/walk-error.ts:21](https://github.com/visulima
|
|
|
1711
2024
|
set name(_name): void;
|
|
1712
2025
|
```
|
|
1713
2026
|
|
|
1714
|
-
Defined in: [packages/fs/src/error/walk-error.ts:
|
|
2027
|
+
Defined in: [packages/fs/src/error/walk-error.ts:66](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/walk-error.ts#L66)
|
|
1715
2028
|
|
|
1716
2029
|
###### Parameters
|
|
1717
2030
|
|
|
@@ -1797,7 +2110,7 @@ Error.message
|
|
|
1797
2110
|
root: string;
|
|
1798
2111
|
```
|
|
1799
2112
|
|
|
1800
|
-
Defined in: [packages/fs/src/error/walk-error.ts:
|
|
2113
|
+
Defined in: [packages/fs/src/error/walk-error.ts:45](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/walk-error.ts#L45)
|
|
1801
2114
|
|
|
1802
2115
|
File path of the root that's being walked.
|
|
1803
2116
|
|
|
@@ -1878,7 +2191,10 @@ Re-exports [JSONError](utils.md#jsonerror)
|
|
|
1878
2191
|
function collect(directory, options): Promise<string[]>;
|
|
1879
2192
|
```
|
|
1880
2193
|
|
|
1881
|
-
Defined in: [packages/fs/src/find/collect.ts:
|
|
2194
|
+
Defined in: [packages/fs/src/find/collect.ts:37](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/find/collect.ts#L37)
|
|
2195
|
+
|
|
2196
|
+
Asynchronously collects all file paths within a directory that match the specified criteria.
|
|
2197
|
+
By default, it searches for JavaScript and TypeScript file extensions.
|
|
1882
2198
|
|
|
1883
2199
|
#### Parameters
|
|
1884
2200
|
|
|
@@ -1886,14 +2202,47 @@ Defined in: [packages/fs/src/find/collect.ts:4](https://github.com/visulima/visu
|
|
|
1886
2202
|
|
|
1887
2203
|
`string`
|
|
1888
2204
|
|
|
2205
|
+
The root directory to start collecting files from.
|
|
2206
|
+
|
|
1889
2207
|
##### options
|
|
1890
2208
|
|
|
1891
2209
|
[`WalkOptions`](#walkoptions) = `{}`
|
|
1892
2210
|
|
|
2211
|
+
Optional configuration to control the collection process. See [WalkOptions](#walkoptions).
|
|
2212
|
+
|
|
1893
2213
|
#### Returns
|
|
1894
2214
|
|
|
1895
2215
|
`Promise`\<`string`[]\>
|
|
1896
2216
|
|
|
2217
|
+
A promise that resolves to an array of absolute file paths.
|
|
2218
|
+
|
|
2219
|
+
#### Example
|
|
2220
|
+
|
|
2221
|
+
```javascript
|
|
2222
|
+
import { collect } from "@visulima/fs";
|
|
2223
|
+
import { join } from "node:path";
|
|
2224
|
+
|
|
2225
|
+
const collectFiles = async () => {
|
|
2226
|
+
// Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
|
|
2227
|
+
const files = await collect(join("/tmp", "docs"), {
|
|
2228
|
+
extensions: ["txt", "md"],
|
|
2229
|
+
maxDepth: 2,
|
|
2230
|
+
includeDirs: false, // Only collect files
|
|
2231
|
+
});
|
|
2232
|
+
console.log(files);
|
|
2233
|
+
// Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
|
|
2234
|
+
|
|
2235
|
+
// Collect all .js files, excluding anything in node_modules
|
|
2236
|
+
const jsFiles = await collect(join("/tmp", "project"), {
|
|
2237
|
+
extensions: ["js"],
|
|
2238
|
+
skip: [/node_modules/],
|
|
2239
|
+
});
|
|
2240
|
+
console.log(jsFiles);
|
|
2241
|
+
};
|
|
2242
|
+
|
|
2243
|
+
collectFiles();
|
|
2244
|
+
```
|
|
2245
|
+
|
|
1897
2246
|
***
|
|
1898
2247
|
|
|
1899
2248
|
### collectSync()
|
|
@@ -1902,7 +2251,10 @@ Defined in: [packages/fs/src/find/collect.ts:4](https://github.com/visulima/visu
|
|
|
1902
2251
|
function collectSync(directory, options): string[];
|
|
1903
2252
|
```
|
|
1904
2253
|
|
|
1905
|
-
Defined in: [packages/fs/src/find/collect-sync.ts:
|
|
2254
|
+
Defined in: [packages/fs/src/find/collect-sync.ts:33](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/find/collect-sync.ts#L33)
|
|
2255
|
+
|
|
2256
|
+
Synchronously collects all file paths within a directory that match the specified criteria.
|
|
2257
|
+
By default, it searches for JavaScript and TypeScript file extensions.
|
|
1906
2258
|
|
|
1907
2259
|
#### Parameters
|
|
1908
2260
|
|
|
@@ -1910,36 +2262,42 @@ Defined in: [packages/fs/src/find/collect-sync.ts:4](https://github.com/visulima
|
|
|
1910
2262
|
|
|
1911
2263
|
`string`
|
|
1912
2264
|
|
|
2265
|
+
The root directory to start collecting files from.
|
|
2266
|
+
|
|
1913
2267
|
##### options
|
|
1914
2268
|
|
|
1915
2269
|
[`WalkOptions`](#walkoptions) = `{}`
|
|
1916
2270
|
|
|
2271
|
+
Optional configuration to control the collection process. See [WalkOptions](#walkoptions).
|
|
2272
|
+
|
|
1917
2273
|
#### Returns
|
|
1918
2274
|
|
|
1919
2275
|
`string`[]
|
|
1920
2276
|
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
### detect()
|
|
1924
|
-
|
|
1925
|
-
```ts
|
|
1926
|
-
function detect(content): "\n" | "\r\n";
|
|
1927
|
-
```
|
|
1928
|
-
|
|
1929
|
-
Defined in: [packages/fs/src/eol.ts:20](https://github.com/visulima/visulima/blob/605d0fc030334277c4a55eed06631ab95f470bdd/packages/fs/src/eol.ts#L20)
|
|
1930
|
-
|
|
1931
|
-
Detect the EOL character for string input.
|
|
1932
|
-
Returns null if no newline.
|
|
1933
|
-
|
|
1934
|
-
#### Parameters
|
|
2277
|
+
An array of absolute file paths.
|
|
1935
2278
|
|
|
1936
|
-
|
|
2279
|
+
#### Example
|
|
1937
2280
|
|
|
1938
|
-
|
|
2281
|
+
```javascript
|
|
2282
|
+
import { collectSync } from "@visulima/fs";
|
|
2283
|
+
import { join } from "node:path";
|
|
1939
2284
|
|
|
1940
|
-
|
|
2285
|
+
// Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
|
|
2286
|
+
const files = collectSync(join("/tmp", "docs"), {
|
|
2287
|
+
extensions: ["txt", "md"],
|
|
2288
|
+
maxDepth: 2,
|
|
2289
|
+
includeDirs: false, // Only collect files
|
|
2290
|
+
});
|
|
2291
|
+
console.log(files);
|
|
2292
|
+
// Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
|
|
1941
2293
|
|
|
1942
|
-
|
|
2294
|
+
// Collect all .js files, excluding anything in node_modules
|
|
2295
|
+
const jsFiles = collectSync(join("/tmp", "project"), {
|
|
2296
|
+
extensions: ["js"],
|
|
2297
|
+
skip: [/node_modules/],
|
|
2298
|
+
});
|
|
2299
|
+
console.log(jsFiles);
|
|
2300
|
+
```
|
|
1943
2301
|
|
|
1944
2302
|
***
|
|
1945
2303
|
|
|
@@ -1949,7 +2307,7 @@ Returns null if no newline.
|
|
|
1949
2307
|
function emptyDir(dir, options?): Promise<void>;
|
|
1950
2308
|
```
|
|
1951
2309
|
|
|
1952
|
-
Defined in: [packages/fs/src/remove/empty-dir.ts:
|
|
2310
|
+
Defined in: [packages/fs/src/remove/empty-dir.ts:38](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/remove/empty-dir.ts#L38)
|
|
1953
2311
|
|
|
1954
2312
|
Ensures that a directory is empty.
|
|
1955
2313
|
Deletes directory contents if the directory is not empty.
|
|
@@ -1960,16 +2318,40 @@ The directory itself is not deleted.
|
|
|
1960
2318
|
|
|
1961
2319
|
##### dir
|
|
1962
2320
|
|
|
2321
|
+
The path to the directory to empty.
|
|
2322
|
+
|
|
1963
2323
|
`string` | `URL`
|
|
1964
2324
|
|
|
1965
2325
|
##### options?
|
|
1966
2326
|
|
|
1967
|
-
|
|
2327
|
+
`RetryOptions`
|
|
2328
|
+
|
|
2329
|
+
Optional configuration for the operation. See RetryOptions.
|
|
1968
2330
|
|
|
1969
2331
|
#### Returns
|
|
1970
2332
|
|
|
1971
2333
|
`Promise`\<`void`\>
|
|
1972
2334
|
|
|
2335
|
+
A promise that resolves when the directory is empty.
|
|
2336
|
+
|
|
2337
|
+
#### Example
|
|
2338
|
+
|
|
2339
|
+
```javascript
|
|
2340
|
+
import { emptyDir } from "@visulima/fs";
|
|
2341
|
+
import { join } from "node:path";
|
|
2342
|
+
|
|
2343
|
+
const clearTempDir = async () => {
|
|
2344
|
+
try {
|
|
2345
|
+
await emptyDir(join("/tmp", "my-app-temp"));
|
|
2346
|
+
console.log("Temporary directory emptied or created.");
|
|
2347
|
+
} catch (error) {
|
|
2348
|
+
console.error("Failed to empty directory:", error);
|
|
2349
|
+
}
|
|
2350
|
+
};
|
|
2351
|
+
|
|
2352
|
+
clearTempDir();
|
|
2353
|
+
```
|
|
2354
|
+
|
|
1973
2355
|
***
|
|
1974
2356
|
|
|
1975
2357
|
### emptyDirSync()
|
|
@@ -1978,7 +2360,7 @@ The directory itself is not deleted.
|
|
|
1978
2360
|
function emptyDirSync(dir, options?): void;
|
|
1979
2361
|
```
|
|
1980
2362
|
|
|
1981
|
-
Defined in: [packages/fs/src/remove/empty-dir-sync.ts:
|
|
2363
|
+
Defined in: [packages/fs/src/remove/empty-dir-sync.ts:33](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/remove/empty-dir-sync.ts#L33)
|
|
1982
2364
|
|
|
1983
2365
|
Ensures that a directory is empty.
|
|
1984
2366
|
Deletes directory contents if the directory is not empty.
|
|
@@ -1989,16 +2371,36 @@ The directory itself is not deleted.
|
|
|
1989
2371
|
|
|
1990
2372
|
##### dir
|
|
1991
2373
|
|
|
2374
|
+
The path to the directory to empty.
|
|
2375
|
+
|
|
1992
2376
|
`string` | `URL`
|
|
1993
2377
|
|
|
1994
2378
|
##### options?
|
|
1995
2379
|
|
|
1996
|
-
|
|
2380
|
+
`RetryOptions`
|
|
2381
|
+
|
|
2382
|
+
Optional configuration for the operation. See RetryOptions.
|
|
1997
2383
|
|
|
1998
2384
|
#### Returns
|
|
1999
2385
|
|
|
2000
2386
|
`void`
|
|
2001
2387
|
|
|
2388
|
+
void
|
|
2389
|
+
|
|
2390
|
+
#### Example
|
|
2391
|
+
|
|
2392
|
+
```javascript
|
|
2393
|
+
import { emptyDirSync } from "@visulima/fs";
|
|
2394
|
+
import { join } from "node:path";
|
|
2395
|
+
|
|
2396
|
+
try {
|
|
2397
|
+
emptyDirSync(join("/tmp", "my-app-temp"));
|
|
2398
|
+
console.log("Temporary directory emptied or created.");
|
|
2399
|
+
} catch (error) {
|
|
2400
|
+
console.error("Failed to empty directory:", error);
|
|
2401
|
+
}
|
|
2402
|
+
```
|
|
2403
|
+
|
|
2002
2404
|
***
|
|
2003
2405
|
|
|
2004
2406
|
### ensureDir()
|
|
@@ -2007,7 +2409,7 @@ The directory itself is not deleted.
|
|
|
2007
2409
|
function ensureDir(directory): Promise<void>;
|
|
2008
2410
|
```
|
|
2009
2411
|
|
|
2010
|
-
Defined in: [packages/fs/src/ensure/ensure-dir.ts:
|
|
2412
|
+
Defined in: [packages/fs/src/ensure/ensure-dir.ts:20](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/ensure/ensure-dir.ts#L20)
|
|
2011
2413
|
|
|
2012
2414
|
Ensures that the directory exists.
|
|
2013
2415
|
If the directory structure does not exist, it is created. Like mkdir -p.
|
|
@@ -2016,12 +2418,23 @@ If the directory structure does not exist, it is created. Like mkdir -p.
|
|
|
2016
2418
|
|
|
2017
2419
|
##### directory
|
|
2018
2420
|
|
|
2421
|
+
The path to the directory to ensure exists.
|
|
2422
|
+
|
|
2019
2423
|
`string` | `URL`
|
|
2020
2424
|
|
|
2021
2425
|
#### Returns
|
|
2022
2426
|
|
|
2023
2427
|
`Promise`\<`void`\>
|
|
2024
2428
|
|
|
2429
|
+
#### Example
|
|
2430
|
+
|
|
2431
|
+
```javascript
|
|
2432
|
+
import ensureDir from "@visulima/fs/ensure/ensure-dir";
|
|
2433
|
+
|
|
2434
|
+
await ensureDir("/tmp/foo/bar/baz");
|
|
2435
|
+
// Creates the directory structure /tmp/foo/bar/baz if it doesn't exist
|
|
2436
|
+
```
|
|
2437
|
+
|
|
2025
2438
|
***
|
|
2026
2439
|
|
|
2027
2440
|
### ensureDirSync()
|
|
@@ -2030,7 +2443,7 @@ If the directory structure does not exist, it is created. Like mkdir -p.
|
|
|
2030
2443
|
function ensureDirSync(directory): void;
|
|
2031
2444
|
```
|
|
2032
2445
|
|
|
2033
|
-
Defined in: [packages/fs/src/ensure/ensure-dir-sync.ts:
|
|
2446
|
+
Defined in: [packages/fs/src/ensure/ensure-dir-sync.ts:20](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/ensure/ensure-dir-sync.ts#L20)
|
|
2034
2447
|
|
|
2035
2448
|
Ensures that the directory exists.
|
|
2036
2449
|
If the directory structure does not exist, it is created. Like mkdir -p.
|
|
@@ -2039,12 +2452,23 @@ If the directory structure does not exist, it is created. Like mkdir -p.
|
|
|
2039
2452
|
|
|
2040
2453
|
##### directory
|
|
2041
2454
|
|
|
2455
|
+
The path to the directory to ensure exists.
|
|
2456
|
+
|
|
2042
2457
|
`string` | `URL`
|
|
2043
2458
|
|
|
2044
2459
|
#### Returns
|
|
2045
2460
|
|
|
2046
2461
|
`void`
|
|
2047
2462
|
|
|
2463
|
+
#### Example
|
|
2464
|
+
|
|
2465
|
+
```javascript
|
|
2466
|
+
import ensureDirSync from "@visulima/fs/ensure/ensure-dir-sync";
|
|
2467
|
+
|
|
2468
|
+
ensureDirSync("/tmp/foo/bar/baz");
|
|
2469
|
+
// Creates the directory structure /tmp/foo/bar/baz if it doesn't exist
|
|
2470
|
+
```
|
|
2471
|
+
|
|
2048
2472
|
***
|
|
2049
2473
|
|
|
2050
2474
|
### ensureFile()
|
|
@@ -2053,22 +2477,52 @@ If the directory structure does not exist, it is created. Like mkdir -p.
|
|
|
2053
2477
|
function ensureFile(filePath): Promise<void>;
|
|
2054
2478
|
```
|
|
2055
2479
|
|
|
2056
|
-
Defined in: [packages/fs/src/ensure/ensure-file.ts:
|
|
2480
|
+
Defined in: [packages/fs/src/ensure/ensure-file.ts:37](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/ensure/ensure-file.ts#L37)
|
|
2057
2481
|
|
|
2058
|
-
|
|
2059
|
-
If the
|
|
2060
|
-
|
|
2482
|
+
Asynchronously ensures that a file exists.
|
|
2483
|
+
If the directory structure for the file does not exist, it is created.
|
|
2484
|
+
If the file already exists, it is not modified.
|
|
2061
2485
|
|
|
2062
2486
|
#### Parameters
|
|
2063
2487
|
|
|
2064
2488
|
##### filePath
|
|
2065
2489
|
|
|
2490
|
+
The path to the file. Can be a string or a URL object.
|
|
2491
|
+
|
|
2066
2492
|
`string` | `URL`
|
|
2067
2493
|
|
|
2068
2494
|
#### Returns
|
|
2069
2495
|
|
|
2070
2496
|
`Promise`\<`void`\>
|
|
2071
2497
|
|
|
2498
|
+
A Promise that resolves when the file has been created or confirmed to exist.
|
|
2499
|
+
|
|
2500
|
+
#### Throws
|
|
2501
|
+
|
|
2502
|
+
Will throw an error if the path exists and is not a file.
|
|
2503
|
+
|
|
2504
|
+
#### Throws
|
|
2505
|
+
|
|
2506
|
+
Will throw an error if directory or file creation fails for reasons other than the path not existing initially.
|
|
2507
|
+
|
|
2508
|
+
#### Example
|
|
2509
|
+
|
|
2510
|
+
```typescript
|
|
2511
|
+
import { ensureFile } from "@visulima/fs";
|
|
2512
|
+
|
|
2513
|
+
(async () => {
|
|
2514
|
+
try {
|
|
2515
|
+
await ensureFile("path/to/my/file.txt");
|
|
2516
|
+
console.log("File ensured!");
|
|
2517
|
+
|
|
2518
|
+
await ensureFile(new URL("file:///path/to/another/file.log"));
|
|
2519
|
+
console.log("Another file ensured!");
|
|
2520
|
+
} catch (error) {
|
|
2521
|
+
console.error("Failed to ensure file:", error);
|
|
2522
|
+
}
|
|
2523
|
+
})();
|
|
2524
|
+
```
|
|
2525
|
+
|
|
2072
2526
|
***
|
|
2073
2527
|
|
|
2074
2528
|
### ensureFileSync()
|
|
@@ -2077,22 +2531,33 @@ these directories are created. If the file already exists, it is NOTMODIFIED.
|
|
|
2077
2531
|
function ensureFileSync(filePath): void;
|
|
2078
2532
|
```
|
|
2079
2533
|
|
|
2080
|
-
Defined in: [packages/fs/src/ensure/ensure-file-sync.ts:
|
|
2534
|
+
Defined in: [packages/fs/src/ensure/ensure-file-sync.ts:24](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/ensure/ensure-file-sync.ts#L24)
|
|
2081
2535
|
|
|
2082
2536
|
Ensures that the file exists.
|
|
2083
2537
|
If the file that is requested to be created is in directories that do not exist,
|
|
2084
|
-
these directories are created. If the file already exists, it is
|
|
2538
|
+
these directories are created. If the file already exists, it is NOT MODIFIED.
|
|
2085
2539
|
|
|
2086
2540
|
#### Parameters
|
|
2087
2541
|
|
|
2088
2542
|
##### filePath
|
|
2089
2543
|
|
|
2544
|
+
The path to the file to ensure exists.
|
|
2545
|
+
|
|
2090
2546
|
`string` | `URL`
|
|
2091
2547
|
|
|
2092
2548
|
#### Returns
|
|
2093
2549
|
|
|
2094
2550
|
`void`
|
|
2095
2551
|
|
|
2552
|
+
#### Example
|
|
2553
|
+
|
|
2554
|
+
```javascript
|
|
2555
|
+
import { ensureFileSync } from "@visulima/fs";
|
|
2556
|
+
|
|
2557
|
+
ensureFileSync("/tmp/foo/bar/baz.txt");
|
|
2558
|
+
// Creates the file /tmp/foo/bar/baz.txt and any missing parent directories if they don't exist
|
|
2559
|
+
```
|
|
2560
|
+
|
|
2096
2561
|
***
|
|
2097
2562
|
|
|
2098
2563
|
### ensureLink()
|
|
@@ -2101,7 +2566,7 @@ these directories are created. If the file already exists, it is NOTMODIFIED.
|
|
|
2101
2566
|
function ensureLink(source, destination): Promise<void>;
|
|
2102
2567
|
```
|
|
2103
2568
|
|
|
2104
|
-
Defined in: [packages/fs/src/ensure/ensure-link.ts:
|
|
2569
|
+
Defined in: [packages/fs/src/ensure/ensure-link.ts:25](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/ensure/ensure-link.ts#L25)
|
|
2105
2570
|
|
|
2106
2571
|
Ensures that the hard link exists.
|
|
2107
2572
|
If the directory structure does not exist, it is created.
|
|
@@ -2110,16 +2575,30 @@ If the directory structure does not exist, it is created.
|
|
|
2110
2575
|
|
|
2111
2576
|
##### source
|
|
2112
2577
|
|
|
2578
|
+
The path to the source file or directory.
|
|
2579
|
+
|
|
2113
2580
|
`string` | `URL`
|
|
2114
2581
|
|
|
2115
2582
|
##### destination
|
|
2116
2583
|
|
|
2584
|
+
The path to the destination link.
|
|
2585
|
+
|
|
2117
2586
|
`string` | `URL`
|
|
2118
2587
|
|
|
2119
2588
|
#### Returns
|
|
2120
2589
|
|
|
2121
2590
|
`Promise`\<`void`\>
|
|
2122
2591
|
|
|
2592
|
+
#### Example
|
|
2593
|
+
|
|
2594
|
+
```javascript
|
|
2595
|
+
import { ensureLink } from "@visulima/fs";
|
|
2596
|
+
import { join } from "node:path";
|
|
2597
|
+
|
|
2598
|
+
// ensure the link /tmp/foo/bar-link.txt points to /tmp/foo/bar.txt
|
|
2599
|
+
await ensureLink(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "bar-link.txt"));
|
|
2600
|
+
```
|
|
2601
|
+
|
|
2123
2602
|
***
|
|
2124
2603
|
|
|
2125
2604
|
### ensureLinkSync()
|
|
@@ -2128,7 +2607,7 @@ If the directory structure does not exist, it is created.
|
|
|
2128
2607
|
function ensureLinkSync(source, destination): void;
|
|
2129
2608
|
```
|
|
2130
2609
|
|
|
2131
|
-
Defined in: [packages/fs/src/ensure/ensure-link-sync.ts:
|
|
2610
|
+
Defined in: [packages/fs/src/ensure/ensure-link-sync.ts:25](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/ensure/ensure-link-sync.ts#L25)
|
|
2132
2611
|
|
|
2133
2612
|
Ensures that the hard link exists.
|
|
2134
2613
|
If the directory structure does not exist, it is created.
|
|
@@ -2137,16 +2616,30 @@ If the directory structure does not exist, it is created.
|
|
|
2137
2616
|
|
|
2138
2617
|
##### source
|
|
2139
2618
|
|
|
2619
|
+
The path to the source file or directory.
|
|
2620
|
+
|
|
2140
2621
|
`string` | `URL`
|
|
2141
2622
|
|
|
2142
2623
|
##### destination
|
|
2143
2624
|
|
|
2625
|
+
The path to the destination link.
|
|
2626
|
+
|
|
2144
2627
|
`string` | `URL`
|
|
2145
2628
|
|
|
2146
2629
|
#### Returns
|
|
2147
2630
|
|
|
2148
2631
|
`void`
|
|
2149
2632
|
|
|
2633
|
+
#### Example
|
|
2634
|
+
|
|
2635
|
+
```javascript
|
|
2636
|
+
import { ensureLinkSync } from "@visulima/fs";
|
|
2637
|
+
import { join } from "node:path";
|
|
2638
|
+
|
|
2639
|
+
// ensure the link /tmp/foo/bar-link.txt points to /tmp/foo/bar.txt
|
|
2640
|
+
ensureLinkSync(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "bar-link.txt"));
|
|
2641
|
+
```
|
|
2642
|
+
|
|
2150
2643
|
***
|
|
2151
2644
|
|
|
2152
2645
|
### ensureSymlink()
|
|
@@ -2158,7 +2651,7 @@ function ensureSymlink(
|
|
|
2158
2651
|
type?): Promise<void>;
|
|
2159
2652
|
```
|
|
2160
2653
|
|
|
2161
|
-
Defined in: [packages/fs/src/ensure/ensure-symlink.ts:
|
|
2654
|
+
Defined in: [packages/fs/src/ensure/ensure-symlink.ts:39](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/ensure/ensure-symlink.ts#L39)
|
|
2162
2655
|
|
|
2163
2656
|
Ensures that the link exists, and points to a valid file.
|
|
2164
2657
|
If the directory structure does not exist, it is created.
|
|
@@ -2190,6 +2683,19 @@ the type of the symlink, or null to use automatic detection
|
|
|
2190
2683
|
|
|
2191
2684
|
A void promise that resolves once the link exists.
|
|
2192
2685
|
|
|
2686
|
+
#### Example
|
|
2687
|
+
|
|
2688
|
+
```javascript
|
|
2689
|
+
import { ensureSymlink } from "@visulima/fs";
|
|
2690
|
+
import { join } from "node:path";
|
|
2691
|
+
|
|
2692
|
+
// Ensure a symlink /tmp/foo/link-to-bar.txt points to /tmp/foo/bar.txt
|
|
2693
|
+
await ensureSymlink(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "link-to-bar.txt"));
|
|
2694
|
+
|
|
2695
|
+
// Ensure a directory symlink /tmp/foo/link-to-baz-dir points to /tmp/foo/baz-dir
|
|
2696
|
+
await ensureSymlink(join("/tmp", "foo", "baz-dir"), join("/tmp", "foo", "link-to-baz-dir"), "dir");
|
|
2697
|
+
```
|
|
2698
|
+
|
|
2193
2699
|
***
|
|
2194
2700
|
|
|
2195
2701
|
### ensureSymlinkSync()
|
|
@@ -2201,7 +2707,7 @@ function ensureSymlinkSync(
|
|
|
2201
2707
|
type?): void;
|
|
2202
2708
|
```
|
|
2203
2709
|
|
|
2204
|
-
Defined in: [packages/fs/src/ensure/ensure-symlink-sync.ts:
|
|
2710
|
+
Defined in: [packages/fs/src/ensure/ensure-symlink-sync.ts:39](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/ensure/ensure-symlink-sync.ts#L39)
|
|
2205
2711
|
|
|
2206
2712
|
Ensures that the link exists, and points to a valid file.
|
|
2207
2713
|
If the directory structure does not exist, it is created.
|
|
@@ -2233,6 +2739,19 @@ the type of the symlink, or null to use automatic detection
|
|
|
2233
2739
|
|
|
2234
2740
|
A void.
|
|
2235
2741
|
|
|
2742
|
+
#### Example
|
|
2743
|
+
|
|
2744
|
+
```javascript
|
|
2745
|
+
import { ensureSymlinkSync } from "@visulima/fs";
|
|
2746
|
+
import { join } from "node:path";
|
|
2747
|
+
|
|
2748
|
+
// Ensure a symlink /tmp/foo/link-to-bar.txt points to /tmp/foo/bar.txt
|
|
2749
|
+
ensureSymlinkSync(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "link-to-bar.txt"));
|
|
2750
|
+
|
|
2751
|
+
// Ensure a directory symlink /tmp/foo/link-to-baz-dir points to /tmp/foo/baz-dir
|
|
2752
|
+
ensureSymlinkSync(join("/tmp", "foo", "baz-dir"), join("/tmp", "foo", "link-to-baz-dir"), "dir");
|
|
2753
|
+
```
|
|
2754
|
+
|
|
2236
2755
|
***
|
|
2237
2756
|
|
|
2238
2757
|
### findUp()
|
|
@@ -2241,7 +2760,9 @@ A void.
|
|
|
2241
2760
|
function findUp(name, options): Promise<string>;
|
|
2242
2761
|
```
|
|
2243
2762
|
|
|
2244
|
-
Defined in: [packages/fs/src/find/find-up.ts:
|
|
2763
|
+
Defined in: [packages/fs/src/find/find-up.ts:55](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/find/find-up.ts#L55)
|
|
2764
|
+
|
|
2765
|
+
Asynchronously finds a file or directory by walking up parent directories.
|
|
2245
2766
|
|
|
2246
2767
|
#### Parameters
|
|
2247
2768
|
|
|
@@ -2249,14 +2770,59 @@ Defined in: [packages/fs/src/find/find-up.ts:11](https://github.com/visulima/vis
|
|
|
2249
2770
|
|
|
2250
2771
|
[`FindUpName`](#findupname)
|
|
2251
2772
|
|
|
2773
|
+
The name(s) of the file or directory to find. Can be a string, an array of strings, or a function that returns a name or `FIND_UP_STOP`.
|
|
2774
|
+
|
|
2252
2775
|
##### options
|
|
2253
2776
|
|
|
2254
2777
|
[`FindUpOptions`](#findupoptions) = `{}`
|
|
2255
2778
|
|
|
2779
|
+
Optional configuration for the search. See [FindUpOptions](#findupoptions).
|
|
2780
|
+
|
|
2256
2781
|
#### Returns
|
|
2257
2782
|
|
|
2258
2783
|
`Promise`\<`string`\>
|
|
2259
2784
|
|
|
2785
|
+
A promise that resolves to the absolute path of the first found file/directory, or `undefined` if not found.
|
|
2786
|
+
|
|
2787
|
+
#### Example
|
|
2788
|
+
|
|
2789
|
+
```javascript
|
|
2790
|
+
import { findUp } from "@visulima/fs";
|
|
2791
|
+
import { join } from "node:path";
|
|
2792
|
+
|
|
2793
|
+
const findProjectRoot = async () => {
|
|
2794
|
+
// Find the closest package.json, starting from /tmp/foo/bar/baz
|
|
2795
|
+
const projectRoot = await findUp("package.json", {
|
|
2796
|
+
cwd: join("/tmp", "foo", "bar", "baz"),
|
|
2797
|
+
type: "file",
|
|
2798
|
+
});
|
|
2799
|
+
console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
|
|
2800
|
+
|
|
2801
|
+
// Find the closest .git directory or a README.md file
|
|
2802
|
+
const gitDirOrReadme = await findUp([".git", "README.md"], {
|
|
2803
|
+
cwd: join("/tmp", "foo", "bar"),
|
|
2804
|
+
});
|
|
2805
|
+
console.log(gitDirOrReadme);
|
|
2806
|
+
|
|
2807
|
+
// Find using a custom function, stopping at /tmp
|
|
2808
|
+
const customFound = await findUp(
|
|
2809
|
+
(directory) => {
|
|
2810
|
+
if (directory === join("/tmp", "foo")) {
|
|
2811
|
+
return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
|
|
2812
|
+
}
|
|
2813
|
+
return undefined;
|
|
2814
|
+
},
|
|
2815
|
+
{
|
|
2816
|
+
cwd: join("/tmp", "foo", "bar", "baz"),
|
|
2817
|
+
stopAt: join("/tmp"),
|
|
2818
|
+
}
|
|
2819
|
+
);
|
|
2820
|
+
console.log(customFound);
|
|
2821
|
+
};
|
|
2822
|
+
|
|
2823
|
+
findProjectRoot();
|
|
2824
|
+
```
|
|
2825
|
+
|
|
2260
2826
|
***
|
|
2261
2827
|
|
|
2262
2828
|
### findUpSync()
|
|
@@ -2265,7 +2831,9 @@ Defined in: [packages/fs/src/find/find-up.ts:11](https://github.com/visulima/vis
|
|
|
2265
2831
|
function findUpSync(name, options): string;
|
|
2266
2832
|
```
|
|
2267
2833
|
|
|
2268
|
-
Defined in: [packages/fs/src/find/find-up-sync.ts:
|
|
2834
|
+
Defined in: [packages/fs/src/find/find-up-sync.ts:51](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/find/find-up-sync.ts#L51)
|
|
2835
|
+
|
|
2836
|
+
Synchronously finds a file or directory by walking up parent directories.
|
|
2269
2837
|
|
|
2270
2838
|
#### Parameters
|
|
2271
2839
|
|
|
@@ -2273,51 +2841,122 @@ Defined in: [packages/fs/src/find/find-up-sync.ts:11](https://github.com/visulim
|
|
|
2273
2841
|
|
|
2274
2842
|
[`FindUpNameSync`](#findupnamesync)
|
|
2275
2843
|
|
|
2844
|
+
The name(s) of the file or directory to find. Can be a string, an array of strings, or a function that returns a name or `FIND_UP_STOP`.
|
|
2845
|
+
|
|
2276
2846
|
##### options
|
|
2277
2847
|
|
|
2278
2848
|
[`FindUpOptions`](#findupoptions) = `{}`
|
|
2279
2849
|
|
|
2850
|
+
Optional configuration for the search. See [FindUpOptions](#findupoptions).
|
|
2851
|
+
|
|
2280
2852
|
#### Returns
|
|
2281
2853
|
|
|
2282
2854
|
`string`
|
|
2283
2855
|
|
|
2856
|
+
The absolute path of the first found file/directory, or `undefined` if not found.
|
|
2857
|
+
|
|
2858
|
+
#### Example
|
|
2859
|
+
|
|
2860
|
+
```javascript
|
|
2861
|
+
import { findUpSync } from "@visulima/fs";
|
|
2862
|
+
import { join } from "node:path";
|
|
2863
|
+
|
|
2864
|
+
// Find the closest package.json, starting from /tmp/foo/bar/baz
|
|
2865
|
+
const projectRoot = findUpSync("package.json", {
|
|
2866
|
+
cwd: join("/tmp", "foo", "bar", "baz"),
|
|
2867
|
+
type: "file",
|
|
2868
|
+
});
|
|
2869
|
+
console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
|
|
2870
|
+
|
|
2871
|
+
// Find the closest .git directory or a README.md file
|
|
2872
|
+
const gitDirOrReadme = findUpSync([".git", "README.md"], {
|
|
2873
|
+
cwd: join("/tmp", "foo", "bar"),
|
|
2874
|
+
});
|
|
2875
|
+
console.log(gitDirOrReadme);
|
|
2876
|
+
|
|
2877
|
+
// Find using a custom function, stopping at /tmp
|
|
2878
|
+
const customFound = findUpSync(
|
|
2879
|
+
(directory) => {
|
|
2880
|
+
if (directory === join("/tmp", "foo")) {
|
|
2881
|
+
return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
|
|
2882
|
+
}
|
|
2883
|
+
return undefined;
|
|
2884
|
+
},
|
|
2885
|
+
{
|
|
2886
|
+
cwd: join("/tmp", "foo", "bar", "baz"),
|
|
2887
|
+
stopAt: join("/tmp"),
|
|
2888
|
+
}
|
|
2889
|
+
);
|
|
2890
|
+
console.log(customFound);
|
|
2891
|
+
```
|
|
2892
|
+
|
|
2284
2893
|
***
|
|
2285
2894
|
|
|
2286
|
-
###
|
|
2895
|
+
### isAccessible()
|
|
2287
2896
|
|
|
2288
2897
|
```ts
|
|
2289
|
-
function
|
|
2898
|
+
function isAccessible(path, mode?): Promise<boolean>;
|
|
2290
2899
|
```
|
|
2291
2900
|
|
|
2292
|
-
Defined in: [packages/fs/src/
|
|
2901
|
+
Defined in: [packages/fs/src/is-accessible.ts:36](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/is-accessible.ts#L36)
|
|
2293
2902
|
|
|
2294
|
-
|
|
2903
|
+
Asynchronously tests a user's permissions for the file or directory specified by path.
|
|
2904
|
+
Returns a Promise that resolves to `true` if the accessibility check is successful, `false` otherwise.
|
|
2295
2905
|
|
|
2296
2906
|
#### Parameters
|
|
2297
2907
|
|
|
2298
|
-
#####
|
|
2908
|
+
##### path
|
|
2299
2909
|
|
|
2300
|
-
|
|
2910
|
+
The path to the file or directory. Can be a string or a URL object.
|
|
2301
2911
|
|
|
2302
|
-
|
|
2912
|
+
`string` | `URL`
|
|
2303
2913
|
|
|
2304
|
-
|
|
2914
|
+
##### mode?
|
|
2915
|
+
|
|
2916
|
+
`number`
|
|
2917
|
+
|
|
2918
|
+
The accessibility checks to perform. Defaults to `F_OK` (check for existence).
|
|
2919
|
+
Other possible values include `R_OK` (check for read access), `W_OK` (check for write access),
|
|
2920
|
+
and `X_OK` (check for execute/search access). Multiple modes can be combined using bitwise OR.
|
|
2305
2921
|
|
|
2306
2922
|
#### Returns
|
|
2307
2923
|
|
|
2308
|
-
`
|
|
2924
|
+
`Promise`\<`boolean`\>
|
|
2925
|
+
|
|
2926
|
+
A Promise that resolves to a boolean indicating if the path is accessible with the specified mode.
|
|
2927
|
+
|
|
2928
|
+
#### Example
|
|
2929
|
+
|
|
2930
|
+
```typescript
|
|
2931
|
+
import { isAccessible, F_OK, R_OK } from "@visulima/fs";
|
|
2932
|
+
|
|
2933
|
+
(async () => {
|
|
2934
|
+
if (await isAccessible("myFile.txt")) {
|
|
2935
|
+
console.log("myFile.txt exists");
|
|
2936
|
+
}
|
|
2937
|
+
|
|
2938
|
+
if (await isAccessible("myFile.txt", R_OK)) {
|
|
2939
|
+
console.log("myFile.txt is readable");
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
if (await isAccessible("myDirectory", F_OK | R_OK | W_OK)) {
|
|
2943
|
+
console.log("myDirectory exists, is readable and writable");
|
|
2944
|
+
}
|
|
2945
|
+
})();
|
|
2946
|
+
```
|
|
2309
2947
|
|
|
2310
2948
|
***
|
|
2311
2949
|
|
|
2312
|
-
###
|
|
2950
|
+
### isAccessibleSync()
|
|
2313
2951
|
|
|
2314
2952
|
```ts
|
|
2315
|
-
function
|
|
2953
|
+
function isAccessibleSync(path, mode?): boolean;
|
|
2316
2954
|
```
|
|
2317
2955
|
|
|
2318
|
-
Defined in: [packages/fs/src/is-accessible.ts:9](https://github.com/visulima/visulima/blob/
|
|
2956
|
+
Defined in: [packages/fs/src/is-accessible-sync.ts:9](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/is-accessible-sync.ts#L9)
|
|
2319
2957
|
|
|
2320
|
-
|
|
2958
|
+
Synchronously tests a user's permissions for the file or directory specified by `path`.
|
|
2959
|
+
If the accessibility check is successful, `true` is returned. Otherwise, `false` is returned.
|
|
2321
2960
|
|
|
2322
2961
|
#### Parameters
|
|
2323
2962
|
|
|
@@ -2331,33 +2970,54 @@ Returns a Promise that resolves to a boolean indicating if the path is accessibl
|
|
|
2331
2970
|
|
|
2332
2971
|
#### Returns
|
|
2333
2972
|
|
|
2334
|
-
`
|
|
2973
|
+
`boolean`
|
|
2335
2974
|
|
|
2336
|
-
|
|
2975
|
+
`true` if the accessibility check is successful, `false` otherwise.
|
|
2337
2976
|
|
|
2338
|
-
|
|
2977
|
+
#### Param
|
|
2339
2978
|
|
|
2340
|
-
|
|
2341
|
-
function isAccessibleSync(path, mode?): boolean;
|
|
2342
|
-
```
|
|
2979
|
+
A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
|
2343
2980
|
|
|
2344
|
-
|
|
2981
|
+
#### Param
|
|
2345
2982
|
|
|
2346
|
-
|
|
2983
|
+
The accessibility checks to perform. Default: `F_OK` (tests for existence of the file).
|
|
2984
|
+
Other possible values are `R_OK` (tests for read permission), `W_OK` (tests for write permission),
|
|
2985
|
+
and `X_OK` (tests for execute permissions). Multiple modes can be combined using bitwise OR.
|
|
2347
2986
|
|
|
2348
|
-
####
|
|
2987
|
+
#### Example
|
|
2349
2988
|
|
|
2350
|
-
|
|
2989
|
+
```javascript
|
|
2990
|
+
import { isAccessibleSync, F_OK, R_OK, W_OK } from "@visulima/fs";
|
|
2991
|
+
import { writeFileSync, unlinkSync, chmodSync } from "node:fs";
|
|
2992
|
+
import { join } from "node:path";
|
|
2351
2993
|
|
|
2352
|
-
|
|
2994
|
+
const filePath = join("temp-access-test.txt");
|
|
2353
2995
|
|
|
2354
|
-
|
|
2996
|
+
// Test for existence (default mode)
|
|
2997
|
+
writeFileSync(filePath, "content");
|
|
2998
|
+
console.log(`File exists: ${isAccessibleSync(filePath)}`); // true
|
|
2999
|
+
unlinkSync(filePath);
|
|
3000
|
+
console.log(`File exists after delete: ${isAccessibleSync(filePath)}`); // false
|
|
2355
3001
|
|
|
2356
|
-
|
|
3002
|
+
// Test for read and write permissions
|
|
3003
|
+
writeFileSync(filePath, "content");
|
|
3004
|
+
chmodSync(filePath, 0o600); // Read/Write for owner
|
|
3005
|
+
console.log(`Readable: ${isAccessibleSync(filePath, R_OK)}`); // true
|
|
3006
|
+
console.log(`Writable: ${isAccessibleSync(filePath, W_OK)}`); // true
|
|
3007
|
+
console.log(`Readable & Writable: ${isAccessibleSync(filePath, R_OK | W_OK)}`); // true
|
|
2357
3008
|
|
|
2358
|
-
|
|
3009
|
+
chmodSync(filePath, 0o400); // Read-only for owner
|
|
3010
|
+
console.log(`Readable (after chmod): ${isAccessibleSync(filePath, R_OK)}`); // true
|
|
3011
|
+
console.log(`Writable (after chmod): ${isAccessibleSync(filePath, W_OK)}`); // false
|
|
2359
3012
|
|
|
2360
|
-
|
|
3013
|
+
unlinkSync(filePath); // Clean up
|
|
3014
|
+
|
|
3015
|
+
// Example with URL
|
|
3016
|
+
writeFileSync(filePath, "content for URL test");
|
|
3017
|
+
const fileUrl = new URL(`file://${join(process.cwd(), filePath)}`);
|
|
3018
|
+
console.log(`URL exists: ${isAccessibleSync(fileUrl)}`); // true
|
|
3019
|
+
unlinkSync(filePath);
|
|
3020
|
+
```
|
|
2361
3021
|
|
|
2362
3022
|
***
|
|
2363
3023
|
|
|
@@ -2370,7 +3030,7 @@ function move(
|
|
|
2370
3030
|
options): Promise<void>;
|
|
2371
3031
|
```
|
|
2372
3032
|
|
|
2373
|
-
Defined in: [packages/fs/src/move/index.ts:35](https://github.com/visulima/visulima/blob/
|
|
3033
|
+
Defined in: [packages/fs/src/move/index.ts:35](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/move/index.ts#L35)
|
|
2374
3034
|
|
|
2375
3035
|
Move a file asynchronously.
|
|
2376
3036
|
|
|
@@ -2403,9 +3063,9 @@ A `Promise` that resolves when the file has been moved.
|
|
|
2403
3063
|
#### Example
|
|
2404
3064
|
|
|
2405
3065
|
```
|
|
2406
|
-
import {
|
|
3066
|
+
import { move } from '@visulima/fs';
|
|
2407
3067
|
|
|
2408
|
-
await
|
|
3068
|
+
await move('source/test.png', 'destination/test.png');
|
|
2409
3069
|
console.log('The file has been moved');
|
|
2410
3070
|
```
|
|
2411
3071
|
|
|
@@ -2420,7 +3080,7 @@ function moveSync(
|
|
|
2420
3080
|
options?): void;
|
|
2421
3081
|
```
|
|
2422
3082
|
|
|
2423
|
-
Defined in: [packages/fs/src/move/index.ts:61](https://github.com/visulima/visulima/blob/
|
|
3083
|
+
Defined in: [packages/fs/src/move/index.ts:61](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/move/index.ts#L61)
|
|
2424
3084
|
|
|
2425
3085
|
Move a file synchronously.
|
|
2426
3086
|
|
|
@@ -2453,9 +3113,9 @@ Nothing is returned.
|
|
|
2453
3113
|
#### Example
|
|
2454
3114
|
|
|
2455
3115
|
```
|
|
2456
|
-
import {
|
|
3116
|
+
import { moveSync } from '@visulima/fs';
|
|
2457
3117
|
|
|
2458
|
-
|
|
3118
|
+
moveSync('source/test.png', 'destination/test.png');
|
|
2459
3119
|
console.log('The file has been moved');
|
|
2460
3120
|
```
|
|
2461
3121
|
|
|
@@ -2467,7 +3127,10 @@ console.log('The file has been moved');
|
|
|
2467
3127
|
function readFile<O>(path, options?): Promise<ContentType<O>>;
|
|
2468
3128
|
```
|
|
2469
3129
|
|
|
2470
|
-
Defined in: [packages/fs/src/read/read-file.ts:
|
|
3130
|
+
Defined in: [packages/fs/src/read/read-file.ts:57](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/read/read-file.ts#L57)
|
|
3131
|
+
|
|
3132
|
+
Asynchronously reads the entire contents of a file.
|
|
3133
|
+
It can also decompress the file content if a `compression` option is provided.
|
|
2471
3134
|
|
|
2472
3135
|
#### Type Parameters
|
|
2473
3136
|
|
|
@@ -2475,19 +3138,57 @@ Defined in: [packages/fs/src/read/read-file.ts:20](https://github.com/visulima/v
|
|
|
2475
3138
|
|
|
2476
3139
|
`O` *extends* [`ReadFileOptions`](#readfileoptions)\<`"brotli"` \| `"gzip"` \| `"none"`\> = `undefined`
|
|
2477
3140
|
|
|
3141
|
+
The type of the options object, extending [ReadFileOptions](#readfileoptions).
|
|
3142
|
+
|
|
2478
3143
|
#### Parameters
|
|
2479
3144
|
|
|
2480
3145
|
##### path
|
|
2481
3146
|
|
|
3147
|
+
The path to the file to read. Can be a file URL or a string path.
|
|
3148
|
+
|
|
2482
3149
|
`string` | `URL`
|
|
2483
3150
|
|
|
2484
3151
|
##### options?
|
|
2485
3152
|
|
|
2486
3153
|
`O`
|
|
2487
3154
|
|
|
3155
|
+
Optional configuration for reading the file. See [ReadFileOptions](#readfileoptions).
|
|
3156
|
+
Available `compression` methods: "brotli", "gzip", "none" (default).
|
|
3157
|
+
|
|
2488
3158
|
#### Returns
|
|
2489
3159
|
|
|
2490
|
-
`Promise
|
|
3160
|
+
`Promise`\<[`ContentType`](#contenttype)\<`O`\>\>
|
|
3161
|
+
|
|
3162
|
+
A promise that resolves with the file content. The type of the content (string or Buffer)
|
|
3163
|
+
depends on the `buffer` option (defaults to string if `buffer` is false or not set).
|
|
3164
|
+
|
|
3165
|
+
#### Example
|
|
3166
|
+
|
|
3167
|
+
```javascript
|
|
3168
|
+
import { readFile } from "@visulima/fs";
|
|
3169
|
+
import { join } from "node:path";
|
|
3170
|
+
|
|
3171
|
+
const readMyFile = async () => {
|
|
3172
|
+
try {
|
|
3173
|
+
// Read a regular text file
|
|
3174
|
+
const content = await readFile(join("path", "to", "my-file.txt"));
|
|
3175
|
+
console.log("File content:", content);
|
|
3176
|
+
|
|
3177
|
+
// Read a file as a Buffer
|
|
3178
|
+
const bufferContent = await readFile(join("path", "to", "another-file.bin"), { buffer: true });
|
|
3179
|
+
console.log("Buffer length:", bufferContent.length);
|
|
3180
|
+
|
|
3181
|
+
// Read and decompress a gzipped file
|
|
3182
|
+
// Assume my-archive.txt.gz exists
|
|
3183
|
+
// const decompressedContent = await readFile(join("path", "to", "my-archive.txt.gz"), { compression: "gzip", encoding: "utf8" });
|
|
3184
|
+
// console.log("Decompressed content:", decompressedContent);
|
|
3185
|
+
} catch (error) {
|
|
3186
|
+
console.error("Failed to read file:", error);
|
|
3187
|
+
}
|
|
3188
|
+
};
|
|
3189
|
+
|
|
3190
|
+
readMyFile();
|
|
3191
|
+
```
|
|
2491
3192
|
|
|
2492
3193
|
***
|
|
2493
3194
|
|
|
@@ -2497,7 +3198,10 @@ Defined in: [packages/fs/src/read/read-file.ts:20](https://github.com/visulima/v
|
|
|
2497
3198
|
function readFileSync<O>(path, options?): ContentType<O>;
|
|
2498
3199
|
```
|
|
2499
3200
|
|
|
2500
|
-
Defined in: [packages/fs/src/read/read-file-sync.ts:
|
|
3201
|
+
Defined in: [packages/fs/src/read/read-file-sync.ts:51](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/read/read-file-sync.ts#L51)
|
|
3202
|
+
|
|
3203
|
+
Synchronously reads the entire contents of a file.
|
|
3204
|
+
It can also decompress the file content if a `compression` option is provided.
|
|
2501
3205
|
|
|
2502
3206
|
#### Type Parameters
|
|
2503
3207
|
|
|
@@ -2505,31 +3209,115 @@ Defined in: [packages/fs/src/read/read-file-sync.ts:18](https://github.com/visul
|
|
|
2505
3209
|
|
|
2506
3210
|
`O` *extends* [`ReadFileOptions`](#readfileoptions)\<`"brotli"` \| `"gzip"` \| `"none"`\> = `undefined`
|
|
2507
3211
|
|
|
3212
|
+
The type of the options object, extending [ReadFileOptions](#readfileoptions).
|
|
3213
|
+
|
|
2508
3214
|
#### Parameters
|
|
2509
3215
|
|
|
2510
3216
|
##### path
|
|
2511
3217
|
|
|
3218
|
+
The path to the file to read. Can be a file URL or a string path.
|
|
3219
|
+
|
|
2512
3220
|
`string` | `URL`
|
|
2513
3221
|
|
|
2514
3222
|
##### options?
|
|
2515
3223
|
|
|
2516
3224
|
`O`
|
|
2517
3225
|
|
|
3226
|
+
Optional configuration for reading the file. See [ReadFileOptions](#readfileoptions).
|
|
3227
|
+
Available `compression` methods: "brotli", "gzip", "none" (default).
|
|
3228
|
+
|
|
2518
3229
|
#### Returns
|
|
2519
3230
|
|
|
2520
|
-
`ContentType
|
|
3231
|
+
[`ContentType`](#contenttype)\<`O`\>
|
|
3232
|
+
|
|
3233
|
+
The file content. The type of the content (string or Buffer)
|
|
3234
|
+
depends on the `buffer` option (defaults to string if `buffer` is false or not set).
|
|
3235
|
+
|
|
3236
|
+
#### Example
|
|
3237
|
+
|
|
3238
|
+
```javascript
|
|
3239
|
+
import { readFileSync } from "@visulima/fs";
|
|
3240
|
+
import { join } from "node:path";
|
|
3241
|
+
|
|
3242
|
+
try {
|
|
3243
|
+
// Read a regular text file
|
|
3244
|
+
const content = readFileSync(join("path", "to", "my-file.txt"));
|
|
3245
|
+
console.log("File content:", content);
|
|
3246
|
+
|
|
3247
|
+
// Read a file as a Buffer
|
|
3248
|
+
const bufferContent = readFileSync(join("path", "to", "another-file.bin"), { buffer: true });
|
|
3249
|
+
console.log("Buffer length:", bufferContent.length);
|
|
3250
|
+
|
|
3251
|
+
// Read and decompress a gzipped file
|
|
3252
|
+
// Assume my-archive.txt.gz exists
|
|
3253
|
+
// const decompressedContent = readFileSync(join("path", "to", "my-archive.txt.gz"), { compression: "gzip", encoding: "utf8" });
|
|
3254
|
+
// console.log("Decompressed content:", decompressedContent);
|
|
3255
|
+
} catch (error) {
|
|
3256
|
+
console.error("Failed to read file:", error);
|
|
3257
|
+
}
|
|
3258
|
+
```
|
|
2521
3259
|
|
|
2522
3260
|
***
|
|
2523
3261
|
|
|
2524
3262
|
### readJson()
|
|
2525
3263
|
|
|
3264
|
+
Asynchronously reads a JSON file and then parses it into an object.
|
|
3265
|
+
|
|
3266
|
+
#### Template
|
|
3267
|
+
|
|
3268
|
+
The expected type of the parsed JSON object.
|
|
3269
|
+
|
|
3270
|
+
#### Param
|
|
3271
|
+
|
|
3272
|
+
The path to the JSON file to read. Can be a file URL or a string path.
|
|
3273
|
+
|
|
3274
|
+
#### Param
|
|
3275
|
+
|
|
3276
|
+
A function to transform the results. This function is called for each member of the object.
|
|
3277
|
+
Alternatively, this can be the `options` object if no reviver function is provided.
|
|
3278
|
+
|
|
3279
|
+
#### Param
|
|
3280
|
+
|
|
3281
|
+
Optional configuration for reading and parsing the JSON file. See [ReadJsonOptions](#readjsonoptions).
|
|
3282
|
+
If `reviver` is an object, this argument is ignored.
|
|
3283
|
+
|
|
3284
|
+
#### Example
|
|
3285
|
+
|
|
3286
|
+
```javascript
|
|
3287
|
+
import { readJson } from "@visulima/fs";
|
|
3288
|
+
import { join } from "node:path";
|
|
3289
|
+
|
|
3290
|
+
const readMyJson = async () => {
|
|
3291
|
+
try {
|
|
3292
|
+
const data = await readJson(join("path", "to", "my-config.json"));
|
|
3293
|
+
console.log("Config data:", data);
|
|
3294
|
+
|
|
3295
|
+
// With a reviver function
|
|
3296
|
+
const dataWithReviver = await readJson(join("path", "to", "another.json"), (key, value) => {
|
|
3297
|
+
if (key === "date") return new Date(value);
|
|
3298
|
+
return value;
|
|
3299
|
+
});
|
|
3300
|
+
console.log("Date field is now a Date object:", dataWithReviver.date);
|
|
3301
|
+
|
|
3302
|
+
// With options (e.g., for custom error reporting)
|
|
3303
|
+
const dataWithOptions = await readJson(join("path", "to", "options.json"), { color: { message: (str) => `\x1b[31m${str}\x1b[0m` } });
|
|
3304
|
+
console.log(dataWithOptions);
|
|
3305
|
+
|
|
3306
|
+
} catch (error) {
|
|
3307
|
+
console.error("Failed to read or parse JSON file:", error);
|
|
3308
|
+
}
|
|
3309
|
+
};
|
|
3310
|
+
|
|
3311
|
+
readMyJson();
|
|
3312
|
+
```
|
|
3313
|
+
|
|
2526
3314
|
#### Call Signature
|
|
2527
3315
|
|
|
2528
3316
|
```ts
|
|
2529
3317
|
function readJson<T>(path, options?): Promise<T>;
|
|
2530
3318
|
```
|
|
2531
3319
|
|
|
2532
|
-
Defined in: [packages/fs/src/read/read-json.ts:8](https://github.com/visulima/visulima/blob/
|
|
3320
|
+
Defined in: [packages/fs/src/read/read-json.ts:8](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/read/read-json.ts#L8)
|
|
2533
3321
|
|
|
2534
3322
|
##### Type Parameters
|
|
2535
3323
|
|
|
@@ -2560,7 +3348,7 @@ function readJson<T>(
|
|
|
2560
3348
|
options?): Promise<T>;
|
|
2561
3349
|
```
|
|
2562
3350
|
|
|
2563
|
-
Defined in: [packages/fs/src/read/read-json.ts:10](https://github.com/visulima/visulima/blob/
|
|
3351
|
+
Defined in: [packages/fs/src/read/read-json.ts:10](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/read/read-json.ts#L10)
|
|
2564
3352
|
|
|
2565
3353
|
##### Type Parameters
|
|
2566
3354
|
|
|
@@ -2590,13 +3378,59 @@ Defined in: [packages/fs/src/read/read-json.ts:10](https://github.com/visulima/v
|
|
|
2590
3378
|
|
|
2591
3379
|
### readJsonSync()
|
|
2592
3380
|
|
|
3381
|
+
Synchronously reads a JSON file and then parses it into an object.
|
|
3382
|
+
|
|
3383
|
+
#### Template
|
|
3384
|
+
|
|
3385
|
+
The expected type of the parsed JSON object.
|
|
3386
|
+
|
|
3387
|
+
#### Param
|
|
3388
|
+
|
|
3389
|
+
The path to the JSON file to read. Can be a file URL or a string path.
|
|
3390
|
+
|
|
3391
|
+
#### Param
|
|
3392
|
+
|
|
3393
|
+
A function to transform the results. This function is called for each member of the object.
|
|
3394
|
+
Alternatively, this can be the `options` object if no reviver function is provided.
|
|
3395
|
+
|
|
3396
|
+
#### Param
|
|
3397
|
+
|
|
3398
|
+
Optional configuration for reading and parsing the JSON file. See [ReadJsonOptions](#readjsonoptions).
|
|
3399
|
+
If `reviver` is an object, this argument is ignored.
|
|
3400
|
+
|
|
3401
|
+
#### Example
|
|
3402
|
+
|
|
3403
|
+
```javascript
|
|
3404
|
+
import { readJsonSync } from "@visulima/fs";
|
|
3405
|
+
import { join } from "node:path";
|
|
3406
|
+
|
|
3407
|
+
try {
|
|
3408
|
+
const data = readJsonSync(join("path", "to", "my-config.json"));
|
|
3409
|
+
console.log("Config data:", data);
|
|
3410
|
+
|
|
3411
|
+
// With a reviver function
|
|
3412
|
+
const dataWithReviver = readJsonSync(join("path", "to", "another.json"), (key, value) => {
|
|
3413
|
+
if (key === "date") return new Date(value);
|
|
3414
|
+
return value;
|
|
3415
|
+
});
|
|
3416
|
+
console.log("Date field is now a Date object:", dataWithReviver.date);
|
|
3417
|
+
|
|
3418
|
+
// With options (e.g., for custom error reporting)
|
|
3419
|
+
const dataWithOptions = readJsonSync(join("path", "to", "options.json"), { color: { message: (str) => `\x1b[31m${str}\x1b[0m` } });
|
|
3420
|
+
console.log(dataWithOptions);
|
|
3421
|
+
|
|
3422
|
+
} catch (error) {
|
|
3423
|
+
console.error("Failed to read or parse JSON file:", error);
|
|
3424
|
+
}
|
|
3425
|
+
```
|
|
3426
|
+
|
|
2593
3427
|
#### Call Signature
|
|
2594
3428
|
|
|
2595
3429
|
```ts
|
|
2596
3430
|
function readJsonSync<T>(path, options?): T;
|
|
2597
3431
|
```
|
|
2598
3432
|
|
|
2599
|
-
Defined in: [packages/fs/src/read/read-json-sync.ts:8](https://github.com/visulima/visulima/blob/
|
|
3433
|
+
Defined in: [packages/fs/src/read/read-json-sync.ts:8](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/read/read-json-sync.ts#L8)
|
|
2600
3434
|
|
|
2601
3435
|
##### Type Parameters
|
|
2602
3436
|
|
|
@@ -2627,7 +3461,7 @@ function readJsonSync<T>(
|
|
|
2627
3461
|
options?): T;
|
|
2628
3462
|
```
|
|
2629
3463
|
|
|
2630
|
-
Defined in: [packages/fs/src/read/read-json-sync.ts:10](https://github.com/visulima/visulima/blob/
|
|
3464
|
+
Defined in: [packages/fs/src/read/read-json-sync.ts:10](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/read/read-json-sync.ts#L10)
|
|
2631
3465
|
|
|
2632
3466
|
##### Type Parameters
|
|
2633
3467
|
|
|
@@ -2661,48 +3495,54 @@ Defined in: [packages/fs/src/read/read-json-sync.ts:10](https://github.com/visul
|
|
|
2661
3495
|
function remove(path, options): Promise<void>;
|
|
2662
3496
|
```
|
|
2663
3497
|
|
|
2664
|
-
Defined in: [packages/fs/src/remove/remove.ts:
|
|
3498
|
+
Defined in: [packages/fs/src/remove/remove.ts:36](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/remove/remove.ts#L36)
|
|
3499
|
+
|
|
3500
|
+
Asynchronously removes a file or directory (recursively).
|
|
3501
|
+
If the path does not exist, it does nothing.
|
|
2665
3502
|
|
|
2666
3503
|
#### Parameters
|
|
2667
3504
|
|
|
2668
3505
|
##### path
|
|
2669
3506
|
|
|
3507
|
+
The path to the file or directory to remove.
|
|
3508
|
+
|
|
2670
3509
|
`string` | `URL`
|
|
2671
3510
|
|
|
2672
3511
|
##### options
|
|
2673
3512
|
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
`number`
|
|
3513
|
+
`RetryOptions` = `{}`
|
|
2677
3514
|
|
|
2678
|
-
|
|
2679
|
-
`EPERM` error is encountered, Node.js will retry the operation with a linear
|
|
2680
|
-
backoff wait of `retryDelay` ms longer on each try. This option represents the
|
|
2681
|
-
number of retries. This option is ignored if the `recursive` option is not
|
|
2682
|
-
`true`.
|
|
3515
|
+
Optional configuration for the operation. See RetryOptions.
|
|
2683
3516
|
|
|
2684
|
-
|
|
3517
|
+
#### Returns
|
|
2685
3518
|
|
|
2686
|
-
|
|
2687
|
-
0
|
|
2688
|
-
```
|
|
3519
|
+
`Promise`\<`void`\>
|
|
2689
3520
|
|
|
2690
|
-
|
|
3521
|
+
A promise that resolves when the path has been removed.
|
|
2691
3522
|
|
|
2692
|
-
|
|
3523
|
+
#### Example
|
|
2693
3524
|
|
|
2694
|
-
|
|
2695
|
-
|
|
3525
|
+
```javascript
|
|
3526
|
+
import { remove } from "@visulima/fs";
|
|
3527
|
+
import { join } from "node:path";
|
|
2696
3528
|
|
|
2697
|
-
|
|
3529
|
+
const deleteFileOrDir = async () => {
|
|
3530
|
+
try {
|
|
3531
|
+
await remove(join("/tmp", "my-file.txt"));
|
|
3532
|
+
console.log("File /tmp/my-file.txt removed.");
|
|
2698
3533
|
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
```
|
|
3534
|
+
await remove(join("/tmp", "my-empty-dir"));
|
|
3535
|
+
console.log("Directory /tmp/my-empty-dir removed.");
|
|
2702
3536
|
|
|
2703
|
-
|
|
3537
|
+
await remove(join("/tmp", "my-dir-with-contents"));
|
|
3538
|
+
console.log("Directory /tmp/my-dir-with-contents and its contents removed.");
|
|
3539
|
+
} catch (error) {
|
|
3540
|
+
console.error("Failed to remove path:", error);
|
|
3541
|
+
}
|
|
3542
|
+
};
|
|
2704
3543
|
|
|
2705
|
-
|
|
3544
|
+
deleteFileOrDir();
|
|
3545
|
+
```
|
|
2706
3546
|
|
|
2707
3547
|
***
|
|
2708
3548
|
|
|
@@ -2712,49 +3552,51 @@ This option is ignored if the `recursive` option is not `true`.
|
|
|
2712
3552
|
function removeSync(path, options): void;
|
|
2713
3553
|
```
|
|
2714
3554
|
|
|
2715
|
-
Defined in: [packages/fs/src/remove/remove-sync.ts:
|
|
3555
|
+
Defined in: [packages/fs/src/remove/remove-sync.ts:32](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/remove/remove-sync.ts#L32)
|
|
3556
|
+
|
|
3557
|
+
Synchronously removes a file or directory (recursively).
|
|
3558
|
+
If the path does not exist, it does nothing.
|
|
2716
3559
|
|
|
2717
3560
|
#### Parameters
|
|
2718
3561
|
|
|
2719
3562
|
##### path
|
|
2720
3563
|
|
|
3564
|
+
The path to the file or directory to remove.
|
|
3565
|
+
|
|
2721
3566
|
`string` | `URL`
|
|
2722
3567
|
|
|
2723
3568
|
##### options
|
|
2724
3569
|
|
|
2725
|
-
|
|
3570
|
+
`RetryOptions` = `{}`
|
|
2726
3571
|
|
|
2727
|
-
|
|
3572
|
+
Optional configuration for the operation. See RetryOptions.
|
|
2728
3573
|
|
|
2729
|
-
|
|
2730
|
-
`EPERM` error is encountered, Node.js will retry the operation with a linear
|
|
2731
|
-
backoff wait of `retryDelay` ms longer on each try. This option represents the
|
|
2732
|
-
number of retries. This option is ignored if the `recursive` option is not
|
|
2733
|
-
`true`.
|
|
3574
|
+
#### Returns
|
|
2734
3575
|
|
|
2735
|
-
|
|
3576
|
+
`void`
|
|
2736
3577
|
|
|
2737
|
-
|
|
2738
|
-
0
|
|
2739
|
-
```
|
|
3578
|
+
void
|
|
2740
3579
|
|
|
2741
|
-
|
|
3580
|
+
#### Example
|
|
2742
3581
|
|
|
2743
|
-
|
|
3582
|
+
```javascript
|
|
3583
|
+
import { removeSync } from "@visulima/fs";
|
|
3584
|
+
import { join } from "node:path";
|
|
2744
3585
|
|
|
2745
|
-
|
|
2746
|
-
|
|
3586
|
+
try {
|
|
3587
|
+
removeSync(join("/tmp", "my-file.txt"));
|
|
3588
|
+
console.log("File /tmp/my-file.txt removed.");
|
|
2747
3589
|
|
|
2748
|
-
|
|
3590
|
+
removeSync(join("/tmp", "my-empty-dir"));
|
|
3591
|
+
console.log("Directory /tmp/my-empty-dir removed.");
|
|
2749
3592
|
|
|
2750
|
-
|
|
2751
|
-
|
|
3593
|
+
removeSync(join("/tmp", "my-dir-with-contents"));
|
|
3594
|
+
console.log("Directory /tmp/my-dir-with-contents and its contents removed.");
|
|
3595
|
+
} catch (error) {
|
|
3596
|
+
console.error("Failed to remove path:", error);
|
|
3597
|
+
}
|
|
2752
3598
|
```
|
|
2753
3599
|
|
|
2754
|
-
#### Returns
|
|
2755
|
-
|
|
2756
|
-
`void`
|
|
2757
|
-
|
|
2758
3600
|
***
|
|
2759
3601
|
|
|
2760
3602
|
### rename()
|
|
@@ -2766,7 +3608,7 @@ function rename(
|
|
|
2766
3608
|
options?): Promise<void>;
|
|
2767
3609
|
```
|
|
2768
3610
|
|
|
2769
|
-
Defined in: [packages/fs/src/move/index.ts:85](https://github.com/visulima/visulima/blob/
|
|
3611
|
+
Defined in: [packages/fs/src/move/index.ts:85](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/move/index.ts#L85)
|
|
2770
3612
|
|
|
2771
3613
|
Rename a file asynchronously.
|
|
2772
3614
|
|
|
@@ -2799,9 +3641,9 @@ A `Promise` that resolves when the file has been renamed.
|
|
|
2799
3641
|
#### Example
|
|
2800
3642
|
|
|
2801
3643
|
```
|
|
2802
|
-
import {
|
|
3644
|
+
import { rename } from '@visulima/fs';
|
|
2803
3645
|
|
|
2804
|
-
await
|
|
3646
|
+
await rename('test.png', 'tests.png', {cwd: 'source'});
|
|
2805
3647
|
console.log('The file has been renamed');
|
|
2806
3648
|
```
|
|
2807
3649
|
|
|
@@ -2816,7 +3658,7 @@ function renameSync(
|
|
|
2816
3658
|
options?): void;
|
|
2817
3659
|
```
|
|
2818
3660
|
|
|
2819
|
-
Defined in: [packages/fs/src/move/index.ts:109](https://github.com/visulima/visulima/blob/
|
|
3661
|
+
Defined in: [packages/fs/src/move/index.ts:109](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/move/index.ts#L109)
|
|
2820
3662
|
|
|
2821
3663
|
Rename a file synchronously.
|
|
2822
3664
|
|
|
@@ -2849,9 +3691,9 @@ A `Promise` that resolves when the file has been renamed.
|
|
|
2849
3691
|
#### Example
|
|
2850
3692
|
|
|
2851
3693
|
```
|
|
2852
|
-
import {
|
|
3694
|
+
import { renameSync } from '@visulima/fs';
|
|
2853
3695
|
|
|
2854
|
-
|
|
3696
|
+
renameSync('test.png', 'tests.png', {cwd: 'source'});
|
|
2855
3697
|
console.log('The file has been renamed');
|
|
2856
3698
|
```
|
|
2857
3699
|
|
|
@@ -2860,63 +3702,108 @@ console.log('The file has been renamed');
|
|
|
2860
3702
|
### walk()
|
|
2861
3703
|
|
|
2862
3704
|
```ts
|
|
2863
|
-
function walk(directory,
|
|
3705
|
+
function walk(directory, options): AsyncIterableIterator<WalkEntry>;
|
|
2864
3706
|
```
|
|
2865
3707
|
|
|
2866
|
-
Defined in: [packages/fs/src/find/walk.ts:
|
|
3708
|
+
Defined in: [packages/fs/src/find/walk.ts:64](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/find/walk.ts#L64)
|
|
2867
3709
|
|
|
2868
|
-
|
|
2869
|
-
tree filtered according to the given options.
|
|
2870
|
-
Options:
|
|
2871
|
-
- maxDepth?: number = Infinity;
|
|
2872
|
-
- includeFiles?: boolean = true;
|
|
2873
|
-
- includeDirs?: boolean = true;
|
|
2874
|
-
- includeSymlinks?: boolean = true;
|
|
2875
|
-
- followSymlinks?: boolean = false;
|
|
2876
|
-
- extensions?: string[];
|
|
2877
|
-
- match?: string | ReadonlyArray<string>;
|
|
2878
|
-
- skip?: string | ReadonlyArray<string>;
|
|
3710
|
+
Asynchronously walks the file tree rooted at `directory`, yielding each file or directory that matches the criteria specified in `options`.
|
|
2879
3711
|
|
|
2880
3712
|
#### Parameters
|
|
2881
3713
|
|
|
2882
3714
|
##### directory
|
|
2883
3715
|
|
|
3716
|
+
The root directory to start walking from.
|
|
3717
|
+
|
|
2884
3718
|
`string` | `URL`
|
|
2885
3719
|
|
|
2886
|
-
#####
|
|
3720
|
+
##### options
|
|
2887
3721
|
|
|
2888
3722
|
[`WalkOptions`](#walkoptions) = `{}`
|
|
2889
3723
|
|
|
3724
|
+
Optional configuration to control the walking process. See [WalkOptions](#walkoptions).
|
|
3725
|
+
|
|
2890
3726
|
#### Returns
|
|
2891
3727
|
|
|
2892
3728
|
`AsyncIterableIterator`\<[`WalkEntry`](#walkentry)\>
|
|
2893
3729
|
|
|
3730
|
+
An async iterable iterator yielding [WalkEntry](#walkentry) objects for each matching file or directory.
|
|
3731
|
+
|
|
3732
|
+
#### Example
|
|
3733
|
+
|
|
3734
|
+
```javascript
|
|
3735
|
+
import { walk } from "@visulima/fs";
|
|
3736
|
+
import { join } from "node:path";
|
|
3737
|
+
|
|
3738
|
+
const printEntries = async () => {
|
|
3739
|
+
// Walk through /tmp/my-project, looking for .ts files, max depth 2
|
|
3740
|
+
for await (const entry of walk(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
|
|
3741
|
+
console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? 'file' : 'directory'})`);
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3744
|
+
// Walk, including only directories, and skip any node_modules folders
|
|
3745
|
+
for await (const entry of walk(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
|
|
3746
|
+
if (entry.isDirectory()) {
|
|
3747
|
+
console.log(`Directory: ${entry.path}`);
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
};
|
|
3751
|
+
|
|
3752
|
+
printEntries();
|
|
3753
|
+
```
|
|
3754
|
+
|
|
2894
3755
|
***
|
|
2895
3756
|
|
|
2896
3757
|
### walkSync()
|
|
2897
3758
|
|
|
2898
3759
|
```ts
|
|
2899
|
-
function walkSync(directory,
|
|
3760
|
+
function walkSync(directory, options): IterableIterator<WalkEntry>;
|
|
2900
3761
|
```
|
|
2901
3762
|
|
|
2902
|
-
Defined in: [packages/fs/src/find/walk-sync.ts:
|
|
3763
|
+
Defined in: [packages/fs/src/find/walk-sync.ts:64](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/find/walk-sync.ts#L64)
|
|
2903
3764
|
|
|
2904
|
-
|
|
3765
|
+
Synchronously walks the file tree rooted at `directory`, yielding each file or directory that matches the criteria specified in `options`.
|
|
3766
|
+
This is the synchronous version of the [walk](#walk) function.
|
|
2905
3767
|
|
|
2906
3768
|
#### Parameters
|
|
2907
3769
|
|
|
2908
3770
|
##### directory
|
|
2909
3771
|
|
|
3772
|
+
The root directory to start walking from.
|
|
3773
|
+
|
|
2910
3774
|
`string` | `URL`
|
|
2911
3775
|
|
|
2912
|
-
#####
|
|
3776
|
+
##### options
|
|
2913
3777
|
|
|
2914
3778
|
[`WalkOptions`](#walkoptions) = `{}`
|
|
2915
3779
|
|
|
3780
|
+
Optional configuration to control the walking process. See [WalkOptions](#walkoptions).
|
|
3781
|
+
|
|
2916
3782
|
#### Returns
|
|
2917
3783
|
|
|
2918
3784
|
`IterableIterator`\<[`WalkEntry`](#walkentry)\>
|
|
2919
3785
|
|
|
3786
|
+
An iterable iterator yielding [WalkEntry](#walkentry) objects for each matching file or directory.
|
|
3787
|
+
|
|
3788
|
+
#### Example
|
|
3789
|
+
|
|
3790
|
+
```javascript
|
|
3791
|
+
import { walkSync } from "@visulima/fs";
|
|
3792
|
+
import { join } from "node:path";
|
|
3793
|
+
|
|
3794
|
+
// Walk through /tmp/my-project, looking for .ts files, max depth 2
|
|
3795
|
+
for (const entry of walkSync(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
|
|
3796
|
+
console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? 'file' : 'directory'})`);
|
|
3797
|
+
}
|
|
3798
|
+
|
|
3799
|
+
// Walk, including only directories, and skip any node_modules folders
|
|
3800
|
+
for (const entry of walkSync(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
|
|
3801
|
+
if (entry.isDirectory()) {
|
|
3802
|
+
console.log(`Directory: ${entry.path}`);
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
```
|
|
3806
|
+
|
|
2920
3807
|
***
|
|
2921
3808
|
|
|
2922
3809
|
### writeFile()
|
|
@@ -2928,26 +3815,58 @@ function writeFile(
|
|
|
2928
3815
|
options?): Promise<void>;
|
|
2929
3816
|
```
|
|
2930
3817
|
|
|
2931
|
-
Defined in: [packages/fs/src/write/write-file.ts:
|
|
3818
|
+
Defined in: [packages/fs/src/write/write-file.ts:43](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/write/write-file.ts#L43)
|
|
3819
|
+
|
|
3820
|
+
Asynchronously writes data to a file, replacing the file if it already exists.
|
|
3821
|
+
This function includes safeguards like writing to a temporary file first and then renaming, and handling permissions.
|
|
2932
3822
|
|
|
2933
3823
|
#### Parameters
|
|
2934
3824
|
|
|
2935
3825
|
##### path
|
|
2936
3826
|
|
|
3827
|
+
The path to the file to write. Can be a file URL or a string path.
|
|
3828
|
+
|
|
2937
3829
|
`string` | `URL`
|
|
2938
3830
|
|
|
2939
3831
|
##### content
|
|
2940
3832
|
|
|
3833
|
+
The data to write. Can be a string, Buffer, ArrayBuffer, or ArrayBufferView.
|
|
3834
|
+
|
|
2941
3835
|
`string` | `ArrayBuffer` | `ArrayBufferView`\<`ArrayBufferLike`\>
|
|
2942
3836
|
|
|
2943
3837
|
##### options?
|
|
2944
3838
|
|
|
2945
3839
|
[`WriteFileOptions`](#writefileoptions)
|
|
2946
3840
|
|
|
3841
|
+
Optional configuration for writing the file. See [WriteFileOptions](#writefileoptions).
|
|
3842
|
+
|
|
2947
3843
|
#### Returns
|
|
2948
3844
|
|
|
2949
3845
|
`Promise`\<`void`\>
|
|
2950
3846
|
|
|
3847
|
+
A promise that resolves when the file has been written.
|
|
3848
|
+
|
|
3849
|
+
#### Example
|
|
3850
|
+
|
|
3851
|
+
```javascript
|
|
3852
|
+
import { writeFile } from "@visulima/fs";
|
|
3853
|
+
import { join } from "node:path";
|
|
3854
|
+
|
|
3855
|
+
const writeMyFile = async () => {
|
|
3856
|
+
try {
|
|
3857
|
+
await writeFile(join("/tmp", "my-new-file.txt"), "Hello World!");
|
|
3858
|
+
console.log("File written successfully.");
|
|
3859
|
+
|
|
3860
|
+
await writeFile(join("/tmp", "another-file.txt"), "Some other content", { encoding: 'utf16le', mode: 0o600 });
|
|
3861
|
+
console.log("Another file written with specific options.");
|
|
3862
|
+
} catch (error) {
|
|
3863
|
+
console.error("Failed to write file:", error);
|
|
3864
|
+
}
|
|
3865
|
+
};
|
|
3866
|
+
|
|
3867
|
+
writeMyFile();
|
|
3868
|
+
```
|
|
3869
|
+
|
|
2951
3870
|
***
|
|
2952
3871
|
|
|
2953
3872
|
### writeFileSync()
|
|
@@ -2959,26 +3878,58 @@ function writeFileSync(
|
|
|
2959
3878
|
options?): void;
|
|
2960
3879
|
```
|
|
2961
3880
|
|
|
2962
|
-
Defined in: [packages/fs/src/write/write-file-sync.ts:
|
|
3881
|
+
Defined in: [packages/fs/src/write/write-file-sync.ts:43](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/write/write-file-sync.ts#L43)
|
|
3882
|
+
|
|
3883
|
+
Synchronously writes data to a file, replacing the file if it already exists.
|
|
3884
|
+
This function includes safeguards like writing to a temporary file first and then renaming, and handling permissions.
|
|
2963
3885
|
|
|
2964
3886
|
#### Parameters
|
|
2965
3887
|
|
|
2966
3888
|
##### path
|
|
2967
3889
|
|
|
3890
|
+
The path to the file to write. Can be a file URL or a string path.
|
|
3891
|
+
|
|
2968
3892
|
`string` | `URL`
|
|
2969
3893
|
|
|
2970
3894
|
##### content
|
|
2971
3895
|
|
|
3896
|
+
The data to write. Can be a string, Buffer, ArrayBuffer, or ArrayBufferView.
|
|
3897
|
+
|
|
2972
3898
|
`string` | `ArrayBuffer` | `ArrayBufferView`\<`ArrayBufferLike`\>
|
|
2973
3899
|
|
|
2974
3900
|
##### options?
|
|
2975
3901
|
|
|
2976
3902
|
[`WriteFileOptions`](#writefileoptions)
|
|
2977
3903
|
|
|
3904
|
+
Optional configuration for writing the file. See [WriteFileOptions](#writefileoptions).
|
|
3905
|
+
|
|
2978
3906
|
#### Returns
|
|
2979
3907
|
|
|
2980
3908
|
`void`
|
|
2981
3909
|
|
|
3910
|
+
void
|
|
3911
|
+
|
|
3912
|
+
#### Example
|
|
3913
|
+
|
|
3914
|
+
```javascript
|
|
3915
|
+
import { writeFileSync } from "@visulima/fs";
|
|
3916
|
+
import { join } from "node:path";
|
|
3917
|
+
|
|
3918
|
+
const writeMyFileSync = () => {
|
|
3919
|
+
try {
|
|
3920
|
+
writeFileSync(join("/tmp", "my-new-file-sync.txt"), "Hello World Synchronously!");
|
|
3921
|
+
console.log("File written successfully (sync).");
|
|
3922
|
+
|
|
3923
|
+
writeFileSync(join("/tmp", "another-file-sync.txt"), "Some other sync content", { encoding: 'utf16le', mode: 0o600 });
|
|
3924
|
+
console.log("Another file written with specific options (sync).");
|
|
3925
|
+
} catch (error) {
|
|
3926
|
+
console.error("Failed to write file (sync):", error);
|
|
3927
|
+
}
|
|
3928
|
+
};
|
|
3929
|
+
|
|
3930
|
+
writeMyFileSync();
|
|
3931
|
+
```
|
|
3932
|
+
|
|
2982
3933
|
***
|
|
2983
3934
|
|
|
2984
3935
|
### writeJson()
|
|
@@ -2990,26 +3941,58 @@ function writeJson(
|
|
|
2990
3941
|
options): Promise<void>;
|
|
2991
3942
|
```
|
|
2992
3943
|
|
|
2993
|
-
Defined in: [packages/fs/src/write/write-json.ts:
|
|
3944
|
+
Defined in: [packages/fs/src/write/write-json.ts:39](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/write/write-json.ts#L39)
|
|
3945
|
+
|
|
3946
|
+
Asynchronously writes an object to a JSON file.
|
|
3947
|
+
Handles indentation detection, custom stringifiers, and gracefully manages existing files.
|
|
2994
3948
|
|
|
2995
3949
|
#### Parameters
|
|
2996
3950
|
|
|
2997
3951
|
##### path
|
|
2998
3952
|
|
|
3953
|
+
The path to the JSON file to write. Can be a file URL or a string path.
|
|
3954
|
+
|
|
2999
3955
|
`string` | `URL`
|
|
3000
3956
|
|
|
3001
3957
|
##### data
|
|
3002
3958
|
|
|
3003
3959
|
`unknown`
|
|
3004
3960
|
|
|
3961
|
+
The data to serialize and write. Can be any JavaScript value that can be stringified by `JSON.stringify` or a custom stringifier.
|
|
3962
|
+
|
|
3005
3963
|
##### options
|
|
3006
3964
|
|
|
3007
3965
|
[`WriteJsonOptions`](#writejsonoptions) = `{}`
|
|
3008
3966
|
|
|
3967
|
+
Optional configuration for writing the JSON file. See [WriteJsonOptions](#writejsonoptions).
|
|
3968
|
+
|
|
3009
3969
|
#### Returns
|
|
3010
3970
|
|
|
3011
3971
|
`Promise`\<`void`\>
|
|
3012
3972
|
|
|
3973
|
+
A promise that resolves when the JSON file has been written.
|
|
3974
|
+
|
|
3975
|
+
#### Example
|
|
3976
|
+
|
|
3977
|
+
```javascript
|
|
3978
|
+
import { writeJson } from "@visulima/fs";
|
|
3979
|
+
import { join } from "node:path";
|
|
3980
|
+
|
|
3981
|
+
const writeMyJson = async () => {
|
|
3982
|
+
try {
|
|
3983
|
+
await writeJson(join("/tmp", "my-config.json"), { setting: "enabled", value: 123 });
|
|
3984
|
+
console.log("JSON file written successfully.");
|
|
3985
|
+
|
|
3986
|
+
await writeJson(join("/tmp", "another-config.json"), { user: "test", id: "abc" }, { indent: 2, replacer: ["user"] });
|
|
3987
|
+
console.log("Another JSON file written with specific options (indent 2, only 'user' key).");
|
|
3988
|
+
} catch (error) {
|
|
3989
|
+
console.error("Failed to write JSON file:", error);
|
|
3990
|
+
}
|
|
3991
|
+
};
|
|
3992
|
+
|
|
3993
|
+
writeMyJson();
|
|
3994
|
+
```
|
|
3995
|
+
|
|
3013
3996
|
***
|
|
3014
3997
|
|
|
3015
3998
|
### writeJsonSync()
|
|
@@ -3021,51 +4004,59 @@ function writeJsonSync(
|
|
|
3021
4004
|
options): void;
|
|
3022
4005
|
```
|
|
3023
4006
|
|
|
3024
|
-
Defined in: [packages/fs/src/write/write-json-sync.ts:
|
|
4007
|
+
Defined in: [packages/fs/src/write/write-json-sync.ts:39](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/write/write-json-sync.ts#L39)
|
|
4008
|
+
|
|
4009
|
+
Synchronously writes an object to a JSON file.
|
|
4010
|
+
Handles indentation detection, custom stringifiers, and gracefully manages existing files.
|
|
3025
4011
|
|
|
3026
4012
|
#### Parameters
|
|
3027
4013
|
|
|
3028
4014
|
##### path
|
|
3029
4015
|
|
|
4016
|
+
The path to the JSON file to write. Can be a file URL or a string path.
|
|
4017
|
+
|
|
3030
4018
|
`string` | `URL`
|
|
3031
4019
|
|
|
3032
4020
|
##### data
|
|
3033
4021
|
|
|
3034
4022
|
`unknown`
|
|
3035
4023
|
|
|
4024
|
+
The data to serialize and write. Can be any JavaScript value that can be stringified by `JSON.stringify` or a custom stringifier.
|
|
4025
|
+
|
|
3036
4026
|
##### options
|
|
3037
4027
|
|
|
3038
4028
|
[`WriteJsonOptions`](#writejsonoptions) = `{}`
|
|
3039
4029
|
|
|
4030
|
+
Optional configuration for writing the JSON file. See [WriteJsonOptions](#writejsonoptions).
|
|
4031
|
+
|
|
3040
4032
|
#### Returns
|
|
3041
4033
|
|
|
3042
4034
|
`void`
|
|
3043
4035
|
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
### CRLF
|
|
4036
|
+
void
|
|
3047
4037
|
|
|
3048
|
-
|
|
3049
|
-
const CRLF: "\r\n";
|
|
3050
|
-
```
|
|
3051
|
-
|
|
3052
|
-
Defined in: [packages/fs/src/eol.ts:9](https://github.com/visulima/visulima/blob/605d0fc030334277c4a55eed06631ab95f470bdd/packages/fs/src/eol.ts#L9)
|
|
4038
|
+
#### Example
|
|
3053
4039
|
|
|
3054
|
-
|
|
4040
|
+
```javascript
|
|
4041
|
+
import { writeJsonSync } from "@visulima/fs";
|
|
4042
|
+
import { join } from "node:path";
|
|
3055
4043
|
|
|
3056
|
-
|
|
4044
|
+
const writeMyJsonSync = () => {
|
|
4045
|
+
try {
|
|
4046
|
+
writeJsonSync(join("/tmp", "my-config-sync.json"), { setting: "enabled", value: 456 });
|
|
4047
|
+
console.log("JSON file written successfully (sync).");
|
|
3057
4048
|
|
|
3058
|
-
|
|
4049
|
+
writeJsonSync(join("/tmp", "another-config-sync.json"), { user: "testSync", id: "def" }, { indent: 4, replacer: ["id"] });
|
|
4050
|
+
console.log("Another JSON file written with specific options (sync, indent 4, only 'id' key).");
|
|
4051
|
+
} catch (error) {
|
|
4052
|
+
console.error("Failed to write JSON file (sync):", error);
|
|
4053
|
+
}
|
|
4054
|
+
};
|
|
3059
4055
|
|
|
3060
|
-
|
|
3061
|
-
const EOL: "\n" | "\r\n";
|
|
4056
|
+
writeMyJsonSync();
|
|
3062
4057
|
```
|
|
3063
4058
|
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
End-of-line character evaluated for the current platform.
|
|
3067
|
-
|
|
3068
|
-
***
|
|
4059
|
+
## Variables
|
|
3069
4060
|
|
|
3070
4061
|
### F\_OK
|
|
3071
4062
|
|
|
@@ -3073,9 +4064,10 @@ End-of-line character evaluated for the current platform.
|
|
|
3073
4064
|
const F_OK: 0 = 0;
|
|
3074
4065
|
```
|
|
3075
4066
|
|
|
3076
|
-
Defined in: [packages/fs/src/constants.ts:
|
|
4067
|
+
Defined in: [packages/fs/src/constants.ts:5](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/constants.ts#L5)
|
|
3077
4068
|
|
|
3078
|
-
|
|
4069
|
+
Constant to check if the path is visible to the calling process.
|
|
4070
|
+
Corresponds to `node:fs.constants.F_OK`.
|
|
3079
4071
|
|
|
3080
4072
|
***
|
|
3081
4073
|
|
|
@@ -3085,19 +4077,10 @@ Is the path visible to the calling process?
|
|
|
3085
4077
|
const FIND_UP_STOP: typeof FIND_UP_STOP;
|
|
3086
4078
|
```
|
|
3087
4079
|
|
|
3088
|
-
Defined in: [packages/fs/src/constants.ts:
|
|
3089
|
-
|
|
3090
|
-
***
|
|
3091
|
-
|
|
3092
|
-
### LF
|
|
3093
|
-
|
|
3094
|
-
```ts
|
|
3095
|
-
const LF: "\n";
|
|
3096
|
-
```
|
|
3097
|
-
|
|
3098
|
-
Defined in: [packages/fs/src/eol.ts:6](https://github.com/visulima/visulima/blob/605d0fc030334277c4a55eed06631ab95f470bdd/packages/fs/src/eol.ts#L6)
|
|
4080
|
+
Defined in: [packages/fs/src/constants.ts:29](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/constants.ts#L29)
|
|
3099
4081
|
|
|
3100
|
-
|
|
4082
|
+
A special symbol that can be returned by the matcher function in `findUp` or `findUpSync`
|
|
4083
|
+
to stop the search process prematurely.
|
|
3101
4084
|
|
|
3102
4085
|
***
|
|
3103
4086
|
|
|
@@ -3107,9 +4090,10 @@ End-of-line character for POSIX platforms such as macOS and Linux.
|
|
|
3107
4090
|
const R_OK: 4 = 4;
|
|
3108
4091
|
```
|
|
3109
4092
|
|
|
3110
|
-
Defined in: [packages/fs/src/constants.ts:
|
|
4093
|
+
Defined in: [packages/fs/src/constants.ts:11](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/constants.ts#L11)
|
|
3111
4094
|
|
|
3112
|
-
|
|
4095
|
+
Constant to check if the path is readable to the calling process.
|
|
4096
|
+
Corresponds to `node:fs.constants.R_OK`.
|
|
3113
4097
|
|
|
3114
4098
|
***
|
|
3115
4099
|
|
|
@@ -3119,9 +4103,10 @@ Is the path readable to the calling process?
|
|
|
3119
4103
|
const W_OK: 2 = 2;
|
|
3120
4104
|
```
|
|
3121
4105
|
|
|
3122
|
-
Defined in: [packages/fs/src/constants.ts:
|
|
4106
|
+
Defined in: [packages/fs/src/constants.ts:17](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/constants.ts#L17)
|
|
3123
4107
|
|
|
3124
|
-
|
|
4108
|
+
Constant to check if the path is writable to the calling process.
|
|
4109
|
+
Corresponds to `node:fs.constants.W_OK`.
|
|
3125
4110
|
|
|
3126
4111
|
***
|
|
3127
4112
|
|
|
@@ -3131,15 +4116,18 @@ Is the path writable to the calling process?
|
|
|
3131
4116
|
const X_OK: 1 = 1;
|
|
3132
4117
|
```
|
|
3133
4118
|
|
|
3134
|
-
Defined in: [packages/fs/src/constants.ts:
|
|
4119
|
+
Defined in: [packages/fs/src/constants.ts:23](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/constants.ts#L23)
|
|
3135
4120
|
|
|
3136
|
-
|
|
4121
|
+
Constant to check if the path is executable by the calling process.
|
|
4122
|
+
Corresponds to `node:fs.constants.X_OK`.
|
|
3137
4123
|
|
|
3138
4124
|
## Interfaces
|
|
3139
4125
|
|
|
3140
4126
|
### WalkEntry
|
|
3141
4127
|
|
|
3142
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4128
|
+
Defined in: [packages/fs/src/types.ts:62](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L62)
|
|
4129
|
+
|
|
4130
|
+
Represents an entry found by `walk` or `walkSync`.
|
|
3143
4131
|
|
|
3144
4132
|
#### Extends
|
|
3145
4133
|
|
|
@@ -3249,13 +4237,17 @@ Pick.name
|
|
|
3249
4237
|
path: string;
|
|
3250
4238
|
```
|
|
3251
4239
|
|
|
3252
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4240
|
+
Defined in: [packages/fs/src/types.ts:64](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L64)
|
|
4241
|
+
|
|
4242
|
+
The full path to the entry.
|
|
3253
4243
|
|
|
3254
4244
|
***
|
|
3255
4245
|
|
|
3256
4246
|
### WalkOptions
|
|
3257
4247
|
|
|
3258
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4248
|
+
Defined in: [packages/fs/src/types.ts:12](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L12)
|
|
4249
|
+
|
|
4250
|
+
Options for the `walk` and `walkSync` functions.
|
|
3259
4251
|
|
|
3260
4252
|
#### Properties
|
|
3261
4253
|
|
|
@@ -3265,7 +4257,7 @@ Defined in: [packages/fs/src/types.ts:9](https://github.com/visulima/visulima/bl
|
|
|
3265
4257
|
optional extensions: string[];
|
|
3266
4258
|
```
|
|
3267
4259
|
|
|
3268
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4260
|
+
Defined in: [packages/fs/src/types.ts:18](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L18)
|
|
3269
4261
|
|
|
3270
4262
|
List of file extensions used to filter entries.
|
|
3271
4263
|
If specified, entries without the file extension specified by this option are excluded.
|
|
@@ -3282,7 +4274,7 @@ If specified, entries without the file extension specified by this option are ex
|
|
|
3282
4274
|
optional followSymlinks: boolean;
|
|
3283
4275
|
```
|
|
3284
4276
|
|
|
3285
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4277
|
+
Defined in: [packages/fs/src/types.ts:23](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L23)
|
|
3286
4278
|
|
|
3287
4279
|
Indicates whether symlinks should be resolved or not.
|
|
3288
4280
|
|
|
@@ -3298,7 +4290,7 @@ Indicates whether symlinks should be resolved or not.
|
|
|
3298
4290
|
optional includeDirs: boolean;
|
|
3299
4291
|
```
|
|
3300
4292
|
|
|
3301
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4293
|
+
Defined in: [packages/fs/src/types.ts:28](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L28)
|
|
3302
4294
|
|
|
3303
4295
|
Indicates whether directory entries should be included or not.
|
|
3304
4296
|
|
|
@@ -3314,7 +4306,7 @@ Indicates whether directory entries should be included or not.
|
|
|
3314
4306
|
optional includeFiles: boolean;
|
|
3315
4307
|
```
|
|
3316
4308
|
|
|
3317
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4309
|
+
Defined in: [packages/fs/src/types.ts:33](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L33)
|
|
3318
4310
|
|
|
3319
4311
|
Indicates whether file entries should be included or not.
|
|
3320
4312
|
|
|
@@ -3330,7 +4322,7 @@ Indicates whether file entries should be included or not.
|
|
|
3330
4322
|
optional includeSymlinks: boolean;
|
|
3331
4323
|
```
|
|
3332
4324
|
|
|
3333
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4325
|
+
Defined in: [packages/fs/src/types.ts:39](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L39)
|
|
3334
4326
|
|
|
3335
4327
|
Indicates whether symlink entries should be included or not.
|
|
3336
4328
|
This option is meaningful only if `followSymlinks` is set to `false`.
|
|
@@ -3347,7 +4339,7 @@ This option is meaningful only if `followSymlinks` is set to `false`.
|
|
|
3347
4339
|
optional match: (string | RegExp)[];
|
|
3348
4340
|
```
|
|
3349
4341
|
|
|
3350
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4342
|
+
Defined in: [packages/fs/src/types.ts:45](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L45)
|
|
3351
4343
|
|
|
3352
4344
|
List of regular expression or glob patterns used to filter entries.
|
|
3353
4345
|
If specified, entries that do not match the patterns specified by this option are excluded.
|
|
@@ -3364,7 +4356,7 @@ If specified, entries that do not match the patterns specified by this option ar
|
|
|
3364
4356
|
optional maxDepth: number;
|
|
3365
4357
|
```
|
|
3366
4358
|
|
|
3367
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4359
|
+
Defined in: [packages/fs/src/types.ts:50](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L50)
|
|
3368
4360
|
|
|
3369
4361
|
The maximum depth of the file tree to be walked recursively.
|
|
3370
4362
|
|
|
@@ -3380,7 +4372,7 @@ The maximum depth of the file tree to be walked recursively.
|
|
|
3380
4372
|
optional skip: (string | RegExp)[];
|
|
3381
4373
|
```
|
|
3382
4374
|
|
|
3383
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4375
|
+
Defined in: [packages/fs/src/types.ts:56](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L56)
|
|
3384
4376
|
|
|
3385
4377
|
List of regular expression or glob patterns used to filter entries.
|
|
3386
4378
|
If specified, entries matching the patterns specified by this option are excluded.
|
|
@@ -3399,7 +4391,9 @@ If specified, entries matching the patterns specified by this option are exclude
|
|
|
3399
4391
|
type CodeFrameLocation = object;
|
|
3400
4392
|
```
|
|
3401
4393
|
|
|
3402
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4394
|
+
Defined in: [packages/fs/src/types.ts:117](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L117)
|
|
4395
|
+
|
|
4396
|
+
Specifies a location (line and column) in a file for code frame generation.
|
|
3403
4397
|
|
|
3404
4398
|
#### Properties
|
|
3405
4399
|
|
|
@@ -3409,7 +4403,9 @@ Defined in: [packages/fs/src/types.ts:91](https://github.com/visulima/visulima/b
|
|
|
3409
4403
|
optional column: number;
|
|
3410
4404
|
```
|
|
3411
4405
|
|
|
3412
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4406
|
+
Defined in: [packages/fs/src/types.ts:119](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L119)
|
|
4407
|
+
|
|
4408
|
+
The column number.
|
|
3413
4409
|
|
|
3414
4410
|
##### line
|
|
3415
4411
|
|
|
@@ -3417,57 +4413,78 @@ Defined in: [packages/fs/src/types.ts:92](https://github.com/visulima/visulima/b
|
|
|
3417
4413
|
line: number;
|
|
3418
4414
|
```
|
|
3419
4415
|
|
|
3420
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4416
|
+
Defined in: [packages/fs/src/types.ts:121](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L121)
|
|
4417
|
+
|
|
4418
|
+
The line number.
|
|
3421
4419
|
|
|
3422
4420
|
***
|
|
3423
4421
|
|
|
3424
|
-
###
|
|
4422
|
+
### CodeFrameOptions
|
|
3425
4423
|
|
|
3426
4424
|
```ts
|
|
3427
|
-
type
|
|
4425
|
+
type CodeFrameOptions = object;
|
|
3428
4426
|
```
|
|
3429
4427
|
|
|
3430
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4428
|
+
Defined in: [packages/fs/src/types.ts:127](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L127)
|
|
4429
|
+
|
|
4430
|
+
Options for customizing the appearance of code frames.
|
|
3431
4431
|
|
|
3432
4432
|
#### Properties
|
|
3433
4433
|
|
|
3434
|
-
#####
|
|
4434
|
+
##### color?
|
|
3435
4435
|
|
|
3436
4436
|
```ts
|
|
3437
|
-
optional
|
|
4437
|
+
optional color: object;
|
|
3438
4438
|
```
|
|
3439
4439
|
|
|
3440
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4440
|
+
Defined in: [packages/fs/src/types.ts:129](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L129)
|
|
3441
4441
|
|
|
3442
|
-
|
|
3443
|
-
`EPERM` error is encountered, Node.js will retry the operation with a linear
|
|
3444
|
-
backoff wait of `retryDelay` ms longer on each try. This option represents the
|
|
3445
|
-
number of retries. This option is ignored if the `recursive` option is not
|
|
3446
|
-
`true`.
|
|
4442
|
+
Colorization methods for different parts of the code frame.
|
|
3447
4443
|
|
|
3448
|
-
######
|
|
4444
|
+
###### gutter?
|
|
3449
4445
|
|
|
3450
4446
|
```ts
|
|
3451
|
-
|
|
4447
|
+
optional gutter: ColorizeMethod;
|
|
3452
4448
|
```
|
|
3453
4449
|
|
|
3454
|
-
|
|
4450
|
+
Color for the gutter (line numbers).
|
|
4451
|
+
|
|
4452
|
+
###### marker?
|
|
3455
4453
|
|
|
3456
4454
|
```ts
|
|
3457
|
-
optional
|
|
4455
|
+
optional marker: ColorizeMethod;
|
|
3458
4456
|
```
|
|
3459
4457
|
|
|
3460
|
-
|
|
4458
|
+
Color for the marker (pointing to the error).
|
|
3461
4459
|
|
|
3462
|
-
|
|
3463
|
-
This option is ignored if the `recursive` option is not `true`.
|
|
4460
|
+
###### message?
|
|
3464
4461
|
|
|
3465
|
-
|
|
4462
|
+
```ts
|
|
4463
|
+
optional message: ColorizeMethod;
|
|
4464
|
+
```
|
|
4465
|
+
|
|
4466
|
+
Color for the message.
|
|
4467
|
+
|
|
4468
|
+
***
|
|
4469
|
+
|
|
4470
|
+
### ContentType\<O\>
|
|
3466
4471
|
|
|
3467
4472
|
```ts
|
|
3468
|
-
|
|
4473
|
+
type ContentType<O> = O extends object ? Buffer : string;
|
|
3469
4474
|
```
|
|
3470
4475
|
|
|
4476
|
+
Defined in: [packages/fs/src/types.ts:104](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L104)
|
|
4477
|
+
|
|
4478
|
+
Represents the content type of a read file, which can be a Buffer or a string based on options.
|
|
4479
|
+
|
|
4480
|
+
#### Type Parameters
|
|
4481
|
+
|
|
4482
|
+
##### O
|
|
4483
|
+
|
|
4484
|
+
`O` = `undefined`
|
|
4485
|
+
|
|
4486
|
+
The ReadFileOptions type.
|
|
4487
|
+
|
|
3471
4488
|
***
|
|
3472
4489
|
|
|
3473
4490
|
### FindUpName
|
|
@@ -3479,7 +4496,10 @@ type FindUpName =
|
|
|
3479
4496
|
| (directory) => FindUpNameFnResult;
|
|
3480
4497
|
```
|
|
3481
4498
|
|
|
3482
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4499
|
+
Defined in: [packages/fs/src/types.ts:270](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L270)
|
|
4500
|
+
|
|
4501
|
+
Specifies the name(s) of the file or directory to search for in `findUp`.
|
|
4502
|
+
Can be a single name, an array of names, or a function that returns a name or `FIND_UP_STOP`.
|
|
3483
4503
|
|
|
3484
4504
|
***
|
|
3485
4505
|
|
|
@@ -3493,7 +4513,11 @@ type FindUpNameFnResult =
|
|
|
3493
4513
|
| undefined;
|
|
3494
4514
|
```
|
|
3495
4515
|
|
|
3496
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4516
|
+
Defined in: [packages/fs/src/types.ts:264](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L264)
|
|
4517
|
+
|
|
4518
|
+
The result type for the name matcher function used in `findUp`.
|
|
4519
|
+
It can be a `PathLike` (string, Buffer, or URL), a Promise resolving to `PathLike` or `FIND_UP_STOP`,
|
|
4520
|
+
`FIND_UP_STOP` to stop the search, or `undefined` to continue.
|
|
3497
4521
|
|
|
3498
4522
|
***
|
|
3499
4523
|
|
|
@@ -3506,7 +4530,10 @@ type FindUpNameSync =
|
|
|
3506
4530
|
| (directory) => FindUpNameSyncFnResult;
|
|
3507
4531
|
```
|
|
3508
4532
|
|
|
3509
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4533
|
+
Defined in: [packages/fs/src/types.ts:284](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L284)
|
|
4534
|
+
|
|
4535
|
+
Specifies the name(s) of the file or directory to search for in `findUpSync`.
|
|
4536
|
+
Can be a single name, an array of names, or a function that returns a name or `FIND_UP_STOP`.
|
|
3510
4537
|
|
|
3511
4538
|
***
|
|
3512
4539
|
|
|
@@ -3516,7 +4543,11 @@ Defined in: [packages/fs/src/types.ts:185](https://github.com/visulima/visulima/
|
|
|
3516
4543
|
type FindUpNameSyncFnResult = PathLike | typeof FIND_UP_STOP | undefined;
|
|
3517
4544
|
```
|
|
3518
4545
|
|
|
3519
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4546
|
+
Defined in: [packages/fs/src/types.ts:278](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L278)
|
|
4547
|
+
|
|
4548
|
+
The result type for the name matcher function used in `findUpSync`.
|
|
4549
|
+
It can be a `PathLike` (string, Buffer, or URL), `FIND_UP_STOP` to stop the search,
|
|
4550
|
+
or `undefined` to continue.
|
|
3520
4551
|
|
|
3521
4552
|
***
|
|
3522
4553
|
|
|
@@ -3526,7 +4557,9 @@ Defined in: [packages/fs/src/types.ts:183](https://github.com/visulima/visulima/
|
|
|
3526
4557
|
type FindUpOptions = object;
|
|
3527
4558
|
```
|
|
3528
4559
|
|
|
3529
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4560
|
+
Defined in: [packages/fs/src/types.ts:235](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L235)
|
|
4561
|
+
|
|
4562
|
+
Options for the `findUp` and `findUpSync` functions.
|
|
3530
4563
|
|
|
3531
4564
|
#### Properties
|
|
3532
4565
|
|
|
@@ -3536,7 +4569,13 @@ Defined in: [packages/fs/src/types.ts:170](https://github.com/visulima/visulima/
|
|
|
3536
4569
|
optional allowSymlinks: boolean;
|
|
3537
4570
|
```
|
|
3538
4571
|
|
|
3539
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4572
|
+
Defined in: [packages/fs/src/types.ts:240](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L240)
|
|
4573
|
+
|
|
4574
|
+
Whether to follow symbolic links.
|
|
4575
|
+
|
|
4576
|
+
###### Default
|
|
4577
|
+
|
|
4578
|
+
undefined (behaves like `true` for `findUp`, `false` for `findUpSync` due to `fs.stat` vs `fs.lstat`)
|
|
3540
4579
|
|
|
3541
4580
|
##### cwd?
|
|
3542
4581
|
|
|
@@ -3544,7 +4583,15 @@ Defined in: [packages/fs/src/types.ts:171](https://github.com/visulima/visulima/
|
|
|
3544
4583
|
optional cwd: URL | string;
|
|
3545
4584
|
```
|
|
3546
4585
|
|
|
3547
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4586
|
+
Defined in: [packages/fs/src/types.ts:245](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L245)
|
|
4587
|
+
|
|
4588
|
+
The current working directory.
|
|
4589
|
+
|
|
4590
|
+
###### Default
|
|
4591
|
+
|
|
4592
|
+
```ts
|
|
4593
|
+
process.cwd()
|
|
4594
|
+
```
|
|
3548
4595
|
|
|
3549
4596
|
##### stopAt?
|
|
3550
4597
|
|
|
@@ -3552,16 +4599,32 @@ Defined in: [packages/fs/src/types.ts:172](https://github.com/visulima/visulima/
|
|
|
3552
4599
|
optional stopAt: URL | string;
|
|
3553
4600
|
```
|
|
3554
4601
|
|
|
3555
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4602
|
+
Defined in: [packages/fs/src/types.ts:250](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L250)
|
|
4603
|
+
|
|
4604
|
+
The directory to stop searching at.
|
|
4605
|
+
|
|
4606
|
+
###### Default
|
|
4607
|
+
|
|
4608
|
+
```ts
|
|
4609
|
+
path.parse(cwd).root
|
|
4610
|
+
```
|
|
4611
|
+
|
|
4612
|
+
##### type?
|
|
4613
|
+
|
|
4614
|
+
```ts
|
|
4615
|
+
optional type: "directory" | "file";
|
|
4616
|
+
```
|
|
4617
|
+
|
|
4618
|
+
Defined in: [packages/fs/src/types.ts:255](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L255)
|
|
3556
4619
|
|
|
3557
|
-
|
|
4620
|
+
The type of path to find.
|
|
4621
|
+
|
|
4622
|
+
###### Default
|
|
3558
4623
|
|
|
3559
4624
|
```ts
|
|
3560
|
-
|
|
4625
|
+
"file"
|
|
3561
4626
|
```
|
|
3562
4627
|
|
|
3563
|
-
Defined in: [packages/fs/src/types.ts:174](https://github.com/visulima/visulima/blob/605d0fc030334277c4a55eed06631ab95f470bdd/packages/fs/src/types.ts#L174)
|
|
3564
|
-
|
|
3565
4628
|
***
|
|
3566
4629
|
|
|
3567
4630
|
### JsonReplacer
|
|
@@ -3570,7 +4633,13 @@ Defined in: [packages/fs/src/types.ts:174](https://github.com/visulima/visulima/
|
|
|
3570
4633
|
type JsonReplacer = (number | string)[] | (this, key, value) => unknown | null;
|
|
3571
4634
|
```
|
|
3572
4635
|
|
|
3573
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4636
|
+
Defined in: [packages/fs/src/types.ts:197](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L197)
|
|
4637
|
+
|
|
4638
|
+
Type for the `replacer` parameter of `JSON.stringify()`.
|
|
4639
|
+
Can be a function that alters the behavior of the stringification process,
|
|
4640
|
+
or an array of strings and numbers that acts as a whitelist for selecting
|
|
4641
|
+
the properties of the value object to be included in the JSON string.
|
|
4642
|
+
If this value is null or not provided, all properties of the object are included in the resulting JSON string.
|
|
3574
4643
|
|
|
3575
4644
|
***
|
|
3576
4645
|
|
|
@@ -3580,7 +4649,11 @@ Defined in: [packages/fs/src/types.ts:143](https://github.com/visulima/visulima/
|
|
|
3580
4649
|
type JsonReviver = Parameters<typeof JSON["parse"]>["1"];
|
|
3581
4650
|
```
|
|
3582
4651
|
|
|
3583
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4652
|
+
Defined in: [packages/fs/src/types.ts:112](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L112)
|
|
4653
|
+
|
|
4654
|
+
Type for the `reviver` parameter of `JSON.parse()`.
|
|
4655
|
+
A function that transforms the results. This function is called for each member of the object.
|
|
4656
|
+
If a member contains nested objects, the nested objects are transformed before the parent object is.
|
|
3584
4657
|
|
|
3585
4658
|
***
|
|
3586
4659
|
|
|
@@ -3590,7 +4663,7 @@ Defined in: [packages/fs/src/types.ts:89](https://github.com/visulima/visulima/b
|
|
|
3590
4663
|
type MoveOptions = object;
|
|
3591
4664
|
```
|
|
3592
4665
|
|
|
3593
|
-
Defined in: [packages/fs/src/move/types.ts:3](https://github.com/visulima/visulima/blob/
|
|
4666
|
+
Defined in: [packages/fs/src/move/types.ts:3](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/move/types.ts#L3)
|
|
3594
4667
|
|
|
3595
4668
|
#### Properties
|
|
3596
4669
|
|
|
@@ -3600,7 +4673,7 @@ Defined in: [packages/fs/src/move/types.ts:3](https://github.com/visulima/visuli
|
|
|
3600
4673
|
optional cwd: URL | string;
|
|
3601
4674
|
```
|
|
3602
4675
|
|
|
3603
|
-
Defined in: [packages/fs/src/move/types.ts:10](https://github.com/visulima/visulima/blob/
|
|
4676
|
+
Defined in: [packages/fs/src/move/types.ts:10](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/move/types.ts#L10)
|
|
3604
4677
|
|
|
3605
4678
|
The working directory to find source files.
|
|
3606
4679
|
The source and destination path are relative to this.
|
|
@@ -3617,7 +4690,7 @@ process.cwd()
|
|
|
3617
4690
|
readonly optional directoryMode: FilePermissions;
|
|
3618
4691
|
```
|
|
3619
4692
|
|
|
3620
|
-
Defined in: [packages/fs/src/move/types.ts:19](https://github.com/visulima/visulima/blob/
|
|
4693
|
+
Defined in: [packages/fs/src/move/types.ts:19](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/move/types.ts#L19)
|
|
3621
4694
|
|
|
3622
4695
|
[Permissions](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) for created directories.
|
|
3623
4696
|
|
|
@@ -3635,7 +4708,7 @@ It has no effect on Windows.
|
|
|
3635
4708
|
readonly optional overwrite: boolean;
|
|
3636
4709
|
```
|
|
3637
4710
|
|
|
3638
|
-
Defined in: [packages/fs/src/move/types.ts:26](https://github.com/visulima/visulima/blob/
|
|
4711
|
+
Defined in: [packages/fs/src/move/types.ts:26](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/move/types.ts#L26)
|
|
3639
4712
|
|
|
3640
4713
|
Overwrite existing destination file.
|
|
3641
4714
|
|
|
@@ -3664,7 +4737,9 @@ type ReadFileEncoding =
|
|
|
3664
4737
|
| "utf16le";
|
|
3665
4738
|
```
|
|
3666
4739
|
|
|
3667
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4740
|
+
Defined in: [packages/fs/src/types.ts:71](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L71)
|
|
4741
|
+
|
|
4742
|
+
Supported file encodings for reading files.
|
|
3668
4743
|
|
|
3669
4744
|
***
|
|
3670
4745
|
|
|
@@ -3674,7 +4749,9 @@ Defined in: [packages/fs/src/types.ts:61](https://github.com/visulima/visulima/b
|
|
|
3674
4749
|
type ReadFileOptions<C> = object;
|
|
3675
4750
|
```
|
|
3676
4751
|
|
|
3677
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4752
|
+
Defined in: [packages/fs/src/types.ts:77](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L77)
|
|
4753
|
+
|
|
4754
|
+
Options for reading files.
|
|
3678
4755
|
|
|
3679
4756
|
#### Type Parameters
|
|
3680
4757
|
|
|
@@ -3682,6 +4759,8 @@ Defined in: [packages/fs/src/types.ts:63](https://github.com/visulima/visulima/b
|
|
|
3682
4759
|
|
|
3683
4760
|
`C`
|
|
3684
4761
|
|
|
4762
|
+
The type of compression used.
|
|
4763
|
+
|
|
3685
4764
|
#### Properties
|
|
3686
4765
|
|
|
3687
4766
|
##### buffer?
|
|
@@ -3690,7 +4769,7 @@ Defined in: [packages/fs/src/types.ts:63](https://github.com/visulima/visulima/b
|
|
|
3690
4769
|
optional buffer: boolean;
|
|
3691
4770
|
```
|
|
3692
4771
|
|
|
3693
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4772
|
+
Defined in: [packages/fs/src/types.ts:81](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L81)
|
|
3694
4773
|
|
|
3695
4774
|
Return content as a Buffer. Default: `false`
|
|
3696
4775
|
|
|
@@ -3700,7 +4779,7 @@ Return content as a Buffer. Default: `false`
|
|
|
3700
4779
|
optional compression: C;
|
|
3701
4780
|
```
|
|
3702
4781
|
|
|
3703
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4782
|
+
Defined in: [packages/fs/src/types.ts:86](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L86)
|
|
3704
4783
|
|
|
3705
4784
|
Compression method to decompress the file against. Default: `none`
|
|
3706
4785
|
|
|
@@ -3710,7 +4789,7 @@ Compression method to decompress the file against. Default: `none`
|
|
|
3710
4789
|
optional encoding: ReadFileEncoding;
|
|
3711
4790
|
```
|
|
3712
4791
|
|
|
3713
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4792
|
+
Defined in: [packages/fs/src/types.ts:92](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L92)
|
|
3714
4793
|
|
|
3715
4794
|
The encoding to use. Default: `utf8`
|
|
3716
4795
|
|
|
@@ -3724,7 +4803,7 @@ https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings
|
|
|
3724
4803
|
optional flag: number | string;
|
|
3725
4804
|
```
|
|
3726
4805
|
|
|
3727
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4806
|
+
Defined in: [packages/fs/src/types.ts:97](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L97)
|
|
3728
4807
|
|
|
3729
4808
|
The flag used to open the file. Default: `r`
|
|
3730
4809
|
|
|
@@ -3736,7 +4815,10 @@ The flag used to open the file. Default: `r`
|
|
|
3736
4815
|
type ReadJsonOptions = CodeFrameOptions & object;
|
|
3737
4816
|
```
|
|
3738
4817
|
|
|
3739
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4818
|
+
Defined in: [packages/fs/src/types.ts:143](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L143)
|
|
4819
|
+
|
|
4820
|
+
Options for reading and parsing JSON files.
|
|
4821
|
+
Extends [CodeFrameOptions](#codeframeoptions).
|
|
3740
4822
|
|
|
3741
4823
|
#### Type declaration
|
|
3742
4824
|
|
|
@@ -3746,16 +4828,22 @@ Defined in: [packages/fs/src/types.ts:104](https://github.com/visulima/visulima/
|
|
|
3746
4828
|
optional beforeParse: (source) => string;
|
|
3747
4829
|
```
|
|
3748
4830
|
|
|
4831
|
+
A function to transform the string content before parsing.
|
|
4832
|
+
|
|
3749
4833
|
###### Parameters
|
|
3750
4834
|
|
|
3751
4835
|
###### source
|
|
3752
4836
|
|
|
3753
4837
|
`string`
|
|
3754
4838
|
|
|
4839
|
+
The raw string content of the file.
|
|
4840
|
+
|
|
3755
4841
|
###### Returns
|
|
3756
4842
|
|
|
3757
4843
|
`string`
|
|
3758
4844
|
|
|
4845
|
+
The transformed string content.
|
|
4846
|
+
|
|
3759
4847
|
***
|
|
3760
4848
|
|
|
3761
4849
|
### WriteFileOptions
|
|
@@ -3764,7 +4852,9 @@ optional beforeParse: (source) => string;
|
|
|
3764
4852
|
type WriteFileOptions = object;
|
|
3765
4853
|
```
|
|
3766
4854
|
|
|
3767
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4855
|
+
Defined in: [packages/fs/src/types.ts:155](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L155)
|
|
4856
|
+
|
|
4857
|
+
Options for writing files.
|
|
3768
4858
|
|
|
3769
4859
|
#### Properties
|
|
3770
4860
|
|
|
@@ -3774,7 +4864,7 @@ Defined in: [packages/fs/src/types.ts:108](https://github.com/visulima/visulima/
|
|
|
3774
4864
|
optional chown: object;
|
|
3775
4865
|
```
|
|
3776
4866
|
|
|
3777
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4867
|
+
Defined in: [packages/fs/src/types.ts:159](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L159)
|
|
3778
4868
|
|
|
3779
4869
|
The group and user ID used to set the file ownership. Default: `undefined`
|
|
3780
4870
|
|
|
@@ -3796,7 +4886,7 @@ uid: number;
|
|
|
3796
4886
|
optional encoding: BufferEncoding | null;
|
|
3797
4887
|
```
|
|
3798
4888
|
|
|
3799
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4889
|
+
Defined in: [packages/fs/src/types.ts:167](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L167)
|
|
3800
4890
|
|
|
3801
4891
|
The encoding to use. Default: `utf8`
|
|
3802
4892
|
|
|
@@ -3806,7 +4896,7 @@ The encoding to use. Default: `utf8`
|
|
|
3806
4896
|
optional flag: string;
|
|
3807
4897
|
```
|
|
3808
4898
|
|
|
3809
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4899
|
+
Defined in: [packages/fs/src/types.ts:172](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L172)
|
|
3810
4900
|
|
|
3811
4901
|
The flag used to write the file. Default: `w`
|
|
3812
4902
|
|
|
@@ -3816,7 +4906,7 @@ The flag used to write the file. Default: `w`
|
|
|
3816
4906
|
optional mode: number;
|
|
3817
4907
|
```
|
|
3818
4908
|
|
|
3819
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4909
|
+
Defined in: [packages/fs/src/types.ts:177](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L177)
|
|
3820
4910
|
|
|
3821
4911
|
The file mode (permission and sticky bits). Default: `0o666`
|
|
3822
4912
|
|
|
@@ -3826,7 +4916,7 @@ The file mode (permission and sticky bits). Default: `0o666`
|
|
|
3826
4916
|
optional overwrite: boolean;
|
|
3827
4917
|
```
|
|
3828
4918
|
|
|
3829
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4919
|
+
Defined in: [packages/fs/src/types.ts:182](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L182)
|
|
3830
4920
|
|
|
3831
4921
|
Indicates whether the file should be overwritten if it already exists. Default: `false`
|
|
3832
4922
|
|
|
@@ -3836,7 +4926,7 @@ Indicates whether the file should be overwritten if it already exists. Default:
|
|
|
3836
4926
|
optional recursive: boolean;
|
|
3837
4927
|
```
|
|
3838
4928
|
|
|
3839
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4929
|
+
Defined in: [packages/fs/src/types.ts:187](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L187)
|
|
3840
4930
|
|
|
3841
4931
|
Recursively create parent directories if needed. Default: `true`
|
|
3842
4932
|
|
|
@@ -3848,7 +4938,10 @@ Recursively create parent directories if needed. Default: `true`
|
|
|
3848
4938
|
type WriteJsonOptions = WriteFileOptions & object;
|
|
3849
4939
|
```
|
|
3850
4940
|
|
|
3851
|
-
Defined in: [packages/fs/src/types.ts:
|
|
4941
|
+
Defined in: [packages/fs/src/types.ts:208](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L208)
|
|
4942
|
+
|
|
4943
|
+
Options for writing JSON files.
|
|
4944
|
+
Extends [WriteFileOptions](#writefileoptions).
|
|
3852
4945
|
|
|
3853
4946
|
#### Type declaration
|
|
3854
4947
|
|
|
@@ -3903,6 +4996,36 @@ Override the default `JSON.stringify` method.
|
|
|
3903
4996
|
###### Returns
|
|
3904
4997
|
|
|
3905
4998
|
`string`
|
|
4999
|
+
|
|
5000
|
+
## References
|
|
5001
|
+
|
|
5002
|
+
### CRLF
|
|
5003
|
+
|
|
5004
|
+
Re-exports [CRLF](eol.md#crlf)
|
|
5005
|
+
|
|
5006
|
+
***
|
|
5007
|
+
|
|
5008
|
+
### detect
|
|
5009
|
+
|
|
5010
|
+
Re-exports [detect](eol.md#detect)
|
|
5011
|
+
|
|
5012
|
+
***
|
|
5013
|
+
|
|
5014
|
+
### EOL
|
|
5015
|
+
|
|
5016
|
+
Re-exports [EOL](eol.md#eol)
|
|
5017
|
+
|
|
5018
|
+
***
|
|
5019
|
+
|
|
5020
|
+
### format
|
|
5021
|
+
|
|
5022
|
+
Re-exports [format](eol.md#format)
|
|
5023
|
+
|
|
5024
|
+
***
|
|
5025
|
+
|
|
5026
|
+
### LF
|
|
5027
|
+
|
|
5028
|
+
Re-exports [LF](eol.md#lf)
|
|
3906
5029
|
# size
|
|
3907
5030
|
|
|
3908
5031
|
## Functions
|
|
@@ -3913,25 +5036,69 @@ Override the default `JSON.stringify` method.
|
|
|
3913
5036
|
function brotliSize(input, options?): Promise<number>;
|
|
3914
5037
|
```
|
|
3915
5038
|
|
|
3916
|
-
Defined in: [packages/fs/src/size.ts:
|
|
5039
|
+
Defined in: [packages/fs/src/size.ts:222](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/size.ts#L222)
|
|
3917
5040
|
|
|
3918
|
-
Asynchronously calculates the Brotli compressed size of the input.
|
|
3919
|
-
|
|
5041
|
+
Asynchronously calculates the Brotli compressed size of the given input.
|
|
5042
|
+
The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
5043
|
+
Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
3920
5044
|
|
|
3921
5045
|
#### Parameters
|
|
3922
5046
|
|
|
3923
5047
|
##### input
|
|
3924
5048
|
|
|
5049
|
+
The input data to compress with Brotli and measure.
|
|
5050
|
+
|
|
3925
5051
|
`string` | `URL` | `Buffer`\<`ArrayBufferLike`\> | `Readable`
|
|
3926
5052
|
|
|
3927
5053
|
##### options?
|
|
3928
5054
|
|
|
3929
5055
|
`BrotliOptions`
|
|
3930
5056
|
|
|
5057
|
+
Optional Zlib options for Brotli compression.
|
|
5058
|
+
|
|
3931
5059
|
#### Returns
|
|
3932
5060
|
|
|
3933
5061
|
`Promise`\<`number`\>
|
|
3934
5062
|
|
|
5063
|
+
A promise that resolves with the Brotli compressed size in bytes.
|
|
5064
|
+
|
|
5065
|
+
#### Example
|
|
5066
|
+
|
|
5067
|
+
```javascript
|
|
5068
|
+
import { brotliSize } from "@visulima/fs";
|
|
5069
|
+
import { Readable } from "node:stream";
|
|
5070
|
+
import { writeFile, unlink } from "node:fs/promises";
|
|
5071
|
+
import { join } from "node:path";
|
|
5072
|
+
|
|
5073
|
+
const text = "This is a test string for Brotli compression efficiency.";
|
|
5074
|
+
const filePath = join("temp-brotli-file.txt");
|
|
5075
|
+
|
|
5076
|
+
async function main() {
|
|
5077
|
+
// From Buffer
|
|
5078
|
+
const buffer = Buffer.from(text);
|
|
5079
|
+
console.log(`Brotli size of buffer: ${await brotliSize(buffer)} bytes`);
|
|
5080
|
+
|
|
5081
|
+
// From string (content)
|
|
5082
|
+
console.log(`Brotli size of string content: ${await brotliSize(text)} bytes`);
|
|
5083
|
+
|
|
5084
|
+
// From file path
|
|
5085
|
+
await writeFile(filePath, text);
|
|
5086
|
+
console.log(`Brotli size of file: ${await brotliSize(filePath)} bytes`);
|
|
5087
|
+
|
|
5088
|
+
// From URL
|
|
5089
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5090
|
+
console.log(`Brotli size of URL: ${await brotliSize(fileUrl)} bytes`);
|
|
5091
|
+
|
|
5092
|
+
// From Readable stream
|
|
5093
|
+
const stream = Readable.from(text);
|
|
5094
|
+
console.log(`Brotli size of stream: ${await brotliSize(stream)} bytes`);
|
|
5095
|
+
|
|
5096
|
+
await unlink(filePath); // Clean up temp file
|
|
5097
|
+
}
|
|
5098
|
+
|
|
5099
|
+
main().catch(console.error);
|
|
5100
|
+
```
|
|
5101
|
+
|
|
3935
5102
|
***
|
|
3936
5103
|
|
|
3937
5104
|
### brotliSizeSync()
|
|
@@ -3940,25 +5107,62 @@ Uses memory-efficient streaming for large inputs.
|
|
|
3940
5107
|
function brotliSizeSync(input, options?): number;
|
|
3941
5108
|
```
|
|
3942
5109
|
|
|
3943
|
-
Defined in: [packages/fs/src/size.ts:
|
|
5110
|
+
Defined in: [packages/fs/src/size.ts:370](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/size.ts#L370)
|
|
3944
5111
|
|
|
3945
|
-
Synchronously calculates the Brotli compressed size of the input.
|
|
3946
|
-
|
|
5112
|
+
Synchronously calculates the Brotli compressed size of the given input.
|
|
5113
|
+
The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
5114
|
+
Note: For Readable streams or very large files, consider using the asynchronous `brotliSize` function for better performance and to avoid blocking.
|
|
3947
5115
|
|
|
3948
5116
|
#### Parameters
|
|
3949
5117
|
|
|
3950
5118
|
##### input
|
|
3951
5119
|
|
|
5120
|
+
The input data to compress with Brotli and measure.
|
|
5121
|
+
|
|
3952
5122
|
`string` | `URL` | `Buffer`\<`ArrayBufferLike`\>
|
|
3953
5123
|
|
|
3954
5124
|
##### options?
|
|
3955
5125
|
|
|
3956
5126
|
`BrotliOptions`
|
|
3957
5127
|
|
|
5128
|
+
Optional Zlib options for Brotli compression.
|
|
5129
|
+
|
|
3958
5130
|
#### Returns
|
|
3959
5131
|
|
|
3960
5132
|
`number`
|
|
3961
5133
|
|
|
5134
|
+
The Brotli compressed size in bytes.
|
|
5135
|
+
|
|
5136
|
+
#### Example
|
|
5137
|
+
|
|
5138
|
+
```javascript
|
|
5139
|
+
import { brotliSizeSync } from "@visulima/fs";
|
|
5140
|
+
import { writeFileSync, unlinkSync } from "node:fs";
|
|
5141
|
+
import { join } from "node:path";
|
|
5142
|
+
|
|
5143
|
+
const text = "This is a test string for Brotli compression efficiency, synchronously.";
|
|
5144
|
+
const filePath = join("temp-brotli-sync-file.txt");
|
|
5145
|
+
|
|
5146
|
+
// From Buffer
|
|
5147
|
+
const buffer = Buffer.from(text);
|
|
5148
|
+
console.log(`Sync Brotli size of buffer: ${brotliSizeSync(buffer)} bytes`);
|
|
5149
|
+
|
|
5150
|
+
// From string (content)
|
|
5151
|
+
console.log(`Sync Brotli size of string content: ${brotliSizeSync(text)} bytes`);
|
|
5152
|
+
|
|
5153
|
+
// From file path
|
|
5154
|
+
try {
|
|
5155
|
+
writeFileSync(filePath, text);
|
|
5156
|
+
console.log(`Sync Brotli size of file: ${brotliSizeSync(filePath)} bytes`);
|
|
5157
|
+
|
|
5158
|
+
// From URL
|
|
5159
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5160
|
+
console.log(`Sync Brotli size of URL: ${brotliSizeSync(fileUrl)} bytes`);
|
|
5161
|
+
} finally {
|
|
5162
|
+
try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
5163
|
+
}
|
|
5164
|
+
```
|
|
5165
|
+
|
|
3962
5166
|
***
|
|
3963
5167
|
|
|
3964
5168
|
### gzipSize()
|
|
@@ -3967,25 +5171,69 @@ Note: For large files, consider using the async brotliSize function instead.
|
|
|
3967
5171
|
function gzipSize(input, options?): Promise<number>;
|
|
3968
5172
|
```
|
|
3969
5173
|
|
|
3970
|
-
Defined in: [packages/fs/src/size.ts:
|
|
5174
|
+
Defined in: [packages/fs/src/size.ts:171](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/size.ts#L171)
|
|
3971
5175
|
|
|
3972
|
-
Asynchronously calculates the gzipped size of the input.
|
|
3973
|
-
|
|
5176
|
+
Asynchronously calculates the gzipped size of the given input.
|
|
5177
|
+
The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
5178
|
+
Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
3974
5179
|
|
|
3975
5180
|
#### Parameters
|
|
3976
5181
|
|
|
3977
5182
|
##### input
|
|
3978
5183
|
|
|
5184
|
+
The input data to gzip and measure.
|
|
5185
|
+
|
|
3979
5186
|
`string` | `URL` | `Buffer`\<`ArrayBufferLike`\> | `Readable`
|
|
3980
5187
|
|
|
3981
5188
|
##### options?
|
|
3982
5189
|
|
|
3983
5190
|
`ZlibOptions`
|
|
3984
5191
|
|
|
5192
|
+
Optional Zlib options for gzip compression.
|
|
5193
|
+
|
|
3985
5194
|
#### Returns
|
|
3986
5195
|
|
|
3987
5196
|
`Promise`\<`number`\>
|
|
3988
5197
|
|
|
5198
|
+
A promise that resolves with the gzipped size in bytes.
|
|
5199
|
+
|
|
5200
|
+
#### Example
|
|
5201
|
+
|
|
5202
|
+
```javascript
|
|
5203
|
+
import { gzipSize } from "@visulima/fs";
|
|
5204
|
+
import { Readable } from "node:stream";
|
|
5205
|
+
import { writeFile, unlink } from "node:fs/promises";
|
|
5206
|
+
import { join } from "node:path";
|
|
5207
|
+
|
|
5208
|
+
const text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
|
5209
|
+
const filePath = join("temp-file.txt");
|
|
5210
|
+
|
|
5211
|
+
async function main() {
|
|
5212
|
+
// From Buffer
|
|
5213
|
+
const buffer = Buffer.from(text);
|
|
5214
|
+
console.log(`Gzip size of buffer: ${await gzipSize(buffer)} bytes`);
|
|
5215
|
+
|
|
5216
|
+
// From string (content)
|
|
5217
|
+
console.log(`Gzip size of string content: ${await gzipSize(text)} bytes`);
|
|
5218
|
+
|
|
5219
|
+
// From file path
|
|
5220
|
+
await writeFile(filePath, text);
|
|
5221
|
+
console.log(`Gzip size of file: ${await gzipSize(filePath)} bytes`);
|
|
5222
|
+
|
|
5223
|
+
// From URL
|
|
5224
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5225
|
+
console.log(`Gzip size of URL: ${await gzipSize(fileUrl)} bytes`);
|
|
5226
|
+
|
|
5227
|
+
// From Readable stream
|
|
5228
|
+
const stream = Readable.from(text);
|
|
5229
|
+
console.log(`Gzip size of stream: ${await gzipSize(stream)} bytes`);
|
|
5230
|
+
|
|
5231
|
+
await unlink(filePath); // Clean up temp file
|
|
5232
|
+
}
|
|
5233
|
+
|
|
5234
|
+
main().catch(console.error);
|
|
5235
|
+
```
|
|
5236
|
+
|
|
3989
5237
|
***
|
|
3990
5238
|
|
|
3991
5239
|
### gzipSizeSync()
|
|
@@ -3994,25 +5242,62 @@ Uses memory-efficient streaming for large inputs.
|
|
|
3994
5242
|
function gzipSizeSync(input, options?): number;
|
|
3995
5243
|
```
|
|
3996
5244
|
|
|
3997
|
-
Defined in: [packages/fs/src/size.ts:
|
|
5245
|
+
Defined in: [packages/fs/src/size.ts:316](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/size.ts#L316)
|
|
3998
5246
|
|
|
3999
|
-
Synchronously calculates the gzipped size of the input.
|
|
4000
|
-
|
|
5247
|
+
Synchronously calculates the gzipped size of the given input.
|
|
5248
|
+
The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
5249
|
+
Note: For Readable streams or very large files, consider using the asynchronous `gzipSize` function for better performance and to avoid blocking.
|
|
4001
5250
|
|
|
4002
5251
|
#### Parameters
|
|
4003
5252
|
|
|
4004
5253
|
##### input
|
|
4005
5254
|
|
|
5255
|
+
The input data to gzip and measure.
|
|
5256
|
+
|
|
4006
5257
|
`string` | `URL` | `Buffer`\<`ArrayBufferLike`\>
|
|
4007
5258
|
|
|
4008
5259
|
##### options?
|
|
4009
5260
|
|
|
4010
5261
|
`ZlibOptions`
|
|
4011
5262
|
|
|
5263
|
+
Optional Zlib options for gzip compression.
|
|
5264
|
+
|
|
4012
5265
|
#### Returns
|
|
4013
5266
|
|
|
4014
5267
|
`number`
|
|
4015
5268
|
|
|
5269
|
+
The gzipped size in bytes.
|
|
5270
|
+
|
|
5271
|
+
#### Example
|
|
5272
|
+
|
|
5273
|
+
```javascript
|
|
5274
|
+
import { gzipSizeSync } from "@visulima/fs";
|
|
5275
|
+
import { writeFileSync, unlinkSync } from "node:fs";
|
|
5276
|
+
import { join } from "node:path";
|
|
5277
|
+
|
|
5278
|
+
const text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
|
5279
|
+
const filePath = join("temp-sync-file.txt");
|
|
5280
|
+
|
|
5281
|
+
// From Buffer
|
|
5282
|
+
const buffer = Buffer.from(text);
|
|
5283
|
+
console.log(`Sync Gzip size of buffer: ${gzipSizeSync(buffer)} bytes`);
|
|
5284
|
+
|
|
5285
|
+
// From string (content)
|
|
5286
|
+
console.log(`Sync Gzip size of string content: ${gzipSizeSync(text)} bytes`);
|
|
5287
|
+
|
|
5288
|
+
// From file path
|
|
5289
|
+
try {
|
|
5290
|
+
writeFileSync(filePath, text);
|
|
5291
|
+
console.log(`Sync Gzip size of file: ${gzipSizeSync(filePath)} bytes`);
|
|
5292
|
+
|
|
5293
|
+
// From URL
|
|
5294
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5295
|
+
console.log(`Sync Gzip size of URL: ${gzipSizeSync(fileUrl)} bytes`);
|
|
5296
|
+
} finally {
|
|
5297
|
+
try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
5298
|
+
}
|
|
5299
|
+
```
|
|
5300
|
+
|
|
4016
5301
|
***
|
|
4017
5302
|
|
|
4018
5303
|
### rawSize()
|
|
@@ -4021,21 +5306,63 @@ Note: For large files, consider using the async gzipSize function instead.
|
|
|
4021
5306
|
function rawSize(input): Promise<number>;
|
|
4022
5307
|
```
|
|
4023
5308
|
|
|
4024
|
-
Defined in: [packages/fs/src/size.ts:
|
|
5309
|
+
Defined in: [packages/fs/src/size.ts:272](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/size.ts#L272)
|
|
4025
5310
|
|
|
4026
|
-
Asynchronously
|
|
4027
|
-
|
|
5311
|
+
Asynchronously calculates the raw (uncompressed) size of the given input.
|
|
5312
|
+
The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
5313
|
+
Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
4028
5314
|
|
|
4029
5315
|
#### Parameters
|
|
4030
5316
|
|
|
4031
5317
|
##### input
|
|
4032
5318
|
|
|
5319
|
+
The input data to measure.
|
|
5320
|
+
|
|
4033
5321
|
`string` | `URL` | `Buffer`\<`ArrayBufferLike`\> | `Readable`
|
|
4034
5322
|
|
|
4035
5323
|
#### Returns
|
|
4036
5324
|
|
|
4037
5325
|
`Promise`\<`number`\>
|
|
4038
5326
|
|
|
5327
|
+
A promise that resolves with the raw size in bytes.
|
|
5328
|
+
|
|
5329
|
+
#### Example
|
|
5330
|
+
|
|
5331
|
+
```javascript
|
|
5332
|
+
import { rawSize } from "@visulima/fs";
|
|
5333
|
+
import { Readable } from "node:stream";
|
|
5334
|
+
import { writeFile, unlink } from "node:fs/promises";
|
|
5335
|
+
import { join } from "node:path";
|
|
5336
|
+
|
|
5337
|
+
const text = "Hello, World!";
|
|
5338
|
+
const filePath = join("temp-raw-file.txt");
|
|
5339
|
+
|
|
5340
|
+
async function main() {
|
|
5341
|
+
// From Buffer
|
|
5342
|
+
const buffer = Buffer.from(text);
|
|
5343
|
+
console.log(`Raw size of buffer: ${await rawSize(buffer)} bytes`);
|
|
5344
|
+
|
|
5345
|
+
// From string (content)
|
|
5346
|
+
console.log(`Raw size of string content: ${await rawSize(text)} bytes`);
|
|
5347
|
+
|
|
5348
|
+
// From file path
|
|
5349
|
+
await writeFile(filePath, text);
|
|
5350
|
+
console.log(`Raw size of file: ${await rawSize(filePath)} bytes`);
|
|
5351
|
+
|
|
5352
|
+
// From URL
|
|
5353
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5354
|
+
console.log(`Raw size of URL: ${await rawSize(fileUrl)} bytes`);
|
|
5355
|
+
|
|
5356
|
+
// From Readable stream
|
|
5357
|
+
const stream = Readable.from(text);
|
|
5358
|
+
console.log(`Raw size of stream: ${await rawSize(stream)} bytes`);
|
|
5359
|
+
|
|
5360
|
+
await unlink(filePath); // Clean up temp file
|
|
5361
|
+
}
|
|
5362
|
+
|
|
5363
|
+
main().catch(console.error);
|
|
5364
|
+
```
|
|
5365
|
+
|
|
4039
5366
|
***
|
|
4040
5367
|
|
|
4041
5368
|
### rawSizeSync()
|
|
@@ -4044,27 +5371,102 @@ Uses memory-efficient streaming for large inputs.
|
|
|
4044
5371
|
function rawSizeSync(input): number;
|
|
4045
5372
|
```
|
|
4046
5373
|
|
|
4047
|
-
Defined in: [packages/fs/src/size.ts:
|
|
5374
|
+
Defined in: [packages/fs/src/size.ts:424](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/size.ts#L424)
|
|
4048
5375
|
|
|
4049
|
-
Synchronously
|
|
4050
|
-
|
|
5376
|
+
Synchronously calculates the raw (uncompressed) size of the given input.
|
|
5377
|
+
The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
5378
|
+
For file paths, it uses `statSync` to get the file size.
|
|
5379
|
+
Note: For Readable streams or very large files, consider using the asynchronous `rawSize` function for better performance and to avoid blocking.
|
|
4051
5380
|
|
|
4052
5381
|
#### Parameters
|
|
4053
5382
|
|
|
4054
5383
|
##### input
|
|
4055
5384
|
|
|
5385
|
+
The input data to measure.
|
|
5386
|
+
|
|
4056
5387
|
`string` | `URL` | `Buffer`\<`ArrayBufferLike`\>
|
|
4057
5388
|
|
|
4058
5389
|
#### Returns
|
|
4059
5390
|
|
|
4060
5391
|
`number`
|
|
5392
|
+
|
|
5393
|
+
The raw size in bytes.
|
|
5394
|
+
|
|
5395
|
+
#### Example
|
|
5396
|
+
|
|
5397
|
+
```javascript
|
|
5398
|
+
import { rawSizeSync } from "@visulima/fs";
|
|
5399
|
+
import { writeFileSync, unlinkSync } from "node:fs";
|
|
5400
|
+
import { join } from "node:path";
|
|
5401
|
+
|
|
5402
|
+
const text = "Hello, Synchronous World!";
|
|
5403
|
+
const filePath = join("temp-raw-sync-file.txt");
|
|
5404
|
+
|
|
5405
|
+
// From Buffer
|
|
5406
|
+
const buffer = Buffer.from(text);
|
|
5407
|
+
console.log(`Sync Raw size of buffer: ${rawSizeSync(buffer)} bytes`);
|
|
5408
|
+
|
|
5409
|
+
// From string (content)
|
|
5410
|
+
console.log(`Sync Raw size of string content: ${rawSizeSync(text)} bytes`);
|
|
5411
|
+
|
|
5412
|
+
// From file path
|
|
5413
|
+
try {
|
|
5414
|
+
writeFileSync(filePath, text);
|
|
5415
|
+
console.log(`Sync Raw size of file: ${rawSizeSync(filePath)} bytes`);
|
|
5416
|
+
|
|
5417
|
+
// From URL
|
|
5418
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5419
|
+
console.log(`Sync Raw size of URL: ${rawSizeSync(fileUrl)} bytes`);
|
|
5420
|
+
} finally {
|
|
5421
|
+
try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
5422
|
+
}
|
|
5423
|
+
```
|
|
4061
5424
|
# utils
|
|
4062
5425
|
|
|
4063
5426
|
## Classes
|
|
4064
5427
|
|
|
4065
5428
|
### JSONError
|
|
4066
5429
|
|
|
4067
|
-
Defined in: [packages/fs/src/error/json-error.ts:
|
|
5430
|
+
Defined in: [packages/fs/src/error/json-error.ts:39](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/json-error.ts#L39)
|
|
5431
|
+
|
|
5432
|
+
Custom error class for handling JSON parsing or related errors.
|
|
5433
|
+
It can optionally include a file name and a code frame for better debugging.
|
|
5434
|
+
|
|
5435
|
+
#### Example
|
|
5436
|
+
|
|
5437
|
+
```javascript
|
|
5438
|
+
import { JSONError } from "@visulima/fs/error";
|
|
5439
|
+
import { readJsonSync } from "@visulima/fs"; // Or any function that might throw this
|
|
5440
|
+
import { join } from "node:path";
|
|
5441
|
+
|
|
5442
|
+
try {
|
|
5443
|
+
// Imagine readJsonSync encounters a malformed JSON file and throws JSONError
|
|
5444
|
+
// Forcing the scenario for demonstration:
|
|
5445
|
+
const simulateJsonError = (filePath, content) => {
|
|
5446
|
+
const err = new JSONError(`Unexpected token '}' at position 15`);
|
|
5447
|
+
err.fileName = filePath;
|
|
5448
|
+
// A real implementation might generate a code frame using a library
|
|
5449
|
+
err.codeFrame = ` 13 | "key": "value",
|
|
5450
|
+
> 14 | "anotherKey": "anotherValue",}
|
|
5451
|
+
| ^
|
|
5452
|
+
15 | "lastKey": "end"
|
|
5453
|
+
`;
|
|
5454
|
+
throw err;
|
|
5455
|
+
};
|
|
5456
|
+
|
|
5457
|
+
simulateJsonError(join("path", "to", "corrupted.json"), '{ "key": "value", "anotherKey": "anotherValue",} ');
|
|
5458
|
+
// const jsonData = readJsonSync(join("path", "to", "corrupted.json"));
|
|
5459
|
+
} catch (error) {
|
|
5460
|
+
if (error instanceof JSONError) {
|
|
5461
|
+
console.error(`JSON Error: ${error.message}`);
|
|
5462
|
+
// message property will include fileName and codeFrame if they were set.
|
|
5463
|
+
// console.error(`File: ${error.fileName}`);
|
|
5464
|
+
// console.error(`Code Frame:\n${error.codeFrame}`);
|
|
5465
|
+
} else {
|
|
5466
|
+
console.error("An unexpected error occurred:", error);
|
|
5467
|
+
}
|
|
5468
|
+
}
|
|
5469
|
+
```
|
|
4068
5470
|
|
|
4069
5471
|
#### Extends
|
|
4070
5472
|
|
|
@@ -4078,7 +5480,9 @@ Defined in: [packages/fs/src/error/json-error.ts:1](https://github.com/visulima/
|
|
|
4078
5480
|
new JSONError(message): JSONError;
|
|
4079
5481
|
```
|
|
4080
5482
|
|
|
4081
|
-
Defined in: [packages/fs/src/error/json-error.ts:
|
|
5483
|
+
Defined in: [packages/fs/src/error/json-error.ts:53](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/json-error.ts#L53)
|
|
5484
|
+
|
|
5485
|
+
Creates a new JSONError instance.
|
|
4082
5486
|
|
|
4083
5487
|
###### Parameters
|
|
4084
5488
|
|
|
@@ -4086,6 +5490,8 @@ Defined in: [packages/fs/src/error/json-error.ts:11](https://github.com/visulima
|
|
|
4086
5490
|
|
|
4087
5491
|
`string`
|
|
4088
5492
|
|
|
5493
|
+
The primary error message.
|
|
5494
|
+
|
|
4089
5495
|
###### Returns
|
|
4090
5496
|
|
|
4091
5497
|
[`JSONError`](#jsonerror)
|
|
@@ -4106,7 +5512,7 @@ Error.constructor
|
|
|
4106
5512
|
get message(): string;
|
|
4107
5513
|
```
|
|
4108
5514
|
|
|
4109
|
-
Defined in: [packages/fs/src/error/json-error.ts:
|
|
5515
|
+
Defined in: [packages/fs/src/error/json-error.ts:63](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/json-error.ts#L63)
|
|
4110
5516
|
|
|
4111
5517
|
###### Returns
|
|
4112
5518
|
|
|
@@ -4118,7 +5524,7 @@ Defined in: [packages/fs/src/error/json-error.ts:21](https://github.com/visulima
|
|
|
4118
5524
|
set message(message): void;
|
|
4119
5525
|
```
|
|
4120
5526
|
|
|
4121
|
-
Defined in: [packages/fs/src/error/json-error.ts:
|
|
5527
|
+
Defined in: [packages/fs/src/error/json-error.ts:67](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/json-error.ts#L67)
|
|
4122
5528
|
|
|
4123
5529
|
###### Parameters
|
|
4124
5530
|
|
|
@@ -4190,7 +5596,7 @@ Error.cause
|
|
|
4190
5596
|
codeFrame: string;
|
|
4191
5597
|
```
|
|
4192
5598
|
|
|
4193
|
-
Defined in: [packages/fs/src/error/json-error.ts:
|
|
5599
|
+
Defined in: [packages/fs/src/error/json-error.ts:42](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/json-error.ts#L42)
|
|
4194
5600
|
|
|
4195
5601
|
##### fileName
|
|
4196
5602
|
|
|
@@ -4198,7 +5604,7 @@ Defined in: [packages/fs/src/error/json-error.ts:4](https://github.com/visulima/
|
|
|
4198
5604
|
fileName: string;
|
|
4199
5605
|
```
|
|
4200
5606
|
|
|
4201
|
-
Defined in: [packages/fs/src/error/json-error.ts:
|
|
5607
|
+
Defined in: [packages/fs/src/error/json-error.ts:40](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/json-error.ts#L40)
|
|
4202
5608
|
|
|
4203
5609
|
##### name
|
|
4204
5610
|
|
|
@@ -4206,7 +5612,7 @@ Defined in: [packages/fs/src/error/json-error.ts:2](https://github.com/visulima/
|
|
|
4206
5612
|
readonly name: "JSONError" = "JSONError";
|
|
4207
5613
|
```
|
|
4208
5614
|
|
|
4209
|
-
Defined in: [packages/fs/src/error/json-error.ts:
|
|
5615
|
+
Defined in: [packages/fs/src/error/json-error.ts:45](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/error/json-error.ts#L45)
|
|
4210
5616
|
|
|
4211
5617
|
###### Overrides
|
|
4212
5618
|
|
|
@@ -4284,7 +5690,10 @@ Error.stackTraceLimit
|
|
|
4284
5690
|
function assertValidFileContents(contents): void;
|
|
4285
5691
|
```
|
|
4286
5692
|
|
|
4287
|
-
Defined in: [packages/fs/src/utils/assert-valid-file-contents.ts:
|
|
5693
|
+
Defined in: [packages/fs/src/utils/assert-valid-file-contents.ts:28](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/utils/assert-valid-file-contents.ts#L28)
|
|
5694
|
+
|
|
5695
|
+
Asserts that the provided contents are valid for writing to a file.
|
|
5696
|
+
Valid contents can be a string, an ArrayBuffer, or an ArrayBuffer view (e.g., Uint8Array).
|
|
4288
5697
|
|
|
4289
5698
|
#### Parameters
|
|
4290
5699
|
|
|
@@ -4292,10 +5701,37 @@ Defined in: [packages/fs/src/utils/assert-valid-file-contents.ts:2](https://gith
|
|
|
4292
5701
|
|
|
4293
5702
|
`any`
|
|
4294
5703
|
|
|
5704
|
+
The file contents to validate.
|
|
5705
|
+
|
|
4295
5706
|
#### Returns
|
|
4296
5707
|
|
|
4297
5708
|
`void`
|
|
4298
5709
|
|
|
5710
|
+
#### Throws
|
|
5711
|
+
|
|
5712
|
+
If the contents are not a string, ArrayBuffer, or ArrayBuffer view.
|
|
5713
|
+
|
|
5714
|
+
#### Example
|
|
5715
|
+
|
|
5716
|
+
```javascript
|
|
5717
|
+
import { assertValidFileContents } from "@visulima/fs"; // Assuming this util is exported
|
|
5718
|
+
|
|
5719
|
+
try {
|
|
5720
|
+
assertValidFileContents("Hello, world!");
|
|
5721
|
+
assertValidFileContents(new Uint8Array([72, 101, 108, 108, 111])); // "Hello"
|
|
5722
|
+
assertValidFileContents(new ArrayBuffer(8));
|
|
5723
|
+
console.log("File contents are valid.");
|
|
5724
|
+
} catch (error) {
|
|
5725
|
+
console.error(error.message); // File contents must be a string, ArrayBuffer, or ArrayBuffer view.
|
|
5726
|
+
}
|
|
5727
|
+
|
|
5728
|
+
try {
|
|
5729
|
+
assertValidFileContents(123); // Invalid content type
|
|
5730
|
+
} catch (error) {
|
|
5731
|
+
console.error(error.message); // File contents must be a string, ArrayBuffer, or ArrayBuffer view.
|
|
5732
|
+
}
|
|
5733
|
+
```
|
|
5734
|
+
|
|
4299
5735
|
***
|
|
4300
5736
|
|
|
4301
5737
|
### assertValidFileOrDirectoryPath()
|
|
@@ -4304,7 +5740,10 @@ Defined in: [packages/fs/src/utils/assert-valid-file-contents.ts:2](https://gith
|
|
|
4304
5740
|
function assertValidFileOrDirectoryPath(fileOrDirectoryPath): void;
|
|
4305
5741
|
```
|
|
4306
5742
|
|
|
4307
|
-
Defined in: [packages/fs/src/utils/assert-valid-file-or-directory-path.ts:
|
|
5743
|
+
Defined in: [packages/fs/src/utils/assert-valid-file-or-directory-path.ts:27](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/utils/assert-valid-file-or-directory-path.ts#L27)
|
|
5744
|
+
|
|
5745
|
+
Asserts that the provided path is a valid file or directory path.
|
|
5746
|
+
A valid path must be a non-empty string or a URL instance.
|
|
4308
5747
|
|
|
4309
5748
|
#### Parameters
|
|
4310
5749
|
|
|
@@ -4312,14 +5751,110 @@ Defined in: [packages/fs/src/utils/assert-valid-file-or-directory-path.ts:2](htt
|
|
|
4312
5751
|
|
|
4313
5752
|
`any`
|
|
4314
5753
|
|
|
5754
|
+
The path to validate.
|
|
5755
|
+
|
|
4315
5756
|
#### Returns
|
|
4316
5757
|
|
|
4317
5758
|
`void`
|
|
4318
5759
|
|
|
5760
|
+
#### Throws
|
|
5761
|
+
|
|
5762
|
+
If the path is not a non-empty string or a URL.
|
|
5763
|
+
|
|
5764
|
+
#### Example
|
|
5765
|
+
|
|
5766
|
+
```javascript
|
|
5767
|
+
import { assertValidFileOrDirectoryPath } from "@visulima/fs"; // Assuming this util is exported
|
|
5768
|
+
|
|
5769
|
+
try {
|
|
5770
|
+
assertValidFileOrDirectoryPath("/path/to/file.txt");
|
|
5771
|
+
assertValidFileOrDirectoryPath(new URL("file:///path/to/file.txt"));
|
|
5772
|
+
console.log("Path is valid.");
|
|
5773
|
+
} catch (error) {
|
|
5774
|
+
console.error(error.message); // Path must be a non-empty string or URL.
|
|
5775
|
+
}
|
|
5776
|
+
|
|
5777
|
+
try {
|
|
5778
|
+
assertValidFileOrDirectoryPath(""); // Invalid path
|
|
5779
|
+
} catch (error) {
|
|
5780
|
+
console.error(error.message); // Path must be a non-empty string or URL.
|
|
5781
|
+
}
|
|
5782
|
+
```
|
|
5783
|
+
|
|
4319
5784
|
***
|
|
4320
5785
|
|
|
4321
5786
|
### parseJson()
|
|
4322
5787
|
|
|
5788
|
+
Parses a JSON string, constructing the JavaScript value or object described by the string.
|
|
5789
|
+
This is a modified version of `parse-json` from `https://github.com/sindresorhus/parse-json/blob/main/index.js`.
|
|
5790
|
+
It provides more detailed error messages including code frames.
|
|
5791
|
+
|
|
5792
|
+
#### Template
|
|
5793
|
+
|
|
5794
|
+
The type of the parsed JSON value.
|
|
5795
|
+
|
|
5796
|
+
#### Param
|
|
5797
|
+
|
|
5798
|
+
The JSON string to parse.
|
|
5799
|
+
|
|
5800
|
+
#### Param
|
|
5801
|
+
|
|
5802
|
+
An optional reviver function that can transform the results, or a filename string if no reviver is used.
|
|
5803
|
+
|
|
5804
|
+
#### Param
|
|
5805
|
+
|
|
5806
|
+
An optional filename string (if reviver is provided), or CodeFrameOptions (if reviver is not provided and this is the third argument).
|
|
5807
|
+
|
|
5808
|
+
#### Param
|
|
5809
|
+
|
|
5810
|
+
Optional options for generating the code frame on error.
|
|
5811
|
+
|
|
5812
|
+
#### Throws
|
|
5813
|
+
|
|
5814
|
+
If the string to parse is not valid JSON, or if any other parsing error occurs.
|
|
5815
|
+
|
|
5816
|
+
#### Example
|
|
5817
|
+
|
|
5818
|
+
```javascript
|
|
5819
|
+
import { parseJson } from "@visulima/fs"; // Assuming this util is exported or re-exported
|
|
5820
|
+
|
|
5821
|
+
const jsonString = '{"name": "John Doe", "age": 30, "city": "New York"}';
|
|
5822
|
+
const malformedJson = '{"name": "Jane Doe", "age": "thirty}'; // Missing quote
|
|
5823
|
+
|
|
5824
|
+
try {
|
|
5825
|
+
const data = parseJson(jsonString);
|
|
5826
|
+
console.log(data.name); // Output: John Doe
|
|
5827
|
+
|
|
5828
|
+
const dataWithReviver = parseJson(jsonString, (key, value) => {
|
|
5829
|
+
if (key === "age") {
|
|
5830
|
+
return value + 5;
|
|
5831
|
+
}
|
|
5832
|
+
return value;
|
|
5833
|
+
});
|
|
5834
|
+
console.log(dataWithReviver.age); // Output: 35
|
|
5835
|
+
|
|
5836
|
+
// With filename for better error reporting
|
|
5837
|
+
const user = parseJson(malformedJson, "user-data.json");
|
|
5838
|
+
|
|
5839
|
+
} catch (error) {
|
|
5840
|
+
// error will be an instance of JsonError
|
|
5841
|
+
console.error(error.message);
|
|
5842
|
+
// Example error message:
|
|
5843
|
+
// Unexpected token } in JSON at position 37 in user-data.json
|
|
5844
|
+
//
|
|
5845
|
+
// 35 | "name": "Jane Doe",
|
|
5846
|
+
// > 36 | "age": "thirty}
|
|
5847
|
+
// | ^
|
|
5848
|
+
// 37 |
|
|
5849
|
+
if (error.fileName) {
|
|
5850
|
+
console.error(`Error in file: ${error.fileName}`);
|
|
5851
|
+
}
|
|
5852
|
+
if (error.codeFrame) {
|
|
5853
|
+
console.error(error.codeFrame);
|
|
5854
|
+
}
|
|
5855
|
+
}
|
|
5856
|
+
```
|
|
5857
|
+
|
|
4323
5858
|
#### Call Signature
|
|
4324
5859
|
|
|
4325
5860
|
```ts
|
|
@@ -4329,7 +5864,7 @@ function parseJson<T>(
|
|
|
4329
5864
|
options?): T;
|
|
4330
5865
|
```
|
|
4331
5866
|
|
|
4332
|
-
Defined in: [packages/fs/src/utils/parse-json.ts:60](https://github.com/visulima/visulima/blob/
|
|
5867
|
+
Defined in: [packages/fs/src/utils/parse-json.ts:60](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/utils/parse-json.ts#L60)
|
|
4333
5868
|
|
|
4334
5869
|
##### Type Parameters
|
|
4335
5870
|
|
|
@@ -4349,7 +5884,7 @@ Defined in: [packages/fs/src/utils/parse-json.ts:60](https://github.com/visulima
|
|
|
4349
5884
|
|
|
4350
5885
|
###### options?
|
|
4351
5886
|
|
|
4352
|
-
`CodeFrameOptions`
|
|
5887
|
+
[`CodeFrameOptions`](index.md#codeframeoptions)
|
|
4353
5888
|
|
|
4354
5889
|
##### Returns
|
|
4355
5890
|
|
|
@@ -4365,7 +5900,7 @@ function parseJson<T>(
|
|
|
4365
5900
|
options?): T;
|
|
4366
5901
|
```
|
|
4367
5902
|
|
|
4368
|
-
Defined in: [packages/fs/src/utils/parse-json.ts:61](https://github.com/visulima/visulima/blob/
|
|
5903
|
+
Defined in: [packages/fs/src/utils/parse-json.ts:61](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/utils/parse-json.ts#L61)
|
|
4369
5904
|
|
|
4370
5905
|
##### Type Parameters
|
|
4371
5906
|
|
|
@@ -4389,7 +5924,7 @@ Defined in: [packages/fs/src/utils/parse-json.ts:61](https://github.com/visulima
|
|
|
4389
5924
|
|
|
4390
5925
|
###### options?
|
|
4391
5926
|
|
|
4392
|
-
`CodeFrameOptions`
|
|
5927
|
+
[`CodeFrameOptions`](index.md#codeframeoptions)
|
|
4393
5928
|
|
|
4394
5929
|
##### Returns
|
|
4395
5930
|
|
|
@@ -4400,10 +5935,13 @@ Defined in: [packages/fs/src/utils/parse-json.ts:61](https://github.com/visulima
|
|
|
4400
5935
|
### stripJsonComments()
|
|
4401
5936
|
|
|
4402
5937
|
```ts
|
|
4403
|
-
function stripJsonComments(jsonString,
|
|
5938
|
+
function stripJsonComments(jsonString, options?): string;
|
|
4404
5939
|
```
|
|
4405
5940
|
|
|
4406
|
-
Defined in: [packages/fs/src/utils/strip-json-comments.ts:
|
|
5941
|
+
Defined in: [packages/fs/src/utils/strip-json-comments.ts:46](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/utils/strip-json-comments.ts#L46)
|
|
5942
|
+
|
|
5943
|
+
Strips comments from a JSON string.
|
|
5944
|
+
Handles both single-line (//) and multi-line (/* ... */) comments.
|
|
4407
5945
|
|
|
4408
5946
|
#### Parameters
|
|
4409
5947
|
|
|
@@ -4411,16 +5949,58 @@ Defined in: [packages/fs/src/utils/strip-json-comments.ts:5](https://github.com/
|
|
|
4411
5949
|
|
|
4412
5950
|
`string`
|
|
4413
5951
|
|
|
4414
|
-
|
|
5952
|
+
The JSON string possibly containing comments.
|
|
5953
|
+
|
|
5954
|
+
##### options?
|
|
5955
|
+
|
|
5956
|
+
Optional configuration for stripping comments.
|
|
4415
5957
|
|
|
4416
5958
|
###### whitespace?
|
|
4417
5959
|
|
|
4418
5960
|
`boolean` = `true`
|
|
4419
5961
|
|
|
5962
|
+
If `true` (default), comments are replaced with whitespace to preserve line numbers and character positions. If `false`, comments are removed entirely.
|
|
5963
|
+
|
|
4420
5964
|
#### Returns
|
|
4421
5965
|
|
|
4422
5966
|
`string`
|
|
4423
5967
|
|
|
5968
|
+
The JSON string with comments stripped.
|
|
5969
|
+
|
|
5970
|
+
#### Example
|
|
5971
|
+
|
|
5972
|
+
```javascript
|
|
5973
|
+
import { stripJsonComments } from "@visulima/fs"; // Assuming this util is exported
|
|
5974
|
+
|
|
5975
|
+
const jsonWithComments = `{
|
|
5976
|
+
// This is a single-line comment
|
|
5977
|
+
"name": "John Doe",
|
|
5978
|
+
"age": 30, /* This is a
|
|
5979
|
+
multi-line comment */
|
|
5980
|
+
"city": "New York"
|
|
5981
|
+
}`;
|
|
5982
|
+
|
|
5983
|
+
const stripped = stripJsonComments(jsonWithComments);
|
|
5984
|
+
console.log(stripped);
|
|
5985
|
+
// Output (with whitespace=true):
|
|
5986
|
+
// {
|
|
5987
|
+
//
|
|
5988
|
+
// "name": "John Doe",
|
|
5989
|
+
// "age": 30, /*
|
|
5990
|
+
//
|
|
5991
|
+
// "city": "New York"
|
|
5992
|
+
// }
|
|
5993
|
+
|
|
5994
|
+
const strippedWithoutWhitespace = stripJsonComments(jsonWithComments, { whitespace: false });
|
|
5995
|
+
console.log(strippedWithoutWhitespace);
|
|
5996
|
+
// Output (with whitespace=false):
|
|
5997
|
+
// {
|
|
5998
|
+
// "name": "John Doe",
|
|
5999
|
+
// "age": 30,
|
|
6000
|
+
// "city": "New York"
|
|
6001
|
+
// }
|
|
6002
|
+
```
|
|
6003
|
+
|
|
4424
6004
|
## Variables
|
|
4425
6005
|
|
|
4426
6006
|
### toPath()
|
|
@@ -4429,7 +6009,7 @@ Defined in: [packages/fs/src/utils/strip-json-comments.ts:5](https://github.com/
|
|
|
4429
6009
|
const toPath: (urlOrPath) => string;
|
|
4430
6010
|
```
|
|
4431
6011
|
|
|
4432
|
-
Defined in: node\_modules/.pnpm/@visulima+path@1.3.
|
|
6012
|
+
Defined in: node\_modules/.pnpm/@visulima+path@1.3.6/node\_modules/@visulima/path/dist/utils.d.mts:7
|
|
4433
6013
|
|
|
4434
6014
|
#### Parameters
|
|
4435
6015
|
|
|
@@ -4446,13 +6026,62 @@ Defined in: node\_modules/.pnpm/@visulima+path@1.3.5/node\_modules/@visulima/pat
|
|
|
4446
6026
|
|
|
4447
6027
|
### readYaml()
|
|
4448
6028
|
|
|
6029
|
+
Asynchronously reads a YAML file and then parses it into an object.
|
|
6030
|
+
|
|
6031
|
+
#### Template
|
|
6032
|
+
|
|
6033
|
+
The expected type of the parsed YAML object. Defaults to `Record<string, unknown>`.
|
|
6034
|
+
|
|
6035
|
+
#### Param
|
|
6036
|
+
|
|
6037
|
+
The path to the YAML file to read. Can be a file URL or a string path.
|
|
6038
|
+
|
|
6039
|
+
#### Param
|
|
6040
|
+
|
|
6041
|
+
An optional reviver function (similar to `JSON.parse` reviver) or the options object.
|
|
6042
|
+
|
|
6043
|
+
#### Param
|
|
6044
|
+
|
|
6045
|
+
Optional configuration for reading and parsing the YAML file. See ReadYamlOptions.
|
|
6046
|
+
If `reviver` is an object, this argument is ignored.
|
|
6047
|
+
|
|
6048
|
+
#### Example
|
|
6049
|
+
|
|
6050
|
+
```javascript
|
|
6051
|
+
import { readYaml } from "@visulima/fs";
|
|
6052
|
+
import { join } from "node:path";
|
|
6053
|
+
|
|
6054
|
+
const readMyYaml = async () => {
|
|
6055
|
+
try {
|
|
6056
|
+
const data = await readYaml(join("path", "to", "my-config.yaml"));
|
|
6057
|
+
console.log("Config data:", data);
|
|
6058
|
+
|
|
6059
|
+
// With a reviver function
|
|
6060
|
+
const dataWithReviver = await readYaml(join("path", "to", "another.yaml"), (key, value) => {
|
|
6061
|
+
if (key === "date") return new Date(value);
|
|
6062
|
+
return value;
|
|
6063
|
+
});
|
|
6064
|
+
console.log("Date field is now a Date object:", dataWithReviver.date);
|
|
6065
|
+
|
|
6066
|
+
// With options (e.g., for schema validation - assuming yaml options are passed correctly)
|
|
6067
|
+
// const dataWithOptions = await readYaml(join("path", "to", "options.yaml"), { schema: 'failsafe' });
|
|
6068
|
+
// console.log(dataWithOptions);
|
|
6069
|
+
|
|
6070
|
+
} catch (error) {
|
|
6071
|
+
console.error("Failed to read or parse YAML file:", error);
|
|
6072
|
+
}
|
|
6073
|
+
};
|
|
6074
|
+
|
|
6075
|
+
readMyYaml();
|
|
6076
|
+
```
|
|
6077
|
+
|
|
4449
6078
|
#### Call Signature
|
|
4450
6079
|
|
|
4451
6080
|
```ts
|
|
4452
6081
|
function readYaml<R>(path, options?): Promise<R>;
|
|
4453
6082
|
```
|
|
4454
6083
|
|
|
4455
|
-
Defined in: [packages/fs/src/read/read-yaml.ts:6](https://github.com/visulima/visulima/blob/
|
|
6084
|
+
Defined in: [packages/fs/src/read/read-yaml.ts:6](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/read/read-yaml.ts#L6)
|
|
4456
6085
|
|
|
4457
6086
|
##### Type Parameters
|
|
4458
6087
|
|
|
@@ -4483,7 +6112,7 @@ function readYaml<R>(
|
|
|
4483
6112
|
options?): Promise<R>;
|
|
4484
6113
|
```
|
|
4485
6114
|
|
|
4486
|
-
Defined in: [packages/fs/src/read/read-yaml.ts:7](https://github.com/visulima/visulima/blob/
|
|
6115
|
+
Defined in: [packages/fs/src/read/read-yaml.ts:7](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/read/read-yaml.ts#L7)
|
|
4487
6116
|
|
|
4488
6117
|
##### Type Parameters
|
|
4489
6118
|
|
|
@@ -4513,13 +6142,58 @@ Defined in: [packages/fs/src/read/read-yaml.ts:7](https://github.com/visulima/vi
|
|
|
4513
6142
|
|
|
4514
6143
|
### readYamlSync()
|
|
4515
6144
|
|
|
6145
|
+
Synchronously reads a YAML file and then parses it into an object.
|
|
6146
|
+
|
|
6147
|
+
#### Template
|
|
6148
|
+
|
|
6149
|
+
The expected type of the parsed YAML object. Defaults to `Record<string, unknown>`.
|
|
6150
|
+
|
|
6151
|
+
#### Param
|
|
6152
|
+
|
|
6153
|
+
The path to the YAML file to read. Can be a file URL or a string path.
|
|
6154
|
+
|
|
6155
|
+
#### Param
|
|
6156
|
+
|
|
6157
|
+
An optional reviver function (similar to `JSON.parse` reviver) or the options object.
|
|
6158
|
+
|
|
6159
|
+
#### Param
|
|
6160
|
+
|
|
6161
|
+
Optional configuration for reading and parsing the YAML file. See ReadYamlOptions.
|
|
6162
|
+
If `reviver` is an object, this argument is ignored.
|
|
6163
|
+
|
|
6164
|
+
#### Example
|
|
6165
|
+
|
|
6166
|
+
```javascript
|
|
6167
|
+
import { readYamlSync } from "@visulima/fs";
|
|
6168
|
+
import { join } from "node:path";
|
|
6169
|
+
|
|
6170
|
+
try {
|
|
6171
|
+
const data = readYamlSync(join("path", "to", "my-config.yaml"));
|
|
6172
|
+
console.log("Config data:", data);
|
|
6173
|
+
|
|
6174
|
+
// With a reviver function
|
|
6175
|
+
const dataWithReviver = readYamlSync(join("path", "to", "another.yaml"), (key, value) => {
|
|
6176
|
+
if (key === "date") return new Date(value);
|
|
6177
|
+
return value;
|
|
6178
|
+
});
|
|
6179
|
+
console.log("Date field is now a Date object:", dataWithReviver.date);
|
|
6180
|
+
|
|
6181
|
+
// With options (e.g., for schema validation - assuming yaml options are passed correctly)
|
|
6182
|
+
// const dataWithOptions = readYamlSync(join("path", "to", "options.yaml"), { schema: 'failsafe' });
|
|
6183
|
+
// console.log(dataWithOptions);
|
|
6184
|
+
|
|
6185
|
+
} catch (error) {
|
|
6186
|
+
console.error("Failed to read or parse YAML file:", error);
|
|
6187
|
+
}
|
|
6188
|
+
```
|
|
6189
|
+
|
|
4516
6190
|
#### Call Signature
|
|
4517
6191
|
|
|
4518
6192
|
```ts
|
|
4519
6193
|
function readYamlSync<R>(path, options?): R;
|
|
4520
6194
|
```
|
|
4521
6195
|
|
|
4522
|
-
Defined in: [packages/fs/src/read/read-yaml-sync.ts:6](https://github.com/visulima/visulima/blob/
|
|
6196
|
+
Defined in: [packages/fs/src/read/read-yaml-sync.ts:6](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/read/read-yaml-sync.ts#L6)
|
|
4523
6197
|
|
|
4524
6198
|
##### Type Parameters
|
|
4525
6199
|
|
|
@@ -4550,7 +6224,7 @@ function readYamlSync<R>(
|
|
|
4550
6224
|
options?): R;
|
|
4551
6225
|
```
|
|
4552
6226
|
|
|
4553
|
-
Defined in: [packages/fs/src/read/read-yaml-sync.ts:7](https://github.com/visulima/visulima/blob/
|
|
6227
|
+
Defined in: [packages/fs/src/read/read-yaml-sync.ts:7](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/read/read-yaml-sync.ts#L7)
|
|
4554
6228
|
|
|
4555
6229
|
##### Type Parameters
|
|
4556
6230
|
|
|
@@ -4580,6 +6254,52 @@ Defined in: [packages/fs/src/read/read-yaml-sync.ts:7](https://github.com/visuli
|
|
|
4580
6254
|
|
|
4581
6255
|
### writeYaml()
|
|
4582
6256
|
|
|
6257
|
+
Asynchronously writes an object to a YAML file.
|
|
6258
|
+
|
|
6259
|
+
#### Param
|
|
6260
|
+
|
|
6261
|
+
The path to the YAML file to write. Can be a file URL or a string path.
|
|
6262
|
+
|
|
6263
|
+
#### Param
|
|
6264
|
+
|
|
6265
|
+
The data to serialize and write. Can be any JavaScript value that can be stringified by `yaml.stringify`.
|
|
6266
|
+
|
|
6267
|
+
#### Param
|
|
6268
|
+
|
|
6269
|
+
Optional. A replacer function or an array of keys to include, or the options object itself.
|
|
6270
|
+
See `yaml.stringify` documentation for more details.
|
|
6271
|
+
|
|
6272
|
+
#### Param
|
|
6273
|
+
|
|
6274
|
+
Optional. Configuration for writing and stringifying the YAML file. See WriteYamlOptions.
|
|
6275
|
+
If `replacer` is an object and not a function/array, it's treated as `options`.
|
|
6276
|
+
The `space` property within options can be a number for spaces or a string for tabs/etc.
|
|
6277
|
+
|
|
6278
|
+
#### Example
|
|
6279
|
+
|
|
6280
|
+
```javascript
|
|
6281
|
+
import { writeYaml } from "@visulima/fs";
|
|
6282
|
+
import { join } from "node:path";
|
|
6283
|
+
|
|
6284
|
+
const writeMyYaml = async () => {
|
|
6285
|
+
try {
|
|
6286
|
+
await writeYaml(join("/tmp", "my-data.yaml"), { name: "John Doe", age: 30, city: "New York" });
|
|
6287
|
+
console.log("YAML file written successfully.");
|
|
6288
|
+
|
|
6289
|
+
await writeYaml(join("/tmp", "another-data.yaml"), { user: "jane", details: { id: 1, status: "active" } }, null, 2);
|
|
6290
|
+
console.log("Another YAML file written with 2 spaces indentation.");
|
|
6291
|
+
|
|
6292
|
+
const customReplacer = (key, value) => (key === "age" ? undefined : value);
|
|
6293
|
+
await writeYaml(join("/tmp", "filtered-data.yaml"), { name: "Smith", age: 45, occupation: "Engineer" }, customReplacer, { space: '\t' });
|
|
6294
|
+
console.log("Filtered YAML file written with tab indentation.");
|
|
6295
|
+
} catch (error) {
|
|
6296
|
+
console.error("Failed to write YAML file:", error);
|
|
6297
|
+
}
|
|
6298
|
+
};
|
|
6299
|
+
|
|
6300
|
+
writeMyYaml();
|
|
6301
|
+
```
|
|
6302
|
+
|
|
4583
6303
|
#### Call Signature
|
|
4584
6304
|
|
|
4585
6305
|
```ts
|
|
@@ -4589,7 +6309,7 @@ function writeYaml(
|
|
|
4589
6309
|
options?): Promise<void>;
|
|
4590
6310
|
```
|
|
4591
6311
|
|
|
4592
|
-
Defined in: [packages/fs/src/write/write-yaml.ts:
|
|
6312
|
+
Defined in: [packages/fs/src/write/write-yaml.ts:6](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/write/write-yaml.ts#L6)
|
|
4593
6313
|
|
|
4594
6314
|
##### Parameters
|
|
4595
6315
|
|
|
@@ -4603,7 +6323,7 @@ Defined in: [packages/fs/src/write/write-yaml.ts:10](https://github.com/visulima
|
|
|
4603
6323
|
|
|
4604
6324
|
###### options?
|
|
4605
6325
|
|
|
4606
|
-
`
|
|
6326
|
+
`WriteYamlOptions`
|
|
4607
6327
|
|
|
4608
6328
|
##### Returns
|
|
4609
6329
|
|
|
@@ -4619,7 +6339,7 @@ function writeYaml(
|
|
|
4619
6339
|
options?): Promise<void>;
|
|
4620
6340
|
```
|
|
4621
6341
|
|
|
4622
|
-
Defined in: [packages/fs/src/write/write-yaml.ts:
|
|
6342
|
+
Defined in: [packages/fs/src/write/write-yaml.ts:12](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/write/write-yaml.ts#L12)
|
|
4623
6343
|
|
|
4624
6344
|
##### Parameters
|
|
4625
6345
|
|
|
@@ -4637,7 +6357,7 @@ Defined in: [packages/fs/src/write/write-yaml.ts:16](https://github.com/visulima
|
|
|
4637
6357
|
|
|
4638
6358
|
###### options?
|
|
4639
6359
|
|
|
4640
|
-
`string` | `number` | `
|
|
6360
|
+
`string` | `number` | `WriteYamlOptions`
|
|
4641
6361
|
|
|
4642
6362
|
##### Returns
|
|
4643
6363
|
|
|
@@ -4647,6 +6367,52 @@ Defined in: [packages/fs/src/write/write-yaml.ts:16](https://github.com/visulima
|
|
|
4647
6367
|
|
|
4648
6368
|
### writeYamlSync()
|
|
4649
6369
|
|
|
6370
|
+
Synchronously writes an object to a YAML file.
|
|
6371
|
+
|
|
6372
|
+
#### Param
|
|
6373
|
+
|
|
6374
|
+
The path to the YAML file to write. Can be a file URL or a string path.
|
|
6375
|
+
|
|
6376
|
+
#### Param
|
|
6377
|
+
|
|
6378
|
+
The data to serialize and write. Can be any JavaScript value that can be stringified by `yaml.stringify`.
|
|
6379
|
+
|
|
6380
|
+
#### Param
|
|
6381
|
+
|
|
6382
|
+
Optional. A replacer function or an array of keys to include, or the options object itself.
|
|
6383
|
+
See `yaml.stringify` documentation for more details.
|
|
6384
|
+
|
|
6385
|
+
#### Param
|
|
6386
|
+
|
|
6387
|
+
Optional. Configuration for writing and stringifying the YAML file. See WriteYamlOptions.
|
|
6388
|
+
If `replacer` is an object and not a function/array, it's treated as `options`.
|
|
6389
|
+
The `space` property within options can be a number for spaces or a string for tabs/etc.
|
|
6390
|
+
|
|
6391
|
+
#### Example
|
|
6392
|
+
|
|
6393
|
+
```javascript
|
|
6394
|
+
import { writeYamlSync } from "@visulima/fs";
|
|
6395
|
+
import { join } from "node:path";
|
|
6396
|
+
|
|
6397
|
+
const writeMyYamlSync = () => {
|
|
6398
|
+
try {
|
|
6399
|
+
writeYamlSync(join("/tmp", "my-data-sync.yaml"), { name: "Jane Doe", age: 28, city: "London" });
|
|
6400
|
+
console.log("YAML file written successfully (sync).");
|
|
6401
|
+
|
|
6402
|
+
writeYamlSync(join("/tmp", "another-data-sync.yaml"), { user: "john_sync", details: { id: 2, status: "inactive" } }, null, 4);
|
|
6403
|
+
console.log("Another YAML file written with 4 spaces indentation (sync).");
|
|
6404
|
+
|
|
6405
|
+
const customReplacer = (key, value) => (key === "city" ? "REDACTED" : value);
|
|
6406
|
+
writeYamlSync(join("/tmp", "filtered-data-sync.yaml"), { name: "Peter", age: 50, city: "Paris" }, customReplacer, { space: 2 });
|
|
6407
|
+
console.log("Filtered YAML file written with 2 spaces indentation (sync).");
|
|
6408
|
+
} catch (error) {
|
|
6409
|
+
console.error("Failed to write YAML file (sync):", error);
|
|
6410
|
+
}
|
|
6411
|
+
};
|
|
6412
|
+
|
|
6413
|
+
writeMyYamlSync();
|
|
6414
|
+
```
|
|
6415
|
+
|
|
4650
6416
|
#### Call Signature
|
|
4651
6417
|
|
|
4652
6418
|
```ts
|
|
@@ -4656,7 +6422,7 @@ function writeYamlSync(
|
|
|
4656
6422
|
options?): void;
|
|
4657
6423
|
```
|
|
4658
6424
|
|
|
4659
|
-
Defined in: [packages/fs/src/write/write-yaml-sync.ts:
|
|
6425
|
+
Defined in: [packages/fs/src/write/write-yaml-sync.ts:6](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/write/write-yaml-sync.ts#L6)
|
|
4660
6426
|
|
|
4661
6427
|
##### Parameters
|
|
4662
6428
|
|
|
@@ -4670,7 +6436,7 @@ Defined in: [packages/fs/src/write/write-yaml-sync.ts:10](https://github.com/vis
|
|
|
4670
6436
|
|
|
4671
6437
|
###### options?
|
|
4672
6438
|
|
|
4673
|
-
`
|
|
6439
|
+
`WriteYamlOptions`
|
|
4674
6440
|
|
|
4675
6441
|
##### Returns
|
|
4676
6442
|
|
|
@@ -4686,7 +6452,7 @@ function writeYamlSync(
|
|
|
4686
6452
|
options?): void;
|
|
4687
6453
|
```
|
|
4688
6454
|
|
|
4689
|
-
Defined in: [packages/fs/src/write/write-yaml-sync.ts:
|
|
6455
|
+
Defined in: [packages/fs/src/write/write-yaml-sync.ts:12](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/write/write-yaml-sync.ts#L12)
|
|
4690
6456
|
|
|
4691
6457
|
##### Parameters
|
|
4692
6458
|
|
|
@@ -4704,7 +6470,7 @@ Defined in: [packages/fs/src/write/write-yaml-sync.ts:16](https://github.com/vis
|
|
|
4704
6470
|
|
|
4705
6471
|
###### options?
|
|
4706
6472
|
|
|
4707
|
-
`string` | `number` | `
|
|
6473
|
+
`string` | `number` | `WriteYamlOptions`
|
|
4708
6474
|
|
|
4709
6475
|
##### Returns
|
|
4710
6476
|
|
|
@@ -4718,7 +6484,9 @@ Defined in: [packages/fs/src/write/write-yaml-sync.ts:16](https://github.com/vis
|
|
|
4718
6484
|
type YamlReplacer = JsonReplacer;
|
|
4719
6485
|
```
|
|
4720
6486
|
|
|
4721
|
-
Defined in: [packages/fs/src/types.ts:
|
|
6487
|
+
Defined in: [packages/fs/src/types.ts:202](https://github.com/visulima/visulima/blob/4efd46a27f16688d6c78a6c8b189adf3275047d9/packages/fs/src/types.ts#L202)
|
|
6488
|
+
|
|
6489
|
+
Type for the `replacer` parameter used in YAML serialization, similar to `JSON.stringify`'s replacer.
|
|
4722
6490
|
|
|
4723
6491
|
<!-- /TYPEDOC -->
|
|
4724
6492
|
|