@visulima/fs 3.1.9 → 4.0.1
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 +43 -0
- package/LICENSE.md +51 -122
- package/README.md +929 -982
- package/dist/eol.js +3 -0
- package/dist/error.js +1 -0
- package/dist/index.d.ts +51 -4
- package/dist/index.js +1 -0
- package/dist/packem_shared/F_OK-CAwY1qU7.js +1 -0
- package/dist/packem_shared/JSONError-D7h6PNWc.js +4 -0
- package/dist/packem_shared/collect-DO31RsLs.js +1 -0
- package/dist/packem_shared/collectSync-Cy7ULmjZ.js +1 -0
- package/dist/packem_shared/emptyDir-zBLHyPsJ.js +1 -0
- package/dist/packem_shared/emptyDirSync-DZ8nTo6g.js +1 -0
- package/dist/packem_shared/ensureDir-CwcwvbZ0.js +1 -0
- package/dist/packem_shared/ensureDirSync-DsFhH5oQ.js +1 -0
- package/dist/packem_shared/ensureFile-DwcEQVDX.js +1 -0
- package/dist/packem_shared/ensureFileSync-KnrH51Ox.js +1 -0
- package/dist/packem_shared/ensureLink-5rjQGEBb.js +1 -0
- package/dist/packem_shared/ensureLinkSync-CYXpscf2.js +1 -0
- package/dist/packem_shared/ensureSymlink-BMLtwpf2.js +1 -0
- package/dist/packem_shared/ensureSymlinkSync-CyAnZg8r.js +1 -0
- package/dist/packem_shared/findUp-Di7Az07S.js +1 -0
- package/dist/packem_shared/findUpSync-iV97v14Q.js +1 -0
- package/dist/packem_shared/index-CYIVJA0W.js +1 -0
- package/dist/packem_shared/isAccessible-CDFxsAAo.js +1 -0
- package/dist/packem_shared/isAccessibleSync-5nzZWgin.js +1 -0
- package/dist/packem_shared/isFsCaseSensitive-Drl8fHLV.js +1 -0
- package/dist/packem_shared/move-Bz4gSIjp.js +1 -0
- package/dist/packem_shared/{parseJson-BEnYqLIc.mjs → parseJson-Cj4v3qzl.js} +1 -1
- package/dist/packem_shared/readFile-CbxFM_zp.js +1 -0
- package/dist/packem_shared/readFileSync-B9iv2Sb8.js +1 -0
- package/dist/packem_shared/readJson-BgC3msx-.js +1 -0
- package/dist/packem_shared/readJsonSync-DHO1vjAG.js +1 -0
- package/dist/packem_shared/readYaml-C8QlsEFe.js +1 -0
- package/dist/packem_shared/readYamlSync-BIuoBHUt.js +1 -0
- package/dist/packem_shared/remove-BUqZUj1W.js +1 -0
- package/dist/packem_shared/removeSync-BbT4vmDi.js +1 -0
- package/dist/packem_shared/stripJsonComments-DbMjL4qv.js +1 -0
- package/dist/packem_shared/{types-XsSUZ9oS.d.mts → types-T308NKwz.d.ts} +2 -1
- package/dist/packem_shared/walk-ZrZngpc4.js +1 -0
- package/dist/packem_shared/walk-include-DCiVAwMP.js +1 -0
- package/dist/packem_shared/walkSync-BQa4NKSG.js +1 -0
- package/dist/packem_shared/writeFile-D5OYEMHu.js +1 -0
- package/dist/packem_shared/writeFileSync-CO4ySqUn.js +1 -0
- package/dist/packem_shared/writeJson-DfmgiY_s.js +4 -0
- package/dist/packem_shared/writeJsonSync-Ck1pmmj_.js +4 -0
- package/dist/packem_shared/writeYaml-a_cglLPV.js +1 -0
- package/dist/packem_shared/writeYamlSync-vSQIN6OR.js +1 -0
- package/dist/size.js +1 -0
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +1 -0
- package/dist/yaml.d.ts +1 -1
- package/dist/yaml.js +1 -0
- package/package.json +17 -77
- package/dist/eol.cjs +0 -3
- package/dist/eol.d.cts +0 -7
- package/dist/eol.d.mts +0 -7
- package/dist/eol.mjs +0 -3
- package/dist/error.cjs +0 -1
- package/dist/error.d.cts +0 -50
- package/dist/error.d.mts +0 -50
- package/dist/error.mjs +0 -1
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +0 -89
- package/dist/index.d.mts +0 -89
- package/dist/index.mjs +0 -1
- package/dist/packem_shared/AlreadyExistsError-GC2XUgzJ.cjs +0 -1
- package/dist/packem_shared/DirectoryError-aGtmQVph.cjs +0 -1
- package/dist/packem_shared/F_OK-7T91O6Oz.cjs +0 -1
- package/dist/packem_shared/F_OK-B71i3mUa.mjs +0 -1
- package/dist/packem_shared/JSONError-CVkb3xZ3.mjs +0 -4
- package/dist/packem_shared/JSONError-CWuiGmNc.cjs +0 -4
- package/dist/packem_shared/NotEmptyError-BWGfec5K.cjs +0 -1
- package/dist/packem_shared/NotFoundError-Diij7oqe.cjs +0 -1
- package/dist/packem_shared/PermissionError-Ck1Es7al.cjs +0 -1
- package/dist/packem_shared/WalkError-gKgp0TWD.cjs +0 -1
- package/dist/packem_shared/assertValidFileContents-CrbDz09d.cjs +0 -1
- package/dist/packem_shared/assertValidFileOrDirectoryPath-HOUs73Jk.cjs +0 -1
- package/dist/packem_shared/collect-Bl2Oc1qs.cjs +0 -1
- package/dist/packem_shared/collect-CyYPQFMs.mjs +0 -1
- package/dist/packem_shared/collectSync-BHjyXWq4.cjs +0 -1
- package/dist/packem_shared/collectSync-CD9cXw2g.mjs +0 -1
- package/dist/packem_shared/emptyDir-BdjO-6Gu.mjs +0 -1
- package/dist/packem_shared/emptyDir-DGRw4yE9.cjs +0 -1
- package/dist/packem_shared/emptyDirSync-C1vsMEp-.mjs +0 -1
- package/dist/packem_shared/emptyDirSync-DzjDZxOx.cjs +0 -1
- package/dist/packem_shared/ensureDir-BuIFF_6B.mjs +0 -1
- package/dist/packem_shared/ensureDir-DtQzyA70.cjs +0 -1
- package/dist/packem_shared/ensureDirSync-BuPHxdP4.mjs +0 -1
- package/dist/packem_shared/ensureDirSync-C8hIoS3o.cjs +0 -1
- package/dist/packem_shared/ensureFile-DcAODM6a.mjs +0 -1
- package/dist/packem_shared/ensureFile-wR8zBfXh.cjs +0 -1
- package/dist/packem_shared/ensureFileSync-BI1fIdNf.cjs +0 -1
- package/dist/packem_shared/ensureFileSync-CzPN6ucX.mjs +0 -1
- package/dist/packem_shared/ensureLink-BaZLXxgx.mjs +0 -1
- package/dist/packem_shared/ensureLink-DCPuU0Za.cjs +0 -1
- package/dist/packem_shared/ensureLinkSync-9C2JL-Sl.mjs +0 -1
- package/dist/packem_shared/ensureLinkSync-CuRZmQlV.cjs +0 -1
- package/dist/packem_shared/ensureSymlink-BH6wbylb.mjs +0 -1
- package/dist/packem_shared/ensureSymlink-J83jhdfA.cjs +0 -1
- package/dist/packem_shared/ensureSymlinkSync-CZSPodAm.mjs +0 -1
- package/dist/packem_shared/ensureSymlinkSync-VNtMTaV8.cjs +0 -1
- package/dist/packem_shared/findUp-C5aWsLuD.cjs +0 -1
- package/dist/packem_shared/findUp-CMGMYNty.mjs +0 -1
- package/dist/packem_shared/findUpSync-QP_ZEsJN.mjs +0 -1
- package/dist/packem_shared/findUpSync-U1lTgv4y.cjs +0 -1
- package/dist/packem_shared/get-file-info-type-DDbpRlDl.cjs +0 -1
- package/dist/packem_shared/index-BSjF-5vj.mjs +0 -1
- package/dist/packem_shared/index-DPla58ce.cjs +0 -1
- package/dist/packem_shared/is-stats-identical-Bti7K05l.cjs +0 -1
- package/dist/packem_shared/isAccessible-BQZd1_xn.cjs +0 -1
- package/dist/packem_shared/isAccessible-CL4eE5VL.mjs +0 -1
- package/dist/packem_shared/isAccessibleSync-BP5N8k_-.cjs +0 -1
- package/dist/packem_shared/isAccessibleSync-_HU_ppdG.mjs +0 -1
- package/dist/packem_shared/json-error-ZPgZIXcg.d.cts +0 -11
- package/dist/packem_shared/json-error-ZPgZIXcg.d.mts +0 -11
- package/dist/packem_shared/move--o4NZLpD.mjs +0 -1
- package/dist/packem_shared/move-DwG6APiG.cjs +0 -1
- package/dist/packem_shared/observable-like.d-BlD8q22s.d.cts +0 -40
- package/dist/packem_shared/observable-like.d-BlD8q22s.d.mts +0 -40
- package/dist/packem_shared/observable-like.d-BlD8q22s.d.ts +0 -40
- package/dist/packem_shared/parseJson-CQlz8sBs.cjs +0 -6
- package/dist/packem_shared/readFile-BvefDyr_.cjs +0 -1
- package/dist/packem_shared/readFile-Cix_ijtX.mjs +0 -1
- package/dist/packem_shared/readFileSync-B0O-8BH0.mjs +0 -1
- package/dist/packem_shared/readFileSync-Ct8Ql4Vs.cjs +0 -1
- package/dist/packem_shared/readJson-CiDugsbt.mjs +0 -1
- package/dist/packem_shared/readJson-DtH0Cn36.cjs +0 -1
- package/dist/packem_shared/readJsonSync-B47Fk6n-.mjs +0 -1
- package/dist/packem_shared/readJsonSync-_SoI70cG.cjs +0 -1
- package/dist/packem_shared/readYaml-BOYTR5D1.mjs +0 -1
- package/dist/packem_shared/readYaml-BzMFDsYe.cjs +0 -1
- package/dist/packem_shared/readYamlSync-BbK0khJu.cjs +0 -1
- package/dist/packem_shared/readYamlSync-md9g88k7.mjs +0 -1
- package/dist/packem_shared/remove-CtnFqEpd.mjs +0 -1
- package/dist/packem_shared/remove-DPCf2Qdb.cjs +0 -1
- package/dist/packem_shared/removeSync-Cyriz7r8.cjs +0 -1
- package/dist/packem_shared/removeSync-DI-IjqVp.mjs +0 -1
- package/dist/packem_shared/resolve-symlink-target-zilkQ_AU.cjs +0 -1
- package/dist/packem_shared/stripJsonComments-Cp5SNAB7.mjs +0 -1
- package/dist/packem_shared/stripJsonComments-CvZSDnYT.cjs +0 -1
- package/dist/packem_shared/to-uint-8-array-2-3EvGd7.cjs +0 -1
- package/dist/packem_shared/types-XsSUZ9oS.d.cts +0 -89
- package/dist/packem_shared/types-XsSUZ9oS.d.ts +0 -89
- package/dist/packem_shared/walk-BZTXbT87.mjs +0 -1
- package/dist/packem_shared/walk-DyN_HVFW.cjs +0 -1
- package/dist/packem_shared/walk-include-C9pVST87.mjs +0 -1
- package/dist/packem_shared/walk-include-DkK-WJl4.cjs +0 -1
- package/dist/packem_shared/walkSync-BHlEzV_m.mjs +0 -1
- package/dist/packem_shared/walkSync-Bqi7L2yG.cjs +0 -1
- package/dist/packem_shared/writeFile-COOAkvOE.mjs +0 -1
- package/dist/packem_shared/writeFile-CjgQEfur.cjs +0 -1
- package/dist/packem_shared/writeFileSync-CQuRHo9n.cjs +0 -1
- package/dist/packem_shared/writeFileSync-rhu-y_zx.mjs +0 -1
- package/dist/packem_shared/writeJson-BYT4WInm.mjs +0 -4
- package/dist/packem_shared/writeJson-CJIciZ_Q.cjs +0 -4
- package/dist/packem_shared/writeJsonSync-BIsrhRbV.cjs +0 -4
- package/dist/packem_shared/writeJsonSync-CLlXOFDm.mjs +0 -4
- package/dist/packem_shared/writeYaml-CjzVd0K-.mjs +0 -1
- package/dist/packem_shared/writeYaml-VmX1VKhN.cjs +0 -1
- package/dist/packem_shared/writeYamlSync-D9A9Ixe1.mjs +0 -1
- package/dist/packem_shared/writeYamlSync-DYsM6XBi.cjs +0 -1
- package/dist/size.cjs +0 -1
- package/dist/size.d.cts +0 -12
- package/dist/size.d.mts +0 -12
- package/dist/size.mjs +0 -1
- package/dist/utils.cjs +0 -1
- package/dist/utils.d.cts +0 -19
- package/dist/utils.d.mts +0 -19
- package/dist/utils.mjs +0 -1
- package/dist/yaml.cjs +0 -1
- package/dist/yaml.d.cts +0 -17
- package/dist/yaml.d.mts +0 -17
- package/dist/yaml.mjs +0 -1
- /package/dist/packem_shared/{AlreadyExistsError-CEu6_Tjb.mjs → AlreadyExistsError-CEu6_Tjb.js} +0 -0
- /package/dist/packem_shared/{DirectoryError-ddlbUV8C.mjs → DirectoryError-ddlbUV8C.js} +0 -0
- /package/dist/packem_shared/{NotEmptyError-DMh1o7UL.mjs → NotEmptyError-DMh1o7UL.js} +0 -0
- /package/dist/packem_shared/{NotFoundError-BPiW0icm.mjs → NotFoundError-BPiW0icm.js} +0 -0
- /package/dist/packem_shared/{PermissionError-B1Emi5a9.mjs → PermissionError-B1Emi5a9.js} +0 -0
- /package/dist/packem_shared/{WalkError-BsngoIKJ.mjs → WalkError-BsngoIKJ.js} +0 -0
- /package/dist/packem_shared/{assertValidFileContents-BZFnXa7K.mjs → assertValidFileContents-BZFnXa7K.js} +0 -0
- /package/dist/packem_shared/{assertValidFileOrDirectoryPath-DgPIPmZT.mjs → assertValidFileOrDirectoryPath-DgPIPmZT.js} +0 -0
- /package/dist/packem_shared/{get-file-info-type-CaWGXRjY.mjs → get-file-info-type-CaWGXRjY.js} +0 -0
- /package/dist/packem_shared/{is-stats-identical-CohsLtWy.mjs → is-stats-identical-CohsLtWy.js} +0 -0
- /package/dist/packem_shared/{resolve-symlink-target-BofZSDIc.mjs → resolve-symlink-target-BofZSDIc.js} +0 -0
- /package/dist/packem_shared/{to-uint-8-array-DwgaTasY.mjs → to-uint-8-array-DwgaTasY.js} +0 -0
package/README.md
CHANGED
|
@@ -463,7 +463,7 @@ The printable section of the JSON which produces the error.
|
|
|
463
463
|
function detect(content): "\n" | "\r\n";
|
|
464
464
|
```
|
|
465
465
|
|
|
466
|
-
Defined in: [packages/fs/src/eol.ts:29](https://github.com/visulima/visulima/blob/
|
|
466
|
+
Defined in: [packages/fs/src/eol.ts:29](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/eol.ts#L29)
|
|
467
467
|
|
|
468
468
|
Detect the EOL character for string input.
|
|
469
469
|
Returns null if no newline.
|
|
@@ -490,7 +490,7 @@ detect("Hello\nWorld"); // "\n"
|
|
|
490
490
|
detect("HelloWorld"); // null
|
|
491
491
|
```
|
|
492
492
|
|
|
493
|
-
|
|
493
|
+
---
|
|
494
494
|
|
|
495
495
|
### format()
|
|
496
496
|
|
|
@@ -498,7 +498,7 @@ detect("HelloWorld"); // null
|
|
|
498
498
|
function format(content, eol): string;
|
|
499
499
|
```
|
|
500
500
|
|
|
501
|
-
Defined in: [packages/fs/src/eol.ts:54](https://github.com/visulima/visulima/blob/
|
|
501
|
+
Defined in: [packages/fs/src/eol.ts:54](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/eol.ts#L54)
|
|
502
502
|
|
|
503
503
|
Format the file to the targeted EOL.
|
|
504
504
|
|
|
@@ -537,11 +537,11 @@ format("Hello\nWorld\r\nWindows", CRLF); // "Hello\r\nWorld\r\nWindows"
|
|
|
537
537
|
const CRLF: "\r\n";
|
|
538
538
|
```
|
|
539
539
|
|
|
540
|
-
Defined in: [packages/fs/src/eol.ts:9](https://github.com/visulima/visulima/blob/
|
|
540
|
+
Defined in: [packages/fs/src/eol.ts:9](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/eol.ts#L9)
|
|
541
541
|
|
|
542
542
|
End-of-line character for Windows platforms.
|
|
543
543
|
|
|
544
|
-
|
|
544
|
+
---
|
|
545
545
|
|
|
546
546
|
### EOL
|
|
547
547
|
|
|
@@ -549,11 +549,11 @@ End-of-line character for Windows platforms.
|
|
|
549
549
|
const EOL: "\n" | "\r\n";
|
|
550
550
|
```
|
|
551
551
|
|
|
552
|
-
Defined in: [packages/fs/src/eol.ts:14](https://github.com/visulima/visulima/blob/
|
|
552
|
+
Defined in: [packages/fs/src/eol.ts:14](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/eol.ts#L14)
|
|
553
553
|
|
|
554
554
|
End-of-line character evaluated for the current platform.
|
|
555
555
|
|
|
556
|
-
|
|
556
|
+
---
|
|
557
557
|
|
|
558
558
|
### LF
|
|
559
559
|
|
|
@@ -561,16 +561,17 @@ End-of-line character evaluated for the current platform.
|
|
|
561
561
|
const LF: "\n";
|
|
562
562
|
```
|
|
563
563
|
|
|
564
|
-
Defined in: [packages/fs/src/eol.ts:6](https://github.com/visulima/visulima/blob/
|
|
564
|
+
Defined in: [packages/fs/src/eol.ts:6](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/eol.ts#L6)
|
|
565
565
|
|
|
566
566
|
End-of-line character for POSIX platforms such as macOS and Linux.
|
|
567
|
+
|
|
567
568
|
# error
|
|
568
569
|
|
|
569
570
|
## Classes
|
|
570
571
|
|
|
571
572
|
### AlreadyExistsError
|
|
572
573
|
|
|
573
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:28](https://github.com/visulima/visulima/blob/
|
|
574
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:28](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/already-exists-error.ts#L28)
|
|
574
575
|
|
|
575
576
|
Error thrown when a file or directory already exists at a specified path, and an operation was expecting it not to.
|
|
576
577
|
|
|
@@ -582,21 +583,22 @@ import { ensureSymlinkSync } from "@visulima/fs"; // Or any function that might
|
|
|
582
583
|
import { join } from "node:path";
|
|
583
584
|
|
|
584
585
|
try {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
586
|
+
// Example: ensureSymlinkSync might throw this if a file (not a symlink) already exists at linkName
|
|
587
|
+
// For demonstration, let's assume someFunction internally throws it:
|
|
588
|
+
const someFunctionThatMightThrow = (path) => {
|
|
589
|
+
if (path === "/tmp/existing-file.txt") {
|
|
590
|
+
// Simulate a check
|
|
591
|
+
throw new AlreadyExistsError(`file already exists at '/tmp/existing-file.txt'`);
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
someFunctionThatMightThrow("/tmp/existing-file.txt");
|
|
593
595
|
} catch (error) {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
596
|
+
if (error instanceof AlreadyExistsError) {
|
|
597
|
+
console.error(`Operation failed because path exists: ${error.message}`);
|
|
598
|
+
console.error(`Error code: ${error.code}`); // EEXIST
|
|
599
|
+
} else {
|
|
600
|
+
console.error("An unexpected error occurred:", error);
|
|
601
|
+
}
|
|
600
602
|
}
|
|
601
603
|
```
|
|
602
604
|
|
|
@@ -612,7 +614,7 @@ try {
|
|
|
612
614
|
new AlreadyExistsError(message): AlreadyExistsError;
|
|
613
615
|
```
|
|
614
616
|
|
|
615
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:33](https://github.com/visulima/visulima/blob/
|
|
617
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:33](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/already-exists-error.ts#L33)
|
|
616
618
|
|
|
617
619
|
Creates a new instance.
|
|
618
620
|
|
|
@@ -631,7 +633,7 @@ The error message.
|
|
|
631
633
|
###### Overrides
|
|
632
634
|
|
|
633
635
|
```ts
|
|
634
|
-
Error.constructor
|
|
636
|
+
Error.constructor;
|
|
635
637
|
```
|
|
636
638
|
|
|
637
639
|
#### Accessors
|
|
@@ -644,7 +646,7 @@ Error.constructor
|
|
|
644
646
|
get code(): string;
|
|
645
647
|
```
|
|
646
648
|
|
|
647
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:38](https://github.com/visulima/visulima/blob/
|
|
649
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:38](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/already-exists-error.ts#L38)
|
|
648
650
|
|
|
649
651
|
###### Returns
|
|
650
652
|
|
|
@@ -656,7 +658,7 @@ Defined in: [packages/fs/src/error/already-exists-error.ts:38](https://github.co
|
|
|
656
658
|
set code(_name): void;
|
|
657
659
|
```
|
|
658
660
|
|
|
659
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:43](https://github.com/visulima/visulima/blob/
|
|
661
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:43](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/already-exists-error.ts#L43)
|
|
660
662
|
|
|
661
663
|
###### Parameters
|
|
662
664
|
|
|
@@ -676,7 +678,7 @@ Defined in: [packages/fs/src/error/already-exists-error.ts:43](https://github.co
|
|
|
676
678
|
get name(): string;
|
|
677
679
|
```
|
|
678
680
|
|
|
679
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:48](https://github.com/visulima/visulima/blob/
|
|
681
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:48](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/already-exists-error.ts#L48)
|
|
680
682
|
|
|
681
683
|
###### Returns
|
|
682
684
|
|
|
@@ -688,7 +690,7 @@ Defined in: [packages/fs/src/error/already-exists-error.ts:48](https://github.co
|
|
|
688
690
|
set name(_name): void;
|
|
689
691
|
```
|
|
690
692
|
|
|
691
|
-
Defined in: [packages/fs/src/error/already-exists-error.ts:53](https://github.com/visulima/visulima/blob/
|
|
693
|
+
Defined in: [packages/fs/src/error/already-exists-error.ts:53](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/already-exists-error.ts#L53)
|
|
692
694
|
|
|
693
695
|
###### Parameters
|
|
694
696
|
|
|
@@ -703,7 +705,7 @@ Defined in: [packages/fs/src/error/already-exists-error.ts:53](https://github.co
|
|
|
703
705
|
###### Overrides
|
|
704
706
|
|
|
705
707
|
```ts
|
|
706
|
-
Error.name
|
|
708
|
+
Error.name;
|
|
707
709
|
```
|
|
708
710
|
|
|
709
711
|
#### Methods
|
|
@@ -714,7 +716,7 @@ Error.name
|
|
|
714
716
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
715
717
|
```
|
|
716
718
|
|
|
717
|
-
Defined in:
|
|
719
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:91
|
|
718
720
|
|
|
719
721
|
Create .stack property on a target object
|
|
720
722
|
|
|
@@ -735,7 +737,7 @@ Create .stack property on a target object
|
|
|
735
737
|
###### Inherited from
|
|
736
738
|
|
|
737
739
|
```ts
|
|
738
|
-
Error.captureStackTrace
|
|
740
|
+
Error.captureStackTrace;
|
|
739
741
|
```
|
|
740
742
|
|
|
741
743
|
#### Properties
|
|
@@ -746,12 +748,12 @@ Error.captureStackTrace
|
|
|
746
748
|
optional cause: unknown;
|
|
747
749
|
```
|
|
748
750
|
|
|
749
|
-
Defined in:
|
|
751
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
|
|
750
752
|
|
|
751
753
|
###### Inherited from
|
|
752
754
|
|
|
753
755
|
```ts
|
|
754
|
-
Error.cause
|
|
756
|
+
Error.cause;
|
|
755
757
|
```
|
|
756
758
|
|
|
757
759
|
##### message
|
|
@@ -760,12 +762,12 @@ Error.cause
|
|
|
760
762
|
message: string;
|
|
761
763
|
```
|
|
762
764
|
|
|
763
|
-
Defined in:
|
|
765
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1077
|
|
764
766
|
|
|
765
767
|
###### Inherited from
|
|
766
768
|
|
|
767
769
|
```ts
|
|
768
|
-
Error.message
|
|
770
|
+
Error.message;
|
|
769
771
|
```
|
|
770
772
|
|
|
771
773
|
##### stack?
|
|
@@ -774,12 +776,12 @@ Error.message
|
|
|
774
776
|
optional stack: string;
|
|
775
777
|
```
|
|
776
778
|
|
|
777
|
-
Defined in:
|
|
779
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1078
|
|
778
780
|
|
|
779
781
|
###### Inherited from
|
|
780
782
|
|
|
781
783
|
```ts
|
|
782
|
-
Error.stack
|
|
784
|
+
Error.stack;
|
|
783
785
|
```
|
|
784
786
|
|
|
785
787
|
##### prepareStackTrace()?
|
|
@@ -788,7 +790,7 @@ Error.stack
|
|
|
788
790
|
static optional prepareStackTrace: (err, stackTraces) => any;
|
|
789
791
|
```
|
|
790
792
|
|
|
791
|
-
Defined in:
|
|
793
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:98
|
|
792
794
|
|
|
793
795
|
Optional override for formatting stack traces
|
|
794
796
|
|
|
@@ -813,7 +815,7 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
813
815
|
###### Inherited from
|
|
814
816
|
|
|
815
817
|
```ts
|
|
816
|
-
Error.prepareStackTrace
|
|
818
|
+
Error.prepareStackTrace;
|
|
817
819
|
```
|
|
818
820
|
|
|
819
821
|
##### stackTraceLimit
|
|
@@ -822,19 +824,19 @@ Error.prepareStackTrace
|
|
|
822
824
|
static stackTraceLimit: number;
|
|
823
825
|
```
|
|
824
826
|
|
|
825
|
-
Defined in:
|
|
827
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:100
|
|
826
828
|
|
|
827
829
|
###### Inherited from
|
|
828
830
|
|
|
829
831
|
```ts
|
|
830
|
-
Error.stackTraceLimit
|
|
832
|
+
Error.stackTraceLimit;
|
|
831
833
|
```
|
|
832
834
|
|
|
833
|
-
|
|
835
|
+
---
|
|
834
836
|
|
|
835
837
|
### DirectoryError
|
|
836
838
|
|
|
837
|
-
Defined in: [packages/fs/src/error/directory-error.ts:36](https://github.com/visulima/visulima/blob/
|
|
839
|
+
Defined in: [packages/fs/src/error/directory-error.ts:36](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/directory-error.ts#L36)
|
|
838
840
|
|
|
839
841
|
Error thrown when an operation that is not allowed on a directory is attempted.
|
|
840
842
|
This typically occurs when a file-specific operation is used on a directory path.
|
|
@@ -847,26 +849,27 @@ import { readFile } from "@visulima/fs"; // Or any function that might throw thi
|
|
|
847
849
|
import { join } from "node:path";
|
|
848
850
|
|
|
849
851
|
const attemptToReadFileFromDir = async () => {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
852
|
+
try {
|
|
853
|
+
// Attempting to read a directory as if it were a file
|
|
854
|
+
// This is a conceptual example; readFile might throw a different error first
|
|
855
|
+
// depending on its internal checks, but EISDIR is the underlying system error.
|
|
856
|
+
// Forcing the scenario:
|
|
857
|
+
const pretendReadFileOnDir = (path) => {
|
|
858
|
+
if (path === "/tmp/my-directory") {
|
|
859
|
+
// Simulate a directory path
|
|
860
|
+
throw new DirectoryError(`read '/tmp/my-directory'`);
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
pretendReadFileOnDir("/tmp/my-directory");
|
|
864
|
+
// await readFile(join("/tmp", "my-directory"));
|
|
865
|
+
} catch (error) {
|
|
866
|
+
if (error instanceof DirectoryError) {
|
|
867
|
+
console.error(`Operation failed, path is a directory: ${error.message}`);
|
|
868
|
+
console.error(`Error code: ${error.code}`); // EISDIR
|
|
869
|
+
} else {
|
|
870
|
+
console.error("An unexpected error occurred:", error);
|
|
871
|
+
}
|
|
859
872
|
}
|
|
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
873
|
};
|
|
871
874
|
|
|
872
875
|
attemptToReadFileFromDir();
|
|
@@ -884,7 +887,7 @@ attemptToReadFileFromDir();
|
|
|
884
887
|
new DirectoryError(message): DirectoryError;
|
|
885
888
|
```
|
|
886
889
|
|
|
887
|
-
Defined in: [packages/fs/src/error/directory-error.ts:41](https://github.com/visulima/visulima/blob/
|
|
890
|
+
Defined in: [packages/fs/src/error/directory-error.ts:41](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/directory-error.ts#L41)
|
|
888
891
|
|
|
889
892
|
Creates a new instance.
|
|
890
893
|
|
|
@@ -903,7 +906,7 @@ The error message.
|
|
|
903
906
|
###### Overrides
|
|
904
907
|
|
|
905
908
|
```ts
|
|
906
|
-
Error.constructor
|
|
909
|
+
Error.constructor;
|
|
907
910
|
```
|
|
908
911
|
|
|
909
912
|
#### Accessors
|
|
@@ -916,7 +919,7 @@ Error.constructor
|
|
|
916
919
|
get code(): string;
|
|
917
920
|
```
|
|
918
921
|
|
|
919
|
-
Defined in: [packages/fs/src/error/directory-error.ts:46](https://github.com/visulima/visulima/blob/
|
|
922
|
+
Defined in: [packages/fs/src/error/directory-error.ts:46](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/directory-error.ts#L46)
|
|
920
923
|
|
|
921
924
|
###### Returns
|
|
922
925
|
|
|
@@ -928,7 +931,7 @@ Defined in: [packages/fs/src/error/directory-error.ts:46](https://github.com/vis
|
|
|
928
931
|
set code(_name): void;
|
|
929
932
|
```
|
|
930
933
|
|
|
931
|
-
Defined in: [packages/fs/src/error/directory-error.ts:51](https://github.com/visulima/visulima/blob/
|
|
934
|
+
Defined in: [packages/fs/src/error/directory-error.ts:51](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/directory-error.ts#L51)
|
|
932
935
|
|
|
933
936
|
###### Parameters
|
|
934
937
|
|
|
@@ -948,7 +951,7 @@ Defined in: [packages/fs/src/error/directory-error.ts:51](https://github.com/vis
|
|
|
948
951
|
get name(): string;
|
|
949
952
|
```
|
|
950
953
|
|
|
951
|
-
Defined in: [packages/fs/src/error/directory-error.ts:56](https://github.com/visulima/visulima/blob/
|
|
954
|
+
Defined in: [packages/fs/src/error/directory-error.ts:56](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/directory-error.ts#L56)
|
|
952
955
|
|
|
953
956
|
###### Returns
|
|
954
957
|
|
|
@@ -960,7 +963,7 @@ Defined in: [packages/fs/src/error/directory-error.ts:56](https://github.com/vis
|
|
|
960
963
|
set name(_name): void;
|
|
961
964
|
```
|
|
962
965
|
|
|
963
|
-
Defined in: [packages/fs/src/error/directory-error.ts:61](https://github.com/visulima/visulima/blob/
|
|
966
|
+
Defined in: [packages/fs/src/error/directory-error.ts:61](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/directory-error.ts#L61)
|
|
964
967
|
|
|
965
968
|
###### Parameters
|
|
966
969
|
|
|
@@ -975,7 +978,7 @@ Defined in: [packages/fs/src/error/directory-error.ts:61](https://github.com/vis
|
|
|
975
978
|
###### Overrides
|
|
976
979
|
|
|
977
980
|
```ts
|
|
978
|
-
Error.name
|
|
981
|
+
Error.name;
|
|
979
982
|
```
|
|
980
983
|
|
|
981
984
|
#### Methods
|
|
@@ -986,7 +989,7 @@ Error.name
|
|
|
986
989
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
987
990
|
```
|
|
988
991
|
|
|
989
|
-
Defined in:
|
|
992
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:91
|
|
990
993
|
|
|
991
994
|
Create .stack property on a target object
|
|
992
995
|
|
|
@@ -1007,7 +1010,7 @@ Create .stack property on a target object
|
|
|
1007
1010
|
###### Inherited from
|
|
1008
1011
|
|
|
1009
1012
|
```ts
|
|
1010
|
-
Error.captureStackTrace
|
|
1013
|
+
Error.captureStackTrace;
|
|
1011
1014
|
```
|
|
1012
1015
|
|
|
1013
1016
|
#### Properties
|
|
@@ -1018,12 +1021,12 @@ Error.captureStackTrace
|
|
|
1018
1021
|
optional cause: unknown;
|
|
1019
1022
|
```
|
|
1020
1023
|
|
|
1021
|
-
Defined in:
|
|
1024
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
|
|
1022
1025
|
|
|
1023
1026
|
###### Inherited from
|
|
1024
1027
|
|
|
1025
1028
|
```ts
|
|
1026
|
-
Error.cause
|
|
1029
|
+
Error.cause;
|
|
1027
1030
|
```
|
|
1028
1031
|
|
|
1029
1032
|
##### message
|
|
@@ -1032,12 +1035,12 @@ Error.cause
|
|
|
1032
1035
|
message: string;
|
|
1033
1036
|
```
|
|
1034
1037
|
|
|
1035
|
-
Defined in:
|
|
1038
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1077
|
|
1036
1039
|
|
|
1037
1040
|
###### Inherited from
|
|
1038
1041
|
|
|
1039
1042
|
```ts
|
|
1040
|
-
Error.message
|
|
1043
|
+
Error.message;
|
|
1041
1044
|
```
|
|
1042
1045
|
|
|
1043
1046
|
##### stack?
|
|
@@ -1046,12 +1049,12 @@ Error.message
|
|
|
1046
1049
|
optional stack: string;
|
|
1047
1050
|
```
|
|
1048
1051
|
|
|
1049
|
-
Defined in:
|
|
1052
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1078
|
|
1050
1053
|
|
|
1051
1054
|
###### Inherited from
|
|
1052
1055
|
|
|
1053
1056
|
```ts
|
|
1054
|
-
Error.stack
|
|
1057
|
+
Error.stack;
|
|
1055
1058
|
```
|
|
1056
1059
|
|
|
1057
1060
|
##### prepareStackTrace()?
|
|
@@ -1060,7 +1063,7 @@ Error.stack
|
|
|
1060
1063
|
static optional prepareStackTrace: (err, stackTraces) => any;
|
|
1061
1064
|
```
|
|
1062
1065
|
|
|
1063
|
-
Defined in:
|
|
1066
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:98
|
|
1064
1067
|
|
|
1065
1068
|
Optional override for formatting stack traces
|
|
1066
1069
|
|
|
@@ -1085,7 +1088,7 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
1085
1088
|
###### Inherited from
|
|
1086
1089
|
|
|
1087
1090
|
```ts
|
|
1088
|
-
Error.prepareStackTrace
|
|
1091
|
+
Error.prepareStackTrace;
|
|
1089
1092
|
```
|
|
1090
1093
|
|
|
1091
1094
|
##### stackTraceLimit
|
|
@@ -1094,19 +1097,19 @@ Error.prepareStackTrace
|
|
|
1094
1097
|
static stackTraceLimit: number;
|
|
1095
1098
|
```
|
|
1096
1099
|
|
|
1097
|
-
Defined in:
|
|
1100
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:100
|
|
1098
1101
|
|
|
1099
1102
|
###### Inherited from
|
|
1100
1103
|
|
|
1101
1104
|
```ts
|
|
1102
|
-
Error.stackTraceLimit
|
|
1105
|
+
Error.stackTraceLimit;
|
|
1103
1106
|
```
|
|
1104
1107
|
|
|
1105
|
-
|
|
1108
|
+
---
|
|
1106
1109
|
|
|
1107
1110
|
### NotEmptyError
|
|
1108
1111
|
|
|
1109
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:40](https://github.com/visulima/visulima/blob/
|
|
1112
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:40](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-empty-error.ts#L40)
|
|
1110
1113
|
|
|
1111
1114
|
Error thrown when a directory is not empty.
|
|
1112
1115
|
|
|
@@ -1118,26 +1121,27 @@ import { rmdir } from "node:fs/promises"; // Or any fs function that might throw
|
|
|
1118
1121
|
import { join } from "node:path";
|
|
1119
1122
|
|
|
1120
1123
|
const attemptToRemoveNonEmptyDir = async () => {
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1124
|
+
const dirPath = join("/tmp", "my-non-empty-dir"); // Assume this directory exists and has files
|
|
1125
|
+
try {
|
|
1126
|
+
// Forcing the scenario for demonstration, as rmdir might throw its own specific error.
|
|
1127
|
+
// Node.js fs operations that encounter a non-empty directory when expecting an empty one
|
|
1128
|
+
// typically throw an error with code ENOTEMPTY.
|
|
1129
|
+
const simulateNotEmpty = (path) => {
|
|
1130
|
+
if (path === dirPath) {
|
|
1131
|
+
// Simulate check for non-empty
|
|
1132
|
+
throw new NotEmptyError(`rmdir '${dirPath}'`);
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
simulateNotEmpty(dirPath);
|
|
1136
|
+
// await rmdir(dirPath); // This would likely throw an error with code ENOTEMPTY
|
|
1137
|
+
} catch (error) {
|
|
1138
|
+
if (error instanceof NotEmptyError) {
|
|
1139
|
+
console.error(`Operation failed, directory is not empty: ${error.message}`);
|
|
1140
|
+
console.error(`Error code: ${error.code}`); // ENOTEMPTY
|
|
1141
|
+
} else {
|
|
1142
|
+
console.error("An unexpected error occurred:", error);
|
|
1143
|
+
}
|
|
1139
1144
|
}
|
|
1140
|
-
}
|
|
1141
1145
|
};
|
|
1142
1146
|
|
|
1143
1147
|
// You would need to set up a non-empty directory at /tmp/my-non-empty-dir for a real test
|
|
@@ -1160,7 +1164,7 @@ attemptToRemoveNonEmptyDir();
|
|
|
1160
1164
|
new NotEmptyError(message): NotEmptyError;
|
|
1161
1165
|
```
|
|
1162
1166
|
|
|
1163
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:45](https://github.com/visulima/visulima/blob/
|
|
1167
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:45](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-empty-error.ts#L45)
|
|
1164
1168
|
|
|
1165
1169
|
Creates a new instance.
|
|
1166
1170
|
|
|
@@ -1179,7 +1183,7 @@ The error message.
|
|
|
1179
1183
|
###### Overrides
|
|
1180
1184
|
|
|
1181
1185
|
```ts
|
|
1182
|
-
Error.constructor
|
|
1186
|
+
Error.constructor;
|
|
1183
1187
|
```
|
|
1184
1188
|
|
|
1185
1189
|
#### Accessors
|
|
@@ -1192,7 +1196,7 @@ Error.constructor
|
|
|
1192
1196
|
get code(): string;
|
|
1193
1197
|
```
|
|
1194
1198
|
|
|
1195
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:50](https://github.com/visulima/visulima/blob/
|
|
1199
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:50](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-empty-error.ts#L50)
|
|
1196
1200
|
|
|
1197
1201
|
###### Returns
|
|
1198
1202
|
|
|
@@ -1204,7 +1208,7 @@ Defined in: [packages/fs/src/error/not-empty-error.ts:50](https://github.com/vis
|
|
|
1204
1208
|
set code(_name): void;
|
|
1205
1209
|
```
|
|
1206
1210
|
|
|
1207
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:55](https://github.com/visulima/visulima/blob/
|
|
1211
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:55](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-empty-error.ts#L55)
|
|
1208
1212
|
|
|
1209
1213
|
###### Parameters
|
|
1210
1214
|
|
|
@@ -1224,7 +1228,7 @@ Defined in: [packages/fs/src/error/not-empty-error.ts:55](https://github.com/vis
|
|
|
1224
1228
|
get name(): string;
|
|
1225
1229
|
```
|
|
1226
1230
|
|
|
1227
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:60](https://github.com/visulima/visulima/blob/
|
|
1231
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:60](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-empty-error.ts#L60)
|
|
1228
1232
|
|
|
1229
1233
|
###### Returns
|
|
1230
1234
|
|
|
@@ -1236,7 +1240,7 @@ Defined in: [packages/fs/src/error/not-empty-error.ts:60](https://github.com/vis
|
|
|
1236
1240
|
set name(_name): void;
|
|
1237
1241
|
```
|
|
1238
1242
|
|
|
1239
|
-
Defined in: [packages/fs/src/error/not-empty-error.ts:65](https://github.com/visulima/visulima/blob/
|
|
1243
|
+
Defined in: [packages/fs/src/error/not-empty-error.ts:65](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-empty-error.ts#L65)
|
|
1240
1244
|
|
|
1241
1245
|
###### Parameters
|
|
1242
1246
|
|
|
@@ -1251,7 +1255,7 @@ Defined in: [packages/fs/src/error/not-empty-error.ts:65](https://github.com/vis
|
|
|
1251
1255
|
###### Overrides
|
|
1252
1256
|
|
|
1253
1257
|
```ts
|
|
1254
|
-
Error.name
|
|
1258
|
+
Error.name;
|
|
1255
1259
|
```
|
|
1256
1260
|
|
|
1257
1261
|
#### Methods
|
|
@@ -1262,7 +1266,7 @@ Error.name
|
|
|
1262
1266
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
1263
1267
|
```
|
|
1264
1268
|
|
|
1265
|
-
Defined in:
|
|
1269
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:91
|
|
1266
1270
|
|
|
1267
1271
|
Create .stack property on a target object
|
|
1268
1272
|
|
|
@@ -1283,7 +1287,7 @@ Create .stack property on a target object
|
|
|
1283
1287
|
###### Inherited from
|
|
1284
1288
|
|
|
1285
1289
|
```ts
|
|
1286
|
-
Error.captureStackTrace
|
|
1290
|
+
Error.captureStackTrace;
|
|
1287
1291
|
```
|
|
1288
1292
|
|
|
1289
1293
|
#### Properties
|
|
@@ -1294,12 +1298,12 @@ Error.captureStackTrace
|
|
|
1294
1298
|
optional cause: unknown;
|
|
1295
1299
|
```
|
|
1296
1300
|
|
|
1297
|
-
Defined in:
|
|
1301
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
|
|
1298
1302
|
|
|
1299
1303
|
###### Inherited from
|
|
1300
1304
|
|
|
1301
1305
|
```ts
|
|
1302
|
-
Error.cause
|
|
1306
|
+
Error.cause;
|
|
1303
1307
|
```
|
|
1304
1308
|
|
|
1305
1309
|
##### message
|
|
@@ -1308,12 +1312,12 @@ Error.cause
|
|
|
1308
1312
|
message: string;
|
|
1309
1313
|
```
|
|
1310
1314
|
|
|
1311
|
-
Defined in:
|
|
1315
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1077
|
|
1312
1316
|
|
|
1313
1317
|
###### Inherited from
|
|
1314
1318
|
|
|
1315
1319
|
```ts
|
|
1316
|
-
Error.message
|
|
1320
|
+
Error.message;
|
|
1317
1321
|
```
|
|
1318
1322
|
|
|
1319
1323
|
##### stack?
|
|
@@ -1322,12 +1326,12 @@ Error.message
|
|
|
1322
1326
|
optional stack: string;
|
|
1323
1327
|
```
|
|
1324
1328
|
|
|
1325
|
-
Defined in:
|
|
1329
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1078
|
|
1326
1330
|
|
|
1327
1331
|
###### Inherited from
|
|
1328
1332
|
|
|
1329
1333
|
```ts
|
|
1330
|
-
Error.stack
|
|
1334
|
+
Error.stack;
|
|
1331
1335
|
```
|
|
1332
1336
|
|
|
1333
1337
|
##### prepareStackTrace()?
|
|
@@ -1336,7 +1340,7 @@ Error.stack
|
|
|
1336
1340
|
static optional prepareStackTrace: (err, stackTraces) => any;
|
|
1337
1341
|
```
|
|
1338
1342
|
|
|
1339
|
-
Defined in:
|
|
1343
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:98
|
|
1340
1344
|
|
|
1341
1345
|
Optional override for formatting stack traces
|
|
1342
1346
|
|
|
@@ -1361,7 +1365,7 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
1361
1365
|
###### Inherited from
|
|
1362
1366
|
|
|
1363
1367
|
```ts
|
|
1364
|
-
Error.prepareStackTrace
|
|
1368
|
+
Error.prepareStackTrace;
|
|
1365
1369
|
```
|
|
1366
1370
|
|
|
1367
1371
|
##### stackTraceLimit
|
|
@@ -1370,19 +1374,19 @@ Error.prepareStackTrace
|
|
|
1370
1374
|
static stackTraceLimit: number;
|
|
1371
1375
|
```
|
|
1372
1376
|
|
|
1373
|
-
Defined in:
|
|
1377
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:100
|
|
1374
1378
|
|
|
1375
1379
|
###### Inherited from
|
|
1376
1380
|
|
|
1377
1381
|
```ts
|
|
1378
|
-
Error.stackTraceLimit
|
|
1382
|
+
Error.stackTraceLimit;
|
|
1379
1383
|
```
|
|
1380
1384
|
|
|
1381
|
-
|
|
1385
|
+
---
|
|
1382
1386
|
|
|
1383
1387
|
### NotFoundError
|
|
1384
1388
|
|
|
1385
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:33](https://github.com/visulima/visulima/blob/
|
|
1389
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:33](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-found-error.ts#L33)
|
|
1386
1390
|
|
|
1387
1391
|
Error thrown when a file or directory is not found at a specified path.
|
|
1388
1392
|
|
|
@@ -1394,24 +1398,24 @@ import { readFile } from "@visulima/fs"; // Or any function that might throw thi
|
|
|
1394
1398
|
import { join } from "node:path";
|
|
1395
1399
|
|
|
1396
1400
|
const tryReadingNonExistentFile = async () => {
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1401
|
+
const filePath = join("/tmp", "this-file-does-not-exist.txt");
|
|
1402
|
+
try {
|
|
1403
|
+
// Forcing the scenario for demonstration, as readFile itself would throw this.
|
|
1404
|
+
const simulateNotFound = (path) => {
|
|
1405
|
+
if (path === filePath) {
|
|
1406
|
+
throw new NotFoundError(`no such file or directory, open '${filePath}'`);
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
simulateNotFound(filePath);
|
|
1410
|
+
// await readFile(filePath);
|
|
1411
|
+
} catch (error) {
|
|
1412
|
+
if (error instanceof NotFoundError) {
|
|
1413
|
+
console.error(`Operation failed, path not found: ${error.message}`);
|
|
1414
|
+
console.error(`Error code: ${error.code}`); // ENOENT
|
|
1415
|
+
} else {
|
|
1416
|
+
console.error("An unexpected error occurred:", error);
|
|
1417
|
+
}
|
|
1413
1418
|
}
|
|
1414
|
-
}
|
|
1415
1419
|
};
|
|
1416
1420
|
|
|
1417
1421
|
tryReadingNonExistentFile();
|
|
@@ -1429,7 +1433,7 @@ tryReadingNonExistentFile();
|
|
|
1429
1433
|
new NotFoundError(message): NotFoundError;
|
|
1430
1434
|
```
|
|
1431
1435
|
|
|
1432
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:38](https://github.com/visulima/visulima/blob/
|
|
1436
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:38](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-found-error.ts#L38)
|
|
1433
1437
|
|
|
1434
1438
|
Creates a new instance.
|
|
1435
1439
|
|
|
@@ -1448,7 +1452,7 @@ The error message.
|
|
|
1448
1452
|
###### Overrides
|
|
1449
1453
|
|
|
1450
1454
|
```ts
|
|
1451
|
-
Error.constructor
|
|
1455
|
+
Error.constructor;
|
|
1452
1456
|
```
|
|
1453
1457
|
|
|
1454
1458
|
#### Accessors
|
|
@@ -1461,7 +1465,7 @@ Error.constructor
|
|
|
1461
1465
|
get code(): string;
|
|
1462
1466
|
```
|
|
1463
1467
|
|
|
1464
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:43](https://github.com/visulima/visulima/blob/
|
|
1468
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:43](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-found-error.ts#L43)
|
|
1465
1469
|
|
|
1466
1470
|
###### Returns
|
|
1467
1471
|
|
|
@@ -1473,7 +1477,7 @@ Defined in: [packages/fs/src/error/not-found-error.ts:43](https://github.com/vis
|
|
|
1473
1477
|
set code(_name): void;
|
|
1474
1478
|
```
|
|
1475
1479
|
|
|
1476
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:48](https://github.com/visulima/visulima/blob/
|
|
1480
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:48](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-found-error.ts#L48)
|
|
1477
1481
|
|
|
1478
1482
|
###### Parameters
|
|
1479
1483
|
|
|
@@ -1493,7 +1497,7 @@ Defined in: [packages/fs/src/error/not-found-error.ts:48](https://github.com/vis
|
|
|
1493
1497
|
get name(): string;
|
|
1494
1498
|
```
|
|
1495
1499
|
|
|
1496
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:53](https://github.com/visulima/visulima/blob/
|
|
1500
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:53](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-found-error.ts#L53)
|
|
1497
1501
|
|
|
1498
1502
|
###### Returns
|
|
1499
1503
|
|
|
@@ -1505,7 +1509,7 @@ Defined in: [packages/fs/src/error/not-found-error.ts:53](https://github.com/vis
|
|
|
1505
1509
|
set name(_name): void;
|
|
1506
1510
|
```
|
|
1507
1511
|
|
|
1508
|
-
Defined in: [packages/fs/src/error/not-found-error.ts:58](https://github.com/visulima/visulima/blob/
|
|
1512
|
+
Defined in: [packages/fs/src/error/not-found-error.ts:58](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/not-found-error.ts#L58)
|
|
1509
1513
|
|
|
1510
1514
|
###### Parameters
|
|
1511
1515
|
|
|
@@ -1520,7 +1524,7 @@ Defined in: [packages/fs/src/error/not-found-error.ts:58](https://github.com/vis
|
|
|
1520
1524
|
###### Overrides
|
|
1521
1525
|
|
|
1522
1526
|
```ts
|
|
1523
|
-
Error.name
|
|
1527
|
+
Error.name;
|
|
1524
1528
|
```
|
|
1525
1529
|
|
|
1526
1530
|
#### Methods
|
|
@@ -1531,7 +1535,7 @@ Error.name
|
|
|
1531
1535
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
1532
1536
|
```
|
|
1533
1537
|
|
|
1534
|
-
Defined in:
|
|
1538
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:91
|
|
1535
1539
|
|
|
1536
1540
|
Create .stack property on a target object
|
|
1537
1541
|
|
|
@@ -1552,7 +1556,7 @@ Create .stack property on a target object
|
|
|
1552
1556
|
###### Inherited from
|
|
1553
1557
|
|
|
1554
1558
|
```ts
|
|
1555
|
-
Error.captureStackTrace
|
|
1559
|
+
Error.captureStackTrace;
|
|
1556
1560
|
```
|
|
1557
1561
|
|
|
1558
1562
|
#### Properties
|
|
@@ -1563,12 +1567,12 @@ Error.captureStackTrace
|
|
|
1563
1567
|
optional cause: unknown;
|
|
1564
1568
|
```
|
|
1565
1569
|
|
|
1566
|
-
Defined in:
|
|
1570
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
|
|
1567
1571
|
|
|
1568
1572
|
###### Inherited from
|
|
1569
1573
|
|
|
1570
1574
|
```ts
|
|
1571
|
-
Error.cause
|
|
1575
|
+
Error.cause;
|
|
1572
1576
|
```
|
|
1573
1577
|
|
|
1574
1578
|
##### message
|
|
@@ -1577,12 +1581,12 @@ Error.cause
|
|
|
1577
1581
|
message: string;
|
|
1578
1582
|
```
|
|
1579
1583
|
|
|
1580
|
-
Defined in:
|
|
1584
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1077
|
|
1581
1585
|
|
|
1582
1586
|
###### Inherited from
|
|
1583
1587
|
|
|
1584
1588
|
```ts
|
|
1585
|
-
Error.message
|
|
1589
|
+
Error.message;
|
|
1586
1590
|
```
|
|
1587
1591
|
|
|
1588
1592
|
##### stack?
|
|
@@ -1591,12 +1595,12 @@ Error.message
|
|
|
1591
1595
|
optional stack: string;
|
|
1592
1596
|
```
|
|
1593
1597
|
|
|
1594
|
-
Defined in:
|
|
1598
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1078
|
|
1595
1599
|
|
|
1596
1600
|
###### Inherited from
|
|
1597
1601
|
|
|
1598
1602
|
```ts
|
|
1599
|
-
Error.stack
|
|
1603
|
+
Error.stack;
|
|
1600
1604
|
```
|
|
1601
1605
|
|
|
1602
1606
|
##### prepareStackTrace()?
|
|
@@ -1605,7 +1609,7 @@ Error.stack
|
|
|
1605
1609
|
static optional prepareStackTrace: (err, stackTraces) => any;
|
|
1606
1610
|
```
|
|
1607
1611
|
|
|
1608
|
-
Defined in:
|
|
1612
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:98
|
|
1609
1613
|
|
|
1610
1614
|
Optional override for formatting stack traces
|
|
1611
1615
|
|
|
@@ -1630,7 +1634,7 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
1630
1634
|
###### Inherited from
|
|
1631
1635
|
|
|
1632
1636
|
```ts
|
|
1633
|
-
Error.prepareStackTrace
|
|
1637
|
+
Error.prepareStackTrace;
|
|
1634
1638
|
```
|
|
1635
1639
|
|
|
1636
1640
|
##### stackTraceLimit
|
|
@@ -1639,19 +1643,19 @@ Error.prepareStackTrace
|
|
|
1639
1643
|
static stackTraceLimit: number;
|
|
1640
1644
|
```
|
|
1641
1645
|
|
|
1642
|
-
Defined in:
|
|
1646
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:100
|
|
1643
1647
|
|
|
1644
1648
|
###### Inherited from
|
|
1645
1649
|
|
|
1646
1650
|
```ts
|
|
1647
|
-
Error.stackTraceLimit
|
|
1651
|
+
Error.stackTraceLimit;
|
|
1648
1652
|
```
|
|
1649
1653
|
|
|
1650
|
-
|
|
1654
|
+
---
|
|
1651
1655
|
|
|
1652
1656
|
### PermissionError
|
|
1653
1657
|
|
|
1654
|
-
Defined in: [packages/fs/src/error/permission-error.ts:34](https://github.com/visulima/visulima/blob/
|
|
1658
|
+
Defined in: [packages/fs/src/error/permission-error.ts:34](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/permission-error.ts#L34)
|
|
1655
1659
|
|
|
1656
1660
|
Error thrown when an operation is not permitted due to insufficient privileges
|
|
1657
1661
|
or other access control restrictions.
|
|
@@ -1664,24 +1668,24 @@ import { writeFile } from "@visulima/fs"; // Or any function that might throw th
|
|
|
1664
1668
|
import { join } from "node:path";
|
|
1665
1669
|
|
|
1666
1670
|
const tryWritingToProtectedFile = async () => {
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1671
|
+
const filePath = join("/root", "protected-file.txt"); // A path that typically requires root privileges
|
|
1672
|
+
try {
|
|
1673
|
+
// Forcing the scenario for demonstration, as writeFile itself would throw this.
|
|
1674
|
+
const simulatePermissionError = (path) => {
|
|
1675
|
+
if (path === filePath) {
|
|
1676
|
+
throw new PermissionError(`open '${filePath}'`);
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1679
|
+
simulatePermissionError(filePath);
|
|
1680
|
+
// await writeFile(filePath, "test content");
|
|
1681
|
+
} catch (error) {
|
|
1682
|
+
if (error instanceof PermissionError) {
|
|
1683
|
+
console.error(`Operation not permitted: ${error.message}`);
|
|
1684
|
+
console.error(`Error code: ${error.code}`); // EPERM
|
|
1685
|
+
} else {
|
|
1686
|
+
console.error("An unexpected error occurred:", error);
|
|
1687
|
+
}
|
|
1683
1688
|
}
|
|
1684
|
-
}
|
|
1685
1689
|
};
|
|
1686
1690
|
|
|
1687
1691
|
tryWritingToProtectedFile();
|
|
@@ -1699,7 +1703,7 @@ tryWritingToProtectedFile();
|
|
|
1699
1703
|
new PermissionError(message): PermissionError;
|
|
1700
1704
|
```
|
|
1701
1705
|
|
|
1702
|
-
Defined in: [packages/fs/src/error/permission-error.ts:39](https://github.com/visulima/visulima/blob/
|
|
1706
|
+
Defined in: [packages/fs/src/error/permission-error.ts:39](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/permission-error.ts#L39)
|
|
1703
1707
|
|
|
1704
1708
|
Creates a new instance.
|
|
1705
1709
|
|
|
@@ -1718,7 +1722,7 @@ The error message.
|
|
|
1718
1722
|
###### Overrides
|
|
1719
1723
|
|
|
1720
1724
|
```ts
|
|
1721
|
-
Error.constructor
|
|
1725
|
+
Error.constructor;
|
|
1722
1726
|
```
|
|
1723
1727
|
|
|
1724
1728
|
#### Accessors
|
|
@@ -1731,7 +1735,7 @@ Error.constructor
|
|
|
1731
1735
|
get code(): string;
|
|
1732
1736
|
```
|
|
1733
1737
|
|
|
1734
|
-
Defined in: [packages/fs/src/error/permission-error.ts:44](https://github.com/visulima/visulima/blob/
|
|
1738
|
+
Defined in: [packages/fs/src/error/permission-error.ts:44](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/permission-error.ts#L44)
|
|
1735
1739
|
|
|
1736
1740
|
###### Returns
|
|
1737
1741
|
|
|
@@ -1743,7 +1747,7 @@ Defined in: [packages/fs/src/error/permission-error.ts:44](https://github.com/vi
|
|
|
1743
1747
|
set code(_name): void;
|
|
1744
1748
|
```
|
|
1745
1749
|
|
|
1746
|
-
Defined in: [packages/fs/src/error/permission-error.ts:49](https://github.com/visulima/visulima/blob/
|
|
1750
|
+
Defined in: [packages/fs/src/error/permission-error.ts:49](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/permission-error.ts#L49)
|
|
1747
1751
|
|
|
1748
1752
|
###### Parameters
|
|
1749
1753
|
|
|
@@ -1763,7 +1767,7 @@ Defined in: [packages/fs/src/error/permission-error.ts:49](https://github.com/vi
|
|
|
1763
1767
|
get name(): string;
|
|
1764
1768
|
```
|
|
1765
1769
|
|
|
1766
|
-
Defined in: [packages/fs/src/error/permission-error.ts:54](https://github.com/visulima/visulima/blob/
|
|
1770
|
+
Defined in: [packages/fs/src/error/permission-error.ts:54](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/permission-error.ts#L54)
|
|
1767
1771
|
|
|
1768
1772
|
###### Returns
|
|
1769
1773
|
|
|
@@ -1775,7 +1779,7 @@ Defined in: [packages/fs/src/error/permission-error.ts:54](https://github.com/vi
|
|
|
1775
1779
|
set name(_name): void;
|
|
1776
1780
|
```
|
|
1777
1781
|
|
|
1778
|
-
Defined in: [packages/fs/src/error/permission-error.ts:59](https://github.com/visulima/visulima/blob/
|
|
1782
|
+
Defined in: [packages/fs/src/error/permission-error.ts:59](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/permission-error.ts#L59)
|
|
1779
1783
|
|
|
1780
1784
|
###### Parameters
|
|
1781
1785
|
|
|
@@ -1790,7 +1794,7 @@ Defined in: [packages/fs/src/error/permission-error.ts:59](https://github.com/vi
|
|
|
1790
1794
|
###### Overrides
|
|
1791
1795
|
|
|
1792
1796
|
```ts
|
|
1793
|
-
Error.name
|
|
1797
|
+
Error.name;
|
|
1794
1798
|
```
|
|
1795
1799
|
|
|
1796
1800
|
#### Methods
|
|
@@ -1801,7 +1805,7 @@ Error.name
|
|
|
1801
1805
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
1802
1806
|
```
|
|
1803
1807
|
|
|
1804
|
-
Defined in:
|
|
1808
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:91
|
|
1805
1809
|
|
|
1806
1810
|
Create .stack property on a target object
|
|
1807
1811
|
|
|
@@ -1822,7 +1826,7 @@ Create .stack property on a target object
|
|
|
1822
1826
|
###### Inherited from
|
|
1823
1827
|
|
|
1824
1828
|
```ts
|
|
1825
|
-
Error.captureStackTrace
|
|
1829
|
+
Error.captureStackTrace;
|
|
1826
1830
|
```
|
|
1827
1831
|
|
|
1828
1832
|
#### Properties
|
|
@@ -1833,12 +1837,12 @@ Error.captureStackTrace
|
|
|
1833
1837
|
optional cause: unknown;
|
|
1834
1838
|
```
|
|
1835
1839
|
|
|
1836
|
-
Defined in:
|
|
1840
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
|
|
1837
1841
|
|
|
1838
1842
|
###### Inherited from
|
|
1839
1843
|
|
|
1840
1844
|
```ts
|
|
1841
|
-
Error.cause
|
|
1845
|
+
Error.cause;
|
|
1842
1846
|
```
|
|
1843
1847
|
|
|
1844
1848
|
##### message
|
|
@@ -1847,12 +1851,12 @@ Error.cause
|
|
|
1847
1851
|
message: string;
|
|
1848
1852
|
```
|
|
1849
1853
|
|
|
1850
|
-
Defined in:
|
|
1854
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1077
|
|
1851
1855
|
|
|
1852
1856
|
###### Inherited from
|
|
1853
1857
|
|
|
1854
1858
|
```ts
|
|
1855
|
-
Error.message
|
|
1859
|
+
Error.message;
|
|
1856
1860
|
```
|
|
1857
1861
|
|
|
1858
1862
|
##### stack?
|
|
@@ -1861,12 +1865,12 @@ Error.message
|
|
|
1861
1865
|
optional stack: string;
|
|
1862
1866
|
```
|
|
1863
1867
|
|
|
1864
|
-
Defined in:
|
|
1868
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1078
|
|
1865
1869
|
|
|
1866
1870
|
###### Inherited from
|
|
1867
1871
|
|
|
1868
1872
|
```ts
|
|
1869
|
-
Error.stack
|
|
1873
|
+
Error.stack;
|
|
1870
1874
|
```
|
|
1871
1875
|
|
|
1872
1876
|
##### prepareStackTrace()?
|
|
@@ -1875,7 +1879,7 @@ Error.stack
|
|
|
1875
1879
|
static optional prepareStackTrace: (err, stackTraces) => any;
|
|
1876
1880
|
```
|
|
1877
1881
|
|
|
1878
|
-
Defined in:
|
|
1882
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:98
|
|
1879
1883
|
|
|
1880
1884
|
Optional override for formatting stack traces
|
|
1881
1885
|
|
|
@@ -1900,7 +1904,7 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
1900
1904
|
###### Inherited from
|
|
1901
1905
|
|
|
1902
1906
|
```ts
|
|
1903
|
-
Error.prepareStackTrace
|
|
1907
|
+
Error.prepareStackTrace;
|
|
1904
1908
|
```
|
|
1905
1909
|
|
|
1906
1910
|
##### stackTraceLimit
|
|
@@ -1909,19 +1913,19 @@ Error.prepareStackTrace
|
|
|
1909
1913
|
static stackTraceLimit: number;
|
|
1910
1914
|
```
|
|
1911
1915
|
|
|
1912
|
-
Defined in:
|
|
1916
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:100
|
|
1913
1917
|
|
|
1914
1918
|
###### Inherited from
|
|
1915
1919
|
|
|
1916
1920
|
```ts
|
|
1917
|
-
Error.stackTraceLimit
|
|
1921
|
+
Error.stackTraceLimit;
|
|
1918
1922
|
```
|
|
1919
1923
|
|
|
1920
|
-
|
|
1924
|
+
---
|
|
1921
1925
|
|
|
1922
1926
|
### WalkError
|
|
1923
1927
|
|
|
1924
|
-
Defined in: [packages/fs/src/error/walk-error.ts:43](https://github.com/visulima/visulima/blob/
|
|
1928
|
+
Defined in: [packages/fs/src/error/walk-error.ts:43](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/walk-error.ts#L43)
|
|
1925
1929
|
|
|
1926
1930
|
Error thrown in walk or walkSync during iteration.
|
|
1927
1931
|
|
|
@@ -1933,30 +1937,30 @@ import { walk } from "@visulima/fs";
|
|
|
1933
1937
|
import { join } from "node:path";
|
|
1934
1938
|
|
|
1935
1939
|
const processDirectory = async () => {
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1940
|
+
const dirToWalk = join("/tmp", "non-existent-or-permission-denied-dir");
|
|
1941
|
+
try {
|
|
1942
|
+
// Forcing the scenario: walk might throw a WalkError if it encounters an issue
|
|
1943
|
+
// like a directory it cannot read during the walk process.
|
|
1944
|
+
const simulateWalkError = async (rootDir) => {
|
|
1945
|
+
// Let's say readdir inside walk fails for a subdirectory.
|
|
1946
|
+
const underlyingError = new Error("Permission denied reading subdirectory");
|
|
1947
|
+
throw new WalkError(underlyingError, rootDir);
|
|
1948
|
+
};
|
|
1949
|
+
// This is conceptual. In a real scenario, 'walk' itself would throw.
|
|
1950
|
+
// for await (const entry of walk(dirToWalk)) {
|
|
1951
|
+
// console.log(entry.path);
|
|
1952
|
+
// }
|
|
1953
|
+
await simulateWalkError(dirToWalk);
|
|
1954
|
+
} catch (error) {
|
|
1955
|
+
if (error instanceof WalkError) {
|
|
1956
|
+
console.error(`Error during directory walk of "${error.root}": ${error.message}`);
|
|
1957
|
+
if (error.cause) {
|
|
1958
|
+
console.error(`Underlying cause: ${error.cause}`);
|
|
1959
|
+
}
|
|
1960
|
+
} else {
|
|
1961
|
+
console.error("An unexpected error occurred:", error);
|
|
1962
|
+
}
|
|
1944
1963
|
}
|
|
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
1964
|
};
|
|
1961
1965
|
|
|
1962
1966
|
processDirectory();
|
|
@@ -1974,7 +1978,7 @@ processDirectory();
|
|
|
1974
1978
|
new WalkError(cause, root): WalkError;
|
|
1975
1979
|
```
|
|
1976
1980
|
|
|
1977
|
-
Defined in: [packages/fs/src/error/walk-error.ts:52](https://github.com/visulima/visulima/blob/
|
|
1981
|
+
Defined in: [packages/fs/src/error/walk-error.ts:52](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/walk-error.ts#L52)
|
|
1978
1982
|
|
|
1979
1983
|
Constructs a new instance.
|
|
1980
1984
|
|
|
@@ -1999,7 +2003,7 @@ The root directory path where the walk operation started or encountered the erro
|
|
|
1999
2003
|
###### Overrides
|
|
2000
2004
|
|
|
2001
2005
|
```ts
|
|
2002
|
-
Error.constructor
|
|
2006
|
+
Error.constructor;
|
|
2003
2007
|
```
|
|
2004
2008
|
|
|
2005
2009
|
#### Accessors
|
|
@@ -2012,7 +2016,7 @@ Error.constructor
|
|
|
2012
2016
|
get name(): string;
|
|
2013
2017
|
```
|
|
2014
2018
|
|
|
2015
|
-
Defined in: [packages/fs/src/error/walk-error.ts:61](https://github.com/visulima/visulima/blob/
|
|
2019
|
+
Defined in: [packages/fs/src/error/walk-error.ts:61](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/walk-error.ts#L61)
|
|
2016
2020
|
|
|
2017
2021
|
###### Returns
|
|
2018
2022
|
|
|
@@ -2024,7 +2028,7 @@ Defined in: [packages/fs/src/error/walk-error.ts:61](https://github.com/visulima
|
|
|
2024
2028
|
set name(_name): void;
|
|
2025
2029
|
```
|
|
2026
2030
|
|
|
2027
|
-
Defined in: [packages/fs/src/error/walk-error.ts:66](https://github.com/visulima/visulima/blob/
|
|
2031
|
+
Defined in: [packages/fs/src/error/walk-error.ts:66](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/walk-error.ts#L66)
|
|
2028
2032
|
|
|
2029
2033
|
###### Parameters
|
|
2030
2034
|
|
|
@@ -2039,7 +2043,7 @@ Defined in: [packages/fs/src/error/walk-error.ts:66](https://github.com/visulima
|
|
|
2039
2043
|
###### Overrides
|
|
2040
2044
|
|
|
2041
2045
|
```ts
|
|
2042
|
-
Error.name
|
|
2046
|
+
Error.name;
|
|
2043
2047
|
```
|
|
2044
2048
|
|
|
2045
2049
|
#### Methods
|
|
@@ -2050,7 +2054,7 @@ Error.name
|
|
|
2050
2054
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
2051
2055
|
```
|
|
2052
2056
|
|
|
2053
|
-
Defined in:
|
|
2057
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:91
|
|
2054
2058
|
|
|
2055
2059
|
Create .stack property on a target object
|
|
2056
2060
|
|
|
@@ -2071,7 +2075,7 @@ Create .stack property on a target object
|
|
|
2071
2075
|
###### Inherited from
|
|
2072
2076
|
|
|
2073
2077
|
```ts
|
|
2074
|
-
Error.captureStackTrace
|
|
2078
|
+
Error.captureStackTrace;
|
|
2075
2079
|
```
|
|
2076
2080
|
|
|
2077
2081
|
#### Properties
|
|
@@ -2082,12 +2086,12 @@ Error.captureStackTrace
|
|
|
2082
2086
|
optional cause: unknown;
|
|
2083
2087
|
```
|
|
2084
2088
|
|
|
2085
|
-
Defined in:
|
|
2089
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
|
|
2086
2090
|
|
|
2087
2091
|
###### Inherited from
|
|
2088
2092
|
|
|
2089
2093
|
```ts
|
|
2090
|
-
Error.cause
|
|
2094
|
+
Error.cause;
|
|
2091
2095
|
```
|
|
2092
2096
|
|
|
2093
2097
|
##### message
|
|
@@ -2096,12 +2100,12 @@ Error.cause
|
|
|
2096
2100
|
message: string;
|
|
2097
2101
|
```
|
|
2098
2102
|
|
|
2099
|
-
Defined in:
|
|
2103
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1077
|
|
2100
2104
|
|
|
2101
2105
|
###### Inherited from
|
|
2102
2106
|
|
|
2103
2107
|
```ts
|
|
2104
|
-
Error.message
|
|
2108
|
+
Error.message;
|
|
2105
2109
|
```
|
|
2106
2110
|
|
|
2107
2111
|
##### root
|
|
@@ -2110,7 +2114,7 @@ Error.message
|
|
|
2110
2114
|
root: string;
|
|
2111
2115
|
```
|
|
2112
2116
|
|
|
2113
|
-
Defined in: [packages/fs/src/error/walk-error.ts:45](https://github.com/visulima/visulima/blob/
|
|
2117
|
+
Defined in: [packages/fs/src/error/walk-error.ts:45](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/walk-error.ts#L45)
|
|
2114
2118
|
|
|
2115
2119
|
File path of the root that's being walked.
|
|
2116
2120
|
|
|
@@ -2120,12 +2124,12 @@ File path of the root that's being walked.
|
|
|
2120
2124
|
optional stack: string;
|
|
2121
2125
|
```
|
|
2122
2126
|
|
|
2123
|
-
Defined in:
|
|
2127
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1078
|
|
2124
2128
|
|
|
2125
2129
|
###### Inherited from
|
|
2126
2130
|
|
|
2127
2131
|
```ts
|
|
2128
|
-
Error.stack
|
|
2132
|
+
Error.stack;
|
|
2129
2133
|
```
|
|
2130
2134
|
|
|
2131
2135
|
##### prepareStackTrace()?
|
|
@@ -2134,7 +2138,7 @@ Error.stack
|
|
|
2134
2138
|
static optional prepareStackTrace: (err, stackTraces) => any;
|
|
2135
2139
|
```
|
|
2136
2140
|
|
|
2137
|
-
Defined in:
|
|
2141
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:98
|
|
2138
2142
|
|
|
2139
2143
|
Optional override for formatting stack traces
|
|
2140
2144
|
|
|
@@ -2159,7 +2163,7 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
2159
2163
|
###### Inherited from
|
|
2160
2164
|
|
|
2161
2165
|
```ts
|
|
2162
|
-
Error.prepareStackTrace
|
|
2166
|
+
Error.prepareStackTrace;
|
|
2163
2167
|
```
|
|
2164
2168
|
|
|
2165
2169
|
##### stackTraceLimit
|
|
@@ -2168,12 +2172,12 @@ Error.prepareStackTrace
|
|
|
2168
2172
|
static stackTraceLimit: number;
|
|
2169
2173
|
```
|
|
2170
2174
|
|
|
2171
|
-
Defined in:
|
|
2175
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:100
|
|
2172
2176
|
|
|
2173
2177
|
###### Inherited from
|
|
2174
2178
|
|
|
2175
2179
|
```ts
|
|
2176
|
-
Error.stackTraceLimit
|
|
2180
|
+
Error.stackTraceLimit;
|
|
2177
2181
|
```
|
|
2178
2182
|
|
|
2179
2183
|
## References
|
|
@@ -2181,6 +2185,7 @@ Error.stackTraceLimit
|
|
|
2181
2185
|
### JSONError
|
|
2182
2186
|
|
|
2183
2187
|
Re-exports [JSONError](utils.md#jsonerror)
|
|
2188
|
+
|
|
2184
2189
|
# index
|
|
2185
2190
|
|
|
2186
2191
|
## Functions
|
|
@@ -2191,7 +2196,7 @@ Re-exports [JSONError](utils.md#jsonerror)
|
|
|
2191
2196
|
function collect(directory, options): Promise<string[]>;
|
|
2192
2197
|
```
|
|
2193
2198
|
|
|
2194
|
-
Defined in: [packages/fs/src/find/collect.ts:37](https://github.com/visulima/visulima/blob/
|
|
2199
|
+
Defined in: [packages/fs/src/find/collect.ts:37](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/find/collect.ts#L37)
|
|
2195
2200
|
|
|
2196
2201
|
Asynchronously collects all file paths within a directory that match the specified criteria.
|
|
2197
2202
|
By default, it searches for JavaScript and TypeScript file extensions.
|
|
@@ -2223,27 +2228,27 @@ import { collect } from "@visulima/fs";
|
|
|
2223
2228
|
import { join } from "node:path";
|
|
2224
2229
|
|
|
2225
2230
|
const collectFiles = async () => {
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2231
|
+
// Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
|
|
2232
|
+
const files = await collect(join("/tmp", "docs"), {
|
|
2233
|
+
extensions: ["txt", "md"],
|
|
2234
|
+
maxDepth: 2,
|
|
2235
|
+
includeDirs: false, // Only collect files
|
|
2236
|
+
});
|
|
2237
|
+
console.log(files);
|
|
2238
|
+
// Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
|
|
2234
2239
|
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2240
|
+
// Collect all .js files, excluding anything in node_modules
|
|
2241
|
+
const jsFiles = await collect(join("/tmp", "project"), {
|
|
2242
|
+
extensions: ["js"],
|
|
2243
|
+
skip: [/node_modules/],
|
|
2244
|
+
});
|
|
2245
|
+
console.log(jsFiles);
|
|
2241
2246
|
};
|
|
2242
2247
|
|
|
2243
2248
|
collectFiles();
|
|
2244
2249
|
```
|
|
2245
2250
|
|
|
2246
|
-
|
|
2251
|
+
---
|
|
2247
2252
|
|
|
2248
2253
|
### collectSync()
|
|
2249
2254
|
|
|
@@ -2251,7 +2256,7 @@ collectFiles();
|
|
|
2251
2256
|
function collectSync(directory, options): string[];
|
|
2252
2257
|
```
|
|
2253
2258
|
|
|
2254
|
-
Defined in: [packages/fs/src/find/collect-sync.ts:33](https://github.com/visulima/visulima/blob/
|
|
2259
|
+
Defined in: [packages/fs/src/find/collect-sync.ts:33](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/find/collect-sync.ts#L33)
|
|
2255
2260
|
|
|
2256
2261
|
Synchronously collects all file paths within a directory that match the specified criteria.
|
|
2257
2262
|
By default, it searches for JavaScript and TypeScript file extensions.
|
|
@@ -2284,22 +2289,22 @@ import { join } from "node:path";
|
|
|
2284
2289
|
|
|
2285
2290
|
// Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
|
|
2286
2291
|
const files = collectSync(join("/tmp", "docs"), {
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2292
|
+
extensions: ["txt", "md"],
|
|
2293
|
+
maxDepth: 2,
|
|
2294
|
+
includeDirs: false, // Only collect files
|
|
2290
2295
|
});
|
|
2291
2296
|
console.log(files);
|
|
2292
2297
|
// Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
|
|
2293
2298
|
|
|
2294
2299
|
// Collect all .js files, excluding anything in node_modules
|
|
2295
2300
|
const jsFiles = collectSync(join("/tmp", "project"), {
|
|
2296
|
-
|
|
2297
|
-
|
|
2301
|
+
extensions: ["js"],
|
|
2302
|
+
skip: [/node_modules/],
|
|
2298
2303
|
});
|
|
2299
2304
|
console.log(jsFiles);
|
|
2300
2305
|
```
|
|
2301
2306
|
|
|
2302
|
-
|
|
2307
|
+
---
|
|
2303
2308
|
|
|
2304
2309
|
### emptyDir()
|
|
2305
2310
|
|
|
@@ -2307,7 +2312,7 @@ console.log(jsFiles);
|
|
|
2307
2312
|
function emptyDir(dir, options?): Promise<void>;
|
|
2308
2313
|
```
|
|
2309
2314
|
|
|
2310
|
-
Defined in: [packages/fs/src/remove/empty-dir.ts:
|
|
2315
|
+
Defined in: [packages/fs/src/remove/empty-dir.ts:38](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/remove/empty-dir.ts#L38)
|
|
2311
2316
|
|
|
2312
2317
|
Ensures that a directory is empty.
|
|
2313
2318
|
Deletes directory contents if the directory is not empty.
|
|
@@ -2341,18 +2346,18 @@ import { emptyDir } from "@visulima/fs";
|
|
|
2341
2346
|
import { join } from "node:path";
|
|
2342
2347
|
|
|
2343
2348
|
const clearTempDir = async () => {
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2349
|
+
try {
|
|
2350
|
+
await emptyDir(join("/tmp", "my-app-temp"));
|
|
2351
|
+
console.log("Temporary directory emptied or created.");
|
|
2352
|
+
} catch (error) {
|
|
2353
|
+
console.error("Failed to empty directory:", error);
|
|
2354
|
+
}
|
|
2350
2355
|
};
|
|
2351
2356
|
|
|
2352
2357
|
clearTempDir();
|
|
2353
2358
|
```
|
|
2354
2359
|
|
|
2355
|
-
|
|
2360
|
+
---
|
|
2356
2361
|
|
|
2357
2362
|
### emptyDirSync()
|
|
2358
2363
|
|
|
@@ -2360,7 +2365,7 @@ clearTempDir();
|
|
|
2360
2365
|
function emptyDirSync(dir, options?): void;
|
|
2361
2366
|
```
|
|
2362
2367
|
|
|
2363
|
-
Defined in: [packages/fs/src/remove/empty-dir-sync.ts:
|
|
2368
|
+
Defined in: [packages/fs/src/remove/empty-dir-sync.ts:33](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/remove/empty-dir-sync.ts#L33)
|
|
2364
2369
|
|
|
2365
2370
|
Ensures that a directory is empty.
|
|
2366
2371
|
Deletes directory contents if the directory is not empty.
|
|
@@ -2394,14 +2399,14 @@ import { emptyDirSync } from "@visulima/fs";
|
|
|
2394
2399
|
import { join } from "node:path";
|
|
2395
2400
|
|
|
2396
2401
|
try {
|
|
2397
|
-
|
|
2398
|
-
|
|
2402
|
+
emptyDirSync(join("/tmp", "my-app-temp"));
|
|
2403
|
+
console.log("Temporary directory emptied or created.");
|
|
2399
2404
|
} catch (error) {
|
|
2400
|
-
|
|
2405
|
+
console.error("Failed to empty directory:", error);
|
|
2401
2406
|
}
|
|
2402
2407
|
```
|
|
2403
2408
|
|
|
2404
|
-
|
|
2409
|
+
---
|
|
2405
2410
|
|
|
2406
2411
|
### ensureDir()
|
|
2407
2412
|
|
|
@@ -2409,7 +2414,7 @@ try {
|
|
|
2409
2414
|
function ensureDir(directory): Promise<void>;
|
|
2410
2415
|
```
|
|
2411
2416
|
|
|
2412
|
-
Defined in: [packages/fs/src/ensure/ensure-dir.ts:20](https://github.com/visulima/visulima/blob/
|
|
2417
|
+
Defined in: [packages/fs/src/ensure/ensure-dir.ts:20](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/ensure/ensure-dir.ts#L20)
|
|
2413
2418
|
|
|
2414
2419
|
Ensures that the directory exists.
|
|
2415
2420
|
If the directory structure does not exist, it is created. Like mkdir -p.
|
|
@@ -2435,7 +2440,7 @@ await ensureDir("/tmp/foo/bar/baz");
|
|
|
2435
2440
|
// Creates the directory structure /tmp/foo/bar/baz if it doesn't exist
|
|
2436
2441
|
```
|
|
2437
2442
|
|
|
2438
|
-
|
|
2443
|
+
---
|
|
2439
2444
|
|
|
2440
2445
|
### ensureDirSync()
|
|
2441
2446
|
|
|
@@ -2443,7 +2448,7 @@ await ensureDir("/tmp/foo/bar/baz");
|
|
|
2443
2448
|
function ensureDirSync(directory): void;
|
|
2444
2449
|
```
|
|
2445
2450
|
|
|
2446
|
-
Defined in: [packages/fs/src/ensure/ensure-dir-sync.ts:20](https://github.com/visulima/visulima/blob/
|
|
2451
|
+
Defined in: [packages/fs/src/ensure/ensure-dir-sync.ts:20](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/ensure/ensure-dir-sync.ts#L20)
|
|
2447
2452
|
|
|
2448
2453
|
Ensures that the directory exists.
|
|
2449
2454
|
If the directory structure does not exist, it is created. Like mkdir -p.
|
|
@@ -2469,7 +2474,7 @@ ensureDirSync("/tmp/foo/bar/baz");
|
|
|
2469
2474
|
// Creates the directory structure /tmp/foo/bar/baz if it doesn't exist
|
|
2470
2475
|
```
|
|
2471
2476
|
|
|
2472
|
-
|
|
2477
|
+
---
|
|
2473
2478
|
|
|
2474
2479
|
### ensureFile()
|
|
2475
2480
|
|
|
@@ -2477,7 +2482,7 @@ ensureDirSync("/tmp/foo/bar/baz");
|
|
|
2477
2482
|
function ensureFile(filePath): Promise<void>;
|
|
2478
2483
|
```
|
|
2479
2484
|
|
|
2480
|
-
Defined in: [packages/fs/src/ensure/ensure-file.ts:37](https://github.com/visulima/visulima/blob/
|
|
2485
|
+
Defined in: [packages/fs/src/ensure/ensure-file.ts:37](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/ensure/ensure-file.ts#L37)
|
|
2481
2486
|
|
|
2482
2487
|
Asynchronously ensures that a file exists.
|
|
2483
2488
|
If the directory structure for the file does not exist, it is created.
|
|
@@ -2511,19 +2516,19 @@ Will throw an error if directory or file creation fails for reasons other than t
|
|
|
2511
2516
|
import { ensureFile } from "@visulima/fs";
|
|
2512
2517
|
|
|
2513
2518
|
(async () => {
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2519
|
+
try {
|
|
2520
|
+
await ensureFile("path/to/my/file.txt");
|
|
2521
|
+
console.log("File ensured!");
|
|
2522
|
+
|
|
2523
|
+
await ensureFile(new URL("file:///path/to/another/file.log"));
|
|
2524
|
+
console.log("Another file ensured!");
|
|
2525
|
+
} catch (error) {
|
|
2526
|
+
console.error("Failed to ensure file:", error);
|
|
2527
|
+
}
|
|
2523
2528
|
})();
|
|
2524
2529
|
```
|
|
2525
2530
|
|
|
2526
|
-
|
|
2531
|
+
---
|
|
2527
2532
|
|
|
2528
2533
|
### ensureFileSync()
|
|
2529
2534
|
|
|
@@ -2531,7 +2536,7 @@ import { ensureFile } from "@visulima/fs";
|
|
|
2531
2536
|
function ensureFileSync(filePath): void;
|
|
2532
2537
|
```
|
|
2533
2538
|
|
|
2534
|
-
Defined in: [packages/fs/src/ensure/ensure-file-sync.ts:24](https://github.com/visulima/visulima/blob/
|
|
2539
|
+
Defined in: [packages/fs/src/ensure/ensure-file-sync.ts:24](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/ensure/ensure-file-sync.ts#L24)
|
|
2535
2540
|
|
|
2536
2541
|
Ensures that the file exists.
|
|
2537
2542
|
If the file that is requested to be created is in directories that do not exist,
|
|
@@ -2558,7 +2563,7 @@ ensureFileSync("/tmp/foo/bar/baz.txt");
|
|
|
2558
2563
|
// Creates the file /tmp/foo/bar/baz.txt and any missing parent directories if they don't exist
|
|
2559
2564
|
```
|
|
2560
2565
|
|
|
2561
|
-
|
|
2566
|
+
---
|
|
2562
2567
|
|
|
2563
2568
|
### ensureLink()
|
|
2564
2569
|
|
|
@@ -2566,7 +2571,7 @@ ensureFileSync("/tmp/foo/bar/baz.txt");
|
|
|
2566
2571
|
function ensureLink(source, destination): Promise<void>;
|
|
2567
2572
|
```
|
|
2568
2573
|
|
|
2569
|
-
Defined in: [packages/fs/src/ensure/ensure-link.ts:25](https://github.com/visulima/visulima/blob/
|
|
2574
|
+
Defined in: [packages/fs/src/ensure/ensure-link.ts:25](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/ensure/ensure-link.ts#L25)
|
|
2570
2575
|
|
|
2571
2576
|
Ensures that the hard link exists.
|
|
2572
2577
|
If the directory structure does not exist, it is created.
|
|
@@ -2599,7 +2604,7 @@ import { join } from "node:path";
|
|
|
2599
2604
|
await ensureLink(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "bar-link.txt"));
|
|
2600
2605
|
```
|
|
2601
2606
|
|
|
2602
|
-
|
|
2607
|
+
---
|
|
2603
2608
|
|
|
2604
2609
|
### ensureLinkSync()
|
|
2605
2610
|
|
|
@@ -2607,7 +2612,7 @@ await ensureLink(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "bar-link.t
|
|
|
2607
2612
|
function ensureLinkSync(source, destination): void;
|
|
2608
2613
|
```
|
|
2609
2614
|
|
|
2610
|
-
Defined in: [packages/fs/src/ensure/ensure-link-sync.ts:25](https://github.com/visulima/visulima/blob/
|
|
2615
|
+
Defined in: [packages/fs/src/ensure/ensure-link-sync.ts:25](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/ensure/ensure-link-sync.ts#L25)
|
|
2611
2616
|
|
|
2612
2617
|
Ensures that the hard link exists.
|
|
2613
2618
|
If the directory structure does not exist, it is created.
|
|
@@ -2640,18 +2645,15 @@ import { join } from "node:path";
|
|
|
2640
2645
|
ensureLinkSync(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "bar-link.txt"));
|
|
2641
2646
|
```
|
|
2642
2647
|
|
|
2643
|
-
|
|
2648
|
+
---
|
|
2644
2649
|
|
|
2645
2650
|
### ensureSymlink()
|
|
2646
2651
|
|
|
2647
2652
|
```ts
|
|
2648
|
-
function ensureSymlink(
|
|
2649
|
-
target,
|
|
2650
|
-
linkName,
|
|
2651
|
-
type?): Promise<void>;
|
|
2653
|
+
function ensureSymlink(target, linkName, type?): Promise<void>;
|
|
2652
2654
|
```
|
|
2653
2655
|
|
|
2654
|
-
Defined in: [packages/fs/src/ensure/ensure-symlink.ts:39](https://github.com/visulima/visulima/blob/
|
|
2656
|
+
Defined in: [packages/fs/src/ensure/ensure-symlink.ts:39](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/ensure/ensure-symlink.ts#L39)
|
|
2655
2657
|
|
|
2656
2658
|
Ensures that the link exists, and points to a valid file.
|
|
2657
2659
|
If the directory structure does not exist, it is created.
|
|
@@ -2696,18 +2698,15 @@ await ensureSymlink(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "link-to
|
|
|
2696
2698
|
await ensureSymlink(join("/tmp", "foo", "baz-dir"), join("/tmp", "foo", "link-to-baz-dir"), "dir");
|
|
2697
2699
|
```
|
|
2698
2700
|
|
|
2699
|
-
|
|
2701
|
+
---
|
|
2700
2702
|
|
|
2701
2703
|
### ensureSymlinkSync()
|
|
2702
2704
|
|
|
2703
2705
|
```ts
|
|
2704
|
-
function ensureSymlinkSync(
|
|
2705
|
-
target,
|
|
2706
|
-
linkName,
|
|
2707
|
-
type?): void;
|
|
2706
|
+
function ensureSymlinkSync(target, linkName, type?): void;
|
|
2708
2707
|
```
|
|
2709
2708
|
|
|
2710
|
-
Defined in: [packages/fs/src/ensure/ensure-symlink-sync.ts:39](https://github.com/visulima/visulima/blob/
|
|
2709
|
+
Defined in: [packages/fs/src/ensure/ensure-symlink-sync.ts:39](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/ensure/ensure-symlink-sync.ts#L39)
|
|
2711
2710
|
|
|
2712
2711
|
Ensures that the link exists, and points to a valid file.
|
|
2713
2712
|
If the directory structure does not exist, it is created.
|
|
@@ -2752,7 +2751,7 @@ ensureSymlinkSync(join("/tmp", "foo", "bar.txt"), join("/tmp", "foo", "link-to-b
|
|
|
2752
2751
|
ensureSymlinkSync(join("/tmp", "foo", "baz-dir"), join("/tmp", "foo", "link-to-baz-dir"), "dir");
|
|
2753
2752
|
```
|
|
2754
2753
|
|
|
2755
|
-
|
|
2754
|
+
---
|
|
2756
2755
|
|
|
2757
2756
|
### findUp()
|
|
2758
2757
|
|
|
@@ -2760,7 +2759,7 @@ ensureSymlinkSync(join("/tmp", "foo", "baz-dir"), join("/tmp", "foo", "link-to-b
|
|
|
2760
2759
|
function findUp(name, options): Promise<string>;
|
|
2761
2760
|
```
|
|
2762
2761
|
|
|
2763
|
-
Defined in: [packages/fs/src/find/find-up.ts:55](https://github.com/visulima/visulima/blob/
|
|
2762
|
+
Defined in: [packages/fs/src/find/find-up.ts:55](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/find/find-up.ts#L55)
|
|
2764
2763
|
|
|
2765
2764
|
Asynchronously finds a file or directory by walking up parent directories.
|
|
2766
2765
|
|
|
@@ -2791,39 +2790,39 @@ import { findUp } from "@visulima/fs";
|
|
|
2791
2790
|
import { join } from "node:path";
|
|
2792
2791
|
|
|
2793
2792
|
const findProjectRoot = async () => {
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
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);
|
|
2793
|
+
// Find the closest package.json, starting from /tmp/foo/bar/baz
|
|
2794
|
+
const projectRoot = await findUp("package.json", {
|
|
2795
|
+
cwd: join("/tmp", "foo", "bar", "baz"),
|
|
2796
|
+
type: "file",
|
|
2797
|
+
});
|
|
2798
|
+
console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
|
|
2806
2799
|
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2800
|
+
// Find the closest .git directory or a README.md file
|
|
2801
|
+
const gitDirOrReadme = await findUp([".git", "README.md"], {
|
|
2802
|
+
cwd: join("/tmp", "foo", "bar"),
|
|
2803
|
+
});
|
|
2804
|
+
console.log(gitDirOrReadme);
|
|
2805
|
+
|
|
2806
|
+
// Find using a custom function, stopping at /tmp
|
|
2807
|
+
const customFound = await findUp(
|
|
2808
|
+
(directory) => {
|
|
2809
|
+
if (directory === join("/tmp", "foo")) {
|
|
2810
|
+
return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
|
|
2811
|
+
}
|
|
2812
|
+
return undefined;
|
|
2813
|
+
},
|
|
2814
|
+
{
|
|
2815
|
+
cwd: join("/tmp", "foo", "bar", "baz"),
|
|
2816
|
+
stopAt: join("/tmp"),
|
|
2817
|
+
},
|
|
2818
|
+
);
|
|
2819
|
+
console.log(customFound);
|
|
2821
2820
|
};
|
|
2822
2821
|
|
|
2823
2822
|
findProjectRoot();
|
|
2824
2823
|
```
|
|
2825
2824
|
|
|
2826
|
-
|
|
2825
|
+
---
|
|
2827
2826
|
|
|
2828
2827
|
### findUpSync()
|
|
2829
2828
|
|
|
@@ -2831,7 +2830,7 @@ findProjectRoot();
|
|
|
2831
2830
|
function findUpSync(name, options): string;
|
|
2832
2831
|
```
|
|
2833
2832
|
|
|
2834
|
-
Defined in: [packages/fs/src/find/find-up-sync.ts:51](https://github.com/visulima/visulima/blob/
|
|
2833
|
+
Defined in: [packages/fs/src/find/find-up-sync.ts:51](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/find/find-up-sync.ts#L51)
|
|
2835
2834
|
|
|
2836
2835
|
Synchronously finds a file or directory by walking up parent directories.
|
|
2837
2836
|
|
|
@@ -2863,34 +2862,34 @@ import { join } from "node:path";
|
|
|
2863
2862
|
|
|
2864
2863
|
// Find the closest package.json, starting from /tmp/foo/bar/baz
|
|
2865
2864
|
const projectRoot = findUpSync("package.json", {
|
|
2866
|
-
|
|
2867
|
-
|
|
2865
|
+
cwd: join("/tmp", "foo", "bar", "baz"),
|
|
2866
|
+
type: "file",
|
|
2868
2867
|
});
|
|
2869
2868
|
console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
|
|
2870
2869
|
|
|
2871
2870
|
// Find the closest .git directory or a README.md file
|
|
2872
2871
|
const gitDirOrReadme = findUpSync([".git", "README.md"], {
|
|
2873
|
-
|
|
2872
|
+
cwd: join("/tmp", "foo", "bar"),
|
|
2874
2873
|
});
|
|
2875
2874
|
console.log(gitDirOrReadme);
|
|
2876
2875
|
|
|
2877
2876
|
// Find using a custom function, stopping at /tmp
|
|
2878
2877
|
const customFound = findUpSync(
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2878
|
+
(directory) => {
|
|
2879
|
+
if (directory === join("/tmp", "foo")) {
|
|
2880
|
+
return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
|
|
2881
|
+
}
|
|
2882
|
+
return undefined;
|
|
2883
|
+
},
|
|
2884
|
+
{
|
|
2885
|
+
cwd: join("/tmp", "foo", "bar", "baz"),
|
|
2886
|
+
stopAt: join("/tmp"),
|
|
2887
|
+
},
|
|
2889
2888
|
);
|
|
2890
2889
|
console.log(customFound);
|
|
2891
2890
|
```
|
|
2892
2891
|
|
|
2893
|
-
|
|
2892
|
+
---
|
|
2894
2893
|
|
|
2895
2894
|
### isAccessible()
|
|
2896
2895
|
|
|
@@ -2898,7 +2897,7 @@ console.log(customFound);
|
|
|
2898
2897
|
function isAccessible(path, mode?): Promise<boolean>;
|
|
2899
2898
|
```
|
|
2900
2899
|
|
|
2901
|
-
Defined in: [packages/fs/src/is-accessible.ts:36](https://github.com/visulima/visulima/blob/
|
|
2900
|
+
Defined in: [packages/fs/src/is-accessible.ts:36](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/is-accessible.ts#L36)
|
|
2902
2901
|
|
|
2903
2902
|
Asynchronously tests a user's permissions for the file or directory specified by path.
|
|
2904
2903
|
Returns a Promise that resolves to `true` if the accessibility check is successful, `false` otherwise.
|
|
@@ -2916,8 +2915,8 @@ The path to the file or directory. Can be a string or a URL object.
|
|
|
2916
2915
|
`number`
|
|
2917
2916
|
|
|
2918
2917
|
The accessibility checks to perform. Defaults to `F_OK` (check for existence).
|
|
2919
|
-
|
|
2920
|
-
|
|
2918
|
+
Other possible values include `R_OK` (check for read access), `W_OK` (check for write access),
|
|
2919
|
+
and `X_OK` (check for execute/search access). Multiple modes can be combined using bitwise OR.
|
|
2921
2920
|
|
|
2922
2921
|
#### Returns
|
|
2923
2922
|
|
|
@@ -2931,21 +2930,21 @@ A Promise that resolves to a boolean indicating if the path is accessible with t
|
|
|
2931
2930
|
import { isAccessible, F_OK, R_OK } from "@visulima/fs";
|
|
2932
2931
|
|
|
2933
2932
|
(async () => {
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2933
|
+
if (await isAccessible("myFile.txt")) {
|
|
2934
|
+
console.log("myFile.txt exists");
|
|
2935
|
+
}
|
|
2937
2936
|
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2937
|
+
if (await isAccessible("myFile.txt", R_OK)) {
|
|
2938
|
+
console.log("myFile.txt is readable");
|
|
2939
|
+
}
|
|
2941
2940
|
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2941
|
+
if (await isAccessible("myDirectory", F_OK | R_OK | W_OK)) {
|
|
2942
|
+
console.log("myDirectory exists, is readable and writable");
|
|
2943
|
+
}
|
|
2945
2944
|
})();
|
|
2946
2945
|
```
|
|
2947
2946
|
|
|
2948
|
-
|
|
2947
|
+
---
|
|
2949
2948
|
|
|
2950
2949
|
### isAccessibleSync()
|
|
2951
2950
|
|
|
@@ -2953,7 +2952,7 @@ import { isAccessible, F_OK, R_OK } from "@visulima/fs";
|
|
|
2953
2952
|
function isAccessibleSync(path, mode?): boolean;
|
|
2954
2953
|
```
|
|
2955
2954
|
|
|
2956
|
-
Defined in: [packages/fs/src/is-accessible-sync.ts:9](https://github.com/visulima/visulima/blob/
|
|
2955
|
+
Defined in: [packages/fs/src/is-accessible-sync.ts:9](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/is-accessible-sync.ts#L9)
|
|
2957
2956
|
|
|
2958
2957
|
Synchronously tests a user's permissions for the file or directory specified by `path`.
|
|
2959
2958
|
If the accessibility check is successful, `true` is returned. Otherwise, `false` is returned.
|
|
@@ -2981,8 +2980,8 @@ A path to a file or directory. If a URL is provided, it must use the `file:` pro
|
|
|
2981
2980
|
#### Param
|
|
2982
2981
|
|
|
2983
2982
|
The accessibility checks to perform. Default: `F_OK` (tests for existence of the file).
|
|
2984
|
-
|
|
2985
|
-
|
|
2983
|
+
Other possible values are `R_OK` (tests for read permission), `W_OK` (tests for write permission),
|
|
2984
|
+
and `X_OK` (tests for execute permissions). Multiple modes can be combined using bitwise OR.
|
|
2986
2985
|
|
|
2987
2986
|
#### Example
|
|
2988
2987
|
|
|
@@ -3019,18 +3018,15 @@ console.log(`URL exists: ${isAccessibleSync(fileUrl)}`); // true
|
|
|
3019
3018
|
unlinkSync(filePath);
|
|
3020
3019
|
```
|
|
3021
3020
|
|
|
3022
|
-
|
|
3021
|
+
---
|
|
3023
3022
|
|
|
3024
3023
|
### move()
|
|
3025
3024
|
|
|
3026
3025
|
```ts
|
|
3027
|
-
function move(
|
|
3028
|
-
sourcePath,
|
|
3029
|
-
destinationPath,
|
|
3030
|
-
options): Promise<void>;
|
|
3026
|
+
function move(sourcePath, destinationPath, options): Promise<void>;
|
|
3031
3027
|
```
|
|
3032
3028
|
|
|
3033
|
-
Defined in: [packages/fs/src/move/index.ts:35](https://github.com/visulima/visulima/blob/
|
|
3029
|
+
Defined in: [packages/fs/src/move/index.ts:35](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/move/index.ts#L35)
|
|
3034
3030
|
|
|
3035
3031
|
Move a file asynchronously.
|
|
3036
3032
|
|
|
@@ -3069,18 +3065,15 @@ await move('source/test.png', 'destination/test.png');
|
|
|
3069
3065
|
console.log('The file has been moved');
|
|
3070
3066
|
```
|
|
3071
3067
|
|
|
3072
|
-
|
|
3068
|
+
---
|
|
3073
3069
|
|
|
3074
3070
|
### moveSync()
|
|
3075
3071
|
|
|
3076
3072
|
```ts
|
|
3077
|
-
function moveSync(
|
|
3078
|
-
sourcePath,
|
|
3079
|
-
destinationPath,
|
|
3080
|
-
options?): void;
|
|
3073
|
+
function moveSync(sourcePath, destinationPath, options?): void;
|
|
3081
3074
|
```
|
|
3082
3075
|
|
|
3083
|
-
Defined in: [packages/fs/src/move/index.ts:61](https://github.com/visulima/visulima/blob/
|
|
3076
|
+
Defined in: [packages/fs/src/move/index.ts:61](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/move/index.ts#L61)
|
|
3084
3077
|
|
|
3085
3078
|
Move a file synchronously.
|
|
3086
3079
|
|
|
@@ -3119,7 +3112,7 @@ moveSync('source/test.png', 'destination/test.png');
|
|
|
3119
3112
|
console.log('The file has been moved');
|
|
3120
3113
|
```
|
|
3121
3114
|
|
|
3122
|
-
|
|
3115
|
+
---
|
|
3123
3116
|
|
|
3124
3117
|
### readFile()
|
|
3125
3118
|
|
|
@@ -3127,7 +3120,7 @@ console.log('The file has been moved');
|
|
|
3127
3120
|
function readFile<O>(path, options?): Promise<ContentType<O>>;
|
|
3128
3121
|
```
|
|
3129
3122
|
|
|
3130
|
-
Defined in: [packages/fs/src/read/read-file.ts:57](https://github.com/visulima/visulima/blob/
|
|
3123
|
+
Defined in: [packages/fs/src/read/read-file.ts:57](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/read/read-file.ts#L57)
|
|
3131
3124
|
|
|
3132
3125
|
Asynchronously reads the entire contents of a file.
|
|
3133
3126
|
It can also decompress the file content if a `compression` option is provided.
|
|
@@ -3136,7 +3129,7 @@ It can also decompress the file content if a `compression` option is provided.
|
|
|
3136
3129
|
|
|
3137
3130
|
##### O
|
|
3138
3131
|
|
|
3139
|
-
`O`
|
|
3132
|
+
`O` _extends_ [`ReadFileOptions`](#readfileoptions)\<`"brotli"` \| `"gzip"` \| `"none"`\> = `undefined`
|
|
3140
3133
|
|
|
3141
3134
|
The type of the options object, extending [ReadFileOptions](#readfileoptions).
|
|
3142
3135
|
|
|
@@ -3153,14 +3146,14 @@ The path to the file to read. Can be a file URL or a string path.
|
|
|
3153
3146
|
`O`
|
|
3154
3147
|
|
|
3155
3148
|
Optional configuration for reading the file. See [ReadFileOptions](#readfileoptions).
|
|
3156
|
-
|
|
3149
|
+
Available `compression` methods: "brotli", "gzip", "none" (default).
|
|
3157
3150
|
|
|
3158
3151
|
#### Returns
|
|
3159
3152
|
|
|
3160
3153
|
`Promise`\<[`ContentType`](#contenttype)\<`O`\>\>
|
|
3161
3154
|
|
|
3162
3155
|
A promise that resolves with the file content. The type of the content (string or Buffer)
|
|
3163
|
-
|
|
3156
|
+
depends on the `buffer` option (defaults to string if `buffer` is false or not set).
|
|
3164
3157
|
|
|
3165
3158
|
#### Example
|
|
3166
3159
|
|
|
@@ -3169,28 +3162,28 @@ import { readFile } from "@visulima/fs";
|
|
|
3169
3162
|
import { join } from "node:path";
|
|
3170
3163
|
|
|
3171
3164
|
const readMyFile = async () => {
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3165
|
+
try {
|
|
3166
|
+
// Read a regular text file
|
|
3167
|
+
const content = await readFile(join("path", "to", "my-file.txt"));
|
|
3168
|
+
console.log("File content:", content);
|
|
3169
|
+
|
|
3170
|
+
// Read a file as a Buffer
|
|
3171
|
+
const bufferContent = await readFile(join("path", "to", "another-file.bin"), { buffer: true });
|
|
3172
|
+
console.log("Buffer length:", bufferContent.length);
|
|
3173
|
+
|
|
3174
|
+
// Read and decompress a gzipped file
|
|
3175
|
+
// Assume my-archive.txt.gz exists
|
|
3176
|
+
// const decompressedContent = await readFile(join("path", "to", "my-archive.txt.gz"), { compression: "gzip", encoding: "utf8" });
|
|
3177
|
+
// console.log("Decompressed content:", decompressedContent);
|
|
3178
|
+
} catch (error) {
|
|
3179
|
+
console.error("Failed to read file:", error);
|
|
3180
|
+
}
|
|
3188
3181
|
};
|
|
3189
3182
|
|
|
3190
3183
|
readMyFile();
|
|
3191
3184
|
```
|
|
3192
3185
|
|
|
3193
|
-
|
|
3186
|
+
---
|
|
3194
3187
|
|
|
3195
3188
|
### readFileSync()
|
|
3196
3189
|
|
|
@@ -3198,7 +3191,7 @@ readMyFile();
|
|
|
3198
3191
|
function readFileSync<O>(path, options?): ContentType<O>;
|
|
3199
3192
|
```
|
|
3200
3193
|
|
|
3201
|
-
Defined in: [packages/fs/src/read/read-file-sync.ts:51](https://github.com/visulima/visulima/blob/
|
|
3194
|
+
Defined in: [packages/fs/src/read/read-file-sync.ts:51](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/read/read-file-sync.ts#L51)
|
|
3202
3195
|
|
|
3203
3196
|
Synchronously reads the entire contents of a file.
|
|
3204
3197
|
It can also decompress the file content if a `compression` option is provided.
|
|
@@ -3207,7 +3200,7 @@ It can also decompress the file content if a `compression` option is provided.
|
|
|
3207
3200
|
|
|
3208
3201
|
##### O
|
|
3209
3202
|
|
|
3210
|
-
`O`
|
|
3203
|
+
`O` _extends_ [`ReadFileOptions`](#readfileoptions)\<`"brotli"` \| `"gzip"` \| `"none"`\> = `undefined`
|
|
3211
3204
|
|
|
3212
3205
|
The type of the options object, extending [ReadFileOptions](#readfileoptions).
|
|
3213
3206
|
|
|
@@ -3224,14 +3217,14 @@ The path to the file to read. Can be a file URL or a string path.
|
|
|
3224
3217
|
`O`
|
|
3225
3218
|
|
|
3226
3219
|
Optional configuration for reading the file. See [ReadFileOptions](#readfileoptions).
|
|
3227
|
-
|
|
3220
|
+
Available `compression` methods: "brotli", "gzip", "none" (default).
|
|
3228
3221
|
|
|
3229
3222
|
#### Returns
|
|
3230
3223
|
|
|
3231
3224
|
[`ContentType`](#contenttype)\<`O`\>
|
|
3232
3225
|
|
|
3233
3226
|
The file content. The type of the content (string or Buffer)
|
|
3234
|
-
|
|
3227
|
+
depends on the `buffer` option (defaults to string if `buffer` is false or not set).
|
|
3235
3228
|
|
|
3236
3229
|
#### Example
|
|
3237
3230
|
|
|
@@ -3240,24 +3233,24 @@ import { readFileSync } from "@visulima/fs";
|
|
|
3240
3233
|
import { join } from "node:path";
|
|
3241
3234
|
|
|
3242
3235
|
try {
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3236
|
+
// Read a regular text file
|
|
3237
|
+
const content = readFileSync(join("path", "to", "my-file.txt"));
|
|
3238
|
+
console.log("File content:", content);
|
|
3239
|
+
|
|
3240
|
+
// Read a file as a Buffer
|
|
3241
|
+
const bufferContent = readFileSync(join("path", "to", "another-file.bin"), { buffer: true });
|
|
3242
|
+
console.log("Buffer length:", bufferContent.length);
|
|
3243
|
+
|
|
3244
|
+
// Read and decompress a gzipped file
|
|
3245
|
+
// Assume my-archive.txt.gz exists
|
|
3246
|
+
// const decompressedContent = readFileSync(join("path", "to", "my-archive.txt.gz"), { compression: "gzip", encoding: "utf8" });
|
|
3247
|
+
// console.log("Decompressed content:", decompressedContent);
|
|
3255
3248
|
} catch (error) {
|
|
3256
|
-
|
|
3249
|
+
console.error("Failed to read file:", error);
|
|
3257
3250
|
}
|
|
3258
3251
|
```
|
|
3259
3252
|
|
|
3260
|
-
|
|
3253
|
+
---
|
|
3261
3254
|
|
|
3262
3255
|
### readJson()
|
|
3263
3256
|
|
|
@@ -3274,12 +3267,12 @@ The path to the JSON file to read. Can be a file URL or a string path.
|
|
|
3274
3267
|
#### Param
|
|
3275
3268
|
|
|
3276
3269
|
A function to transform the results. This function is called for each member of the object.
|
|
3277
|
-
|
|
3270
|
+
Alternatively, this can be the `options` object if no reviver function is provided.
|
|
3278
3271
|
|
|
3279
3272
|
#### Param
|
|
3280
3273
|
|
|
3281
3274
|
Optional configuration for reading and parsing the JSON file. See [ReadJsonOptions](#readjsonoptions).
|
|
3282
|
-
|
|
3275
|
+
If `reviver` is an object, this argument is ignored.
|
|
3283
3276
|
|
|
3284
3277
|
#### Example
|
|
3285
3278
|
|
|
@@ -3288,24 +3281,23 @@ import { readJson } from "@visulima/fs";
|
|
|
3288
3281
|
import { join } from "node:path";
|
|
3289
3282
|
|
|
3290
3283
|
const readMyJson = async () => {
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
}
|
|
3284
|
+
try {
|
|
3285
|
+
const data = await readJson(join("path", "to", "my-config.json"));
|
|
3286
|
+
console.log("Config data:", data);
|
|
3287
|
+
|
|
3288
|
+
// With a reviver function
|
|
3289
|
+
const dataWithReviver = await readJson(join("path", "to", "another.json"), (key, value) => {
|
|
3290
|
+
if (key === "date") return new Date(value);
|
|
3291
|
+
return value;
|
|
3292
|
+
});
|
|
3293
|
+
console.log("Date field is now a Date object:", dataWithReviver.date);
|
|
3294
|
+
|
|
3295
|
+
// With options (e.g., for custom error reporting)
|
|
3296
|
+
const dataWithOptions = await readJson(join("path", "to", "options.json"), { color: { message: (str) => `\x1b[31m${str}\x1b[0m` } });
|
|
3297
|
+
console.log(dataWithOptions);
|
|
3298
|
+
} catch (error) {
|
|
3299
|
+
console.error("Failed to read or parse JSON file:", error);
|
|
3300
|
+
}
|
|
3309
3301
|
};
|
|
3310
3302
|
|
|
3311
3303
|
readMyJson();
|
|
@@ -3317,13 +3309,13 @@ readMyJson();
|
|
|
3317
3309
|
function readJson<T>(path, options?): Promise<T>;
|
|
3318
3310
|
```
|
|
3319
3311
|
|
|
3320
|
-
Defined in: [packages/fs/src/read/read-json.ts:8](https://github.com/visulima/visulima/blob/
|
|
3312
|
+
Defined in: [packages/fs/src/read/read-json.ts:8](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/read/read-json.ts#L8)
|
|
3321
3313
|
|
|
3322
3314
|
##### Type Parameters
|
|
3323
3315
|
|
|
3324
3316
|
###### T
|
|
3325
3317
|
|
|
3326
|
-
`T`
|
|
3318
|
+
`T` _extends_ `JsonValue`
|
|
3327
3319
|
|
|
3328
3320
|
##### Parameters
|
|
3329
3321
|
|
|
@@ -3342,19 +3334,16 @@ Defined in: [packages/fs/src/read/read-json.ts:8](https://github.com/visulima/vi
|
|
|
3342
3334
|
#### Call Signature
|
|
3343
3335
|
|
|
3344
3336
|
```ts
|
|
3345
|
-
function readJson<T>(
|
|
3346
|
-
path,
|
|
3347
|
-
reviver,
|
|
3348
|
-
options?): Promise<T>;
|
|
3337
|
+
function readJson<T>(path, reviver, options?): Promise<T>;
|
|
3349
3338
|
```
|
|
3350
3339
|
|
|
3351
|
-
Defined in: [packages/fs/src/read/read-json.ts:10](https://github.com/visulima/visulima/blob/
|
|
3340
|
+
Defined in: [packages/fs/src/read/read-json.ts:10](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/read/read-json.ts#L10)
|
|
3352
3341
|
|
|
3353
3342
|
##### Type Parameters
|
|
3354
3343
|
|
|
3355
3344
|
###### T
|
|
3356
3345
|
|
|
3357
|
-
`T`
|
|
3346
|
+
`T` _extends_ `JsonValue`
|
|
3358
3347
|
|
|
3359
3348
|
##### Parameters
|
|
3360
3349
|
|
|
@@ -3374,7 +3363,7 @@ Defined in: [packages/fs/src/read/read-json.ts:10](https://github.com/visulima/v
|
|
|
3374
3363
|
|
|
3375
3364
|
`Promise`\<`T`\>
|
|
3376
3365
|
|
|
3377
|
-
|
|
3366
|
+
---
|
|
3378
3367
|
|
|
3379
3368
|
### readJsonSync()
|
|
3380
3369
|
|
|
@@ -3391,12 +3380,12 @@ The path to the JSON file to read. Can be a file URL or a string path.
|
|
|
3391
3380
|
#### Param
|
|
3392
3381
|
|
|
3393
3382
|
A function to transform the results. This function is called for each member of the object.
|
|
3394
|
-
|
|
3383
|
+
Alternatively, this can be the `options` object if no reviver function is provided.
|
|
3395
3384
|
|
|
3396
3385
|
#### Param
|
|
3397
3386
|
|
|
3398
3387
|
Optional configuration for reading and parsing the JSON file. See [ReadJsonOptions](#readjsonoptions).
|
|
3399
|
-
|
|
3388
|
+
If `reviver` is an object, this argument is ignored.
|
|
3400
3389
|
|
|
3401
3390
|
#### Example
|
|
3402
3391
|
|
|
@@ -3405,22 +3394,21 @@ import { readJsonSync } from "@visulima/fs";
|
|
|
3405
3394
|
import { join } from "node:path";
|
|
3406
3395
|
|
|
3407
3396
|
try {
|
|
3408
|
-
|
|
3409
|
-
|
|
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);
|
|
3397
|
+
const data = readJsonSync(join("path", "to", "my-config.json"));
|
|
3398
|
+
console.log("Config data:", data);
|
|
3417
3399
|
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3400
|
+
// With a reviver function
|
|
3401
|
+
const dataWithReviver = readJsonSync(join("path", "to", "another.json"), (key, value) => {
|
|
3402
|
+
if (key === "date") return new Date(value);
|
|
3403
|
+
return value;
|
|
3404
|
+
});
|
|
3405
|
+
console.log("Date field is now a Date object:", dataWithReviver.date);
|
|
3421
3406
|
|
|
3407
|
+
// With options (e.g., for custom error reporting)
|
|
3408
|
+
const dataWithOptions = readJsonSync(join("path", "to", "options.json"), { color: { message: (str) => `\x1b[31m${str}\x1b[0m` } });
|
|
3409
|
+
console.log(dataWithOptions);
|
|
3422
3410
|
} catch (error) {
|
|
3423
|
-
|
|
3411
|
+
console.error("Failed to read or parse JSON file:", error);
|
|
3424
3412
|
}
|
|
3425
3413
|
```
|
|
3426
3414
|
|
|
@@ -3430,13 +3418,13 @@ try {
|
|
|
3430
3418
|
function readJsonSync<T>(path, options?): T;
|
|
3431
3419
|
```
|
|
3432
3420
|
|
|
3433
|
-
Defined in: [packages/fs/src/read/read-json-sync.ts:8](https://github.com/visulima/visulima/blob/
|
|
3421
|
+
Defined in: [packages/fs/src/read/read-json-sync.ts:8](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/read/read-json-sync.ts#L8)
|
|
3434
3422
|
|
|
3435
3423
|
##### Type Parameters
|
|
3436
3424
|
|
|
3437
3425
|
###### T
|
|
3438
3426
|
|
|
3439
|
-
`T`
|
|
3427
|
+
`T` _extends_ `JsonValue`
|
|
3440
3428
|
|
|
3441
3429
|
##### Parameters
|
|
3442
3430
|
|
|
@@ -3455,19 +3443,16 @@ Defined in: [packages/fs/src/read/read-json-sync.ts:8](https://github.com/visuli
|
|
|
3455
3443
|
#### Call Signature
|
|
3456
3444
|
|
|
3457
3445
|
```ts
|
|
3458
|
-
function readJsonSync<T>(
|
|
3459
|
-
path,
|
|
3460
|
-
reviver,
|
|
3461
|
-
options?): T;
|
|
3446
|
+
function readJsonSync<T>(path, reviver, options?): T;
|
|
3462
3447
|
```
|
|
3463
3448
|
|
|
3464
|
-
Defined in: [packages/fs/src/read/read-json-sync.ts:10](https://github.com/visulima/visulima/blob/
|
|
3449
|
+
Defined in: [packages/fs/src/read/read-json-sync.ts:10](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/read/read-json-sync.ts#L10)
|
|
3465
3450
|
|
|
3466
3451
|
##### Type Parameters
|
|
3467
3452
|
|
|
3468
3453
|
###### T
|
|
3469
3454
|
|
|
3470
|
-
`T`
|
|
3455
|
+
`T` _extends_ `JsonValue`
|
|
3471
3456
|
|
|
3472
3457
|
##### Parameters
|
|
3473
3458
|
|
|
@@ -3487,7 +3472,7 @@ Defined in: [packages/fs/src/read/read-json-sync.ts:10](https://github.com/visul
|
|
|
3487
3472
|
|
|
3488
3473
|
`T`
|
|
3489
3474
|
|
|
3490
|
-
|
|
3475
|
+
---
|
|
3491
3476
|
|
|
3492
3477
|
### remove()
|
|
3493
3478
|
|
|
@@ -3495,7 +3480,7 @@ Defined in: [packages/fs/src/read/read-json-sync.ts:10](https://github.com/visul
|
|
|
3495
3480
|
function remove(path, options): Promise<void>;
|
|
3496
3481
|
```
|
|
3497
3482
|
|
|
3498
|
-
Defined in: [packages/fs/src/remove/remove.ts:36](https://github.com/visulima/visulima/blob/
|
|
3483
|
+
Defined in: [packages/fs/src/remove/remove.ts:36](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/remove/remove.ts#L36)
|
|
3499
3484
|
|
|
3500
3485
|
Asynchronously removes a file or directory (recursively).
|
|
3501
3486
|
If the path does not exist, it does nothing.
|
|
@@ -3527,24 +3512,24 @@ import { remove } from "@visulima/fs";
|
|
|
3527
3512
|
import { join } from "node:path";
|
|
3528
3513
|
|
|
3529
3514
|
const deleteFileOrDir = async () => {
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3515
|
+
try {
|
|
3516
|
+
await remove(join("/tmp", "my-file.txt"));
|
|
3517
|
+
console.log("File /tmp/my-file.txt removed.");
|
|
3533
3518
|
|
|
3534
|
-
|
|
3535
|
-
|
|
3519
|
+
await remove(join("/tmp", "my-empty-dir"));
|
|
3520
|
+
console.log("Directory /tmp/my-empty-dir removed.");
|
|
3536
3521
|
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3522
|
+
await remove(join("/tmp", "my-dir-with-contents"));
|
|
3523
|
+
console.log("Directory /tmp/my-dir-with-contents and its contents removed.");
|
|
3524
|
+
} catch (error) {
|
|
3525
|
+
console.error("Failed to remove path:", error);
|
|
3526
|
+
}
|
|
3542
3527
|
};
|
|
3543
3528
|
|
|
3544
3529
|
deleteFileOrDir();
|
|
3545
3530
|
```
|
|
3546
3531
|
|
|
3547
|
-
|
|
3532
|
+
---
|
|
3548
3533
|
|
|
3549
3534
|
### removeSync()
|
|
3550
3535
|
|
|
@@ -3552,7 +3537,7 @@ deleteFileOrDir();
|
|
|
3552
3537
|
function removeSync(path, options): void;
|
|
3553
3538
|
```
|
|
3554
3539
|
|
|
3555
|
-
Defined in: [packages/fs/src/remove/remove-sync.ts:32](https://github.com/visulima/visulima/blob/
|
|
3540
|
+
Defined in: [packages/fs/src/remove/remove-sync.ts:32](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/remove/remove-sync.ts#L32)
|
|
3556
3541
|
|
|
3557
3542
|
Synchronously removes a file or directory (recursively).
|
|
3558
3543
|
If the path does not exist, it does nothing.
|
|
@@ -3584,31 +3569,28 @@ import { removeSync } from "@visulima/fs";
|
|
|
3584
3569
|
import { join } from "node:path";
|
|
3585
3570
|
|
|
3586
3571
|
try {
|
|
3587
|
-
|
|
3588
|
-
|
|
3572
|
+
removeSync(join("/tmp", "my-file.txt"));
|
|
3573
|
+
console.log("File /tmp/my-file.txt removed.");
|
|
3589
3574
|
|
|
3590
|
-
|
|
3591
|
-
|
|
3575
|
+
removeSync(join("/tmp", "my-empty-dir"));
|
|
3576
|
+
console.log("Directory /tmp/my-empty-dir removed.");
|
|
3592
3577
|
|
|
3593
|
-
|
|
3594
|
-
|
|
3578
|
+
removeSync(join("/tmp", "my-dir-with-contents"));
|
|
3579
|
+
console.log("Directory /tmp/my-dir-with-contents and its contents removed.");
|
|
3595
3580
|
} catch (error) {
|
|
3596
|
-
|
|
3581
|
+
console.error("Failed to remove path:", error);
|
|
3597
3582
|
}
|
|
3598
3583
|
```
|
|
3599
3584
|
|
|
3600
|
-
|
|
3585
|
+
---
|
|
3601
3586
|
|
|
3602
3587
|
### rename()
|
|
3603
3588
|
|
|
3604
3589
|
```ts
|
|
3605
|
-
function rename(
|
|
3606
|
-
source,
|
|
3607
|
-
destination,
|
|
3608
|
-
options?): Promise<void>;
|
|
3590
|
+
function rename(source, destination, options?): Promise<void>;
|
|
3609
3591
|
```
|
|
3610
3592
|
|
|
3611
|
-
Defined in: [packages/fs/src/move/index.ts:85](https://github.com/visulima/visulima/blob/
|
|
3593
|
+
Defined in: [packages/fs/src/move/index.ts:85](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/move/index.ts#L85)
|
|
3612
3594
|
|
|
3613
3595
|
Rename a file asynchronously.
|
|
3614
3596
|
|
|
@@ -3647,18 +3629,15 @@ await rename('test.png', 'tests.png', {cwd: 'source'});
|
|
|
3647
3629
|
console.log('The file has been renamed');
|
|
3648
3630
|
```
|
|
3649
3631
|
|
|
3650
|
-
|
|
3632
|
+
---
|
|
3651
3633
|
|
|
3652
3634
|
### renameSync()
|
|
3653
3635
|
|
|
3654
3636
|
```ts
|
|
3655
|
-
function renameSync(
|
|
3656
|
-
source,
|
|
3657
|
-
destination,
|
|
3658
|
-
options?): void;
|
|
3637
|
+
function renameSync(source, destination, options?): void;
|
|
3659
3638
|
```
|
|
3660
3639
|
|
|
3661
|
-
Defined in: [packages/fs/src/move/index.ts:109](https://github.com/visulima/visulima/blob/
|
|
3640
|
+
Defined in: [packages/fs/src/move/index.ts:109](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/move/index.ts#L109)
|
|
3662
3641
|
|
|
3663
3642
|
Rename a file synchronously.
|
|
3664
3643
|
|
|
@@ -3697,7 +3676,7 @@ renameSync('test.png', 'tests.png', {cwd: 'source'});
|
|
|
3697
3676
|
console.log('The file has been renamed');
|
|
3698
3677
|
```
|
|
3699
3678
|
|
|
3700
|
-
|
|
3679
|
+
---
|
|
3701
3680
|
|
|
3702
3681
|
### walk()
|
|
3703
3682
|
|
|
@@ -3705,7 +3684,7 @@ console.log('The file has been renamed');
|
|
|
3705
3684
|
function walk(directory, options): AsyncIterableIterator<WalkEntry>;
|
|
3706
3685
|
```
|
|
3707
3686
|
|
|
3708
|
-
Defined in: [packages/fs/src/find/walk.ts:64](https://github.com/visulima/visulima/blob/
|
|
3687
|
+
Defined in: [packages/fs/src/find/walk.ts:64](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/find/walk.ts#L64)
|
|
3709
3688
|
|
|
3710
3689
|
Asynchronously walks the file tree rooted at `directory`, yielding each file or directory that matches the criteria specified in `options`.
|
|
3711
3690
|
|
|
@@ -3736,23 +3715,23 @@ import { walk } from "@visulima/fs";
|
|
|
3736
3715
|
import { join } from "node:path";
|
|
3737
3716
|
|
|
3738
3717
|
const printEntries = async () => {
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3718
|
+
// Walk through /tmp/my-project, looking for .ts files, max depth 2
|
|
3719
|
+
for await (const entry of walk(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
|
|
3720
|
+
console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? "file" : "directory"})`);
|
|
3721
|
+
}
|
|
3743
3722
|
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3723
|
+
// Walk, including only directories, and skip any node_modules folders
|
|
3724
|
+
for await (const entry of walk(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
|
|
3725
|
+
if (entry.isDirectory()) {
|
|
3726
|
+
console.log(`Directory: ${entry.path}`);
|
|
3727
|
+
}
|
|
3748
3728
|
}
|
|
3749
|
-
}
|
|
3750
3729
|
};
|
|
3751
3730
|
|
|
3752
3731
|
printEntries();
|
|
3753
3732
|
```
|
|
3754
3733
|
|
|
3755
|
-
|
|
3734
|
+
---
|
|
3756
3735
|
|
|
3757
3736
|
### walkSync()
|
|
3758
3737
|
|
|
@@ -3760,7 +3739,7 @@ printEntries();
|
|
|
3760
3739
|
function walkSync(directory, options): IterableIterator<WalkEntry>;
|
|
3761
3740
|
```
|
|
3762
3741
|
|
|
3763
|
-
Defined in: [packages/fs/src/find/walk-sync.ts:64](https://github.com/visulima/visulima/blob/
|
|
3742
|
+
Defined in: [packages/fs/src/find/walk-sync.ts:64](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/find/walk-sync.ts#L64)
|
|
3764
3743
|
|
|
3765
3744
|
Synchronously walks the file tree rooted at `directory`, yielding each file or directory that matches the criteria specified in `options`.
|
|
3766
3745
|
This is the synchronous version of the [walk](#walk) function.
|
|
@@ -3793,29 +3772,26 @@ import { join } from "node:path";
|
|
|
3793
3772
|
|
|
3794
3773
|
// Walk through /tmp/my-project, looking for .ts files, max depth 2
|
|
3795
3774
|
for (const entry of walkSync(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
|
|
3796
|
-
|
|
3775
|
+
console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? "file" : "directory"})`);
|
|
3797
3776
|
}
|
|
3798
3777
|
|
|
3799
3778
|
// Walk, including only directories, and skip any node_modules folders
|
|
3800
3779
|
for (const entry of walkSync(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3780
|
+
if (entry.isDirectory()) {
|
|
3781
|
+
console.log(`Directory: ${entry.path}`);
|
|
3782
|
+
}
|
|
3804
3783
|
}
|
|
3805
3784
|
```
|
|
3806
3785
|
|
|
3807
|
-
|
|
3786
|
+
---
|
|
3808
3787
|
|
|
3809
3788
|
### writeFile()
|
|
3810
3789
|
|
|
3811
3790
|
```ts
|
|
3812
|
-
function writeFile(
|
|
3813
|
-
path,
|
|
3814
|
-
content,
|
|
3815
|
-
options?): Promise<void>;
|
|
3791
|
+
function writeFile(path, content, options?): Promise<void>;
|
|
3816
3792
|
```
|
|
3817
3793
|
|
|
3818
|
-
Defined in: [packages/fs/src/write/write-file.ts:43](https://github.com/visulima/visulima/blob/
|
|
3794
|
+
Defined in: [packages/fs/src/write/write-file.ts:43](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/write/write-file.ts#L43)
|
|
3819
3795
|
|
|
3820
3796
|
Asynchronously writes data to a file, replacing the file if it already exists.
|
|
3821
3797
|
This function includes safeguards like writing to a temporary file first and then renaming, and handling permissions.
|
|
@@ -3853,32 +3829,29 @@ import { writeFile } from "@visulima/fs";
|
|
|
3853
3829
|
import { join } from "node:path";
|
|
3854
3830
|
|
|
3855
3831
|
const writeMyFile = async () => {
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3832
|
+
try {
|
|
3833
|
+
await writeFile(join("/tmp", "my-new-file.txt"), "Hello World!");
|
|
3834
|
+
console.log("File written successfully.");
|
|
3835
|
+
|
|
3836
|
+
await writeFile(join("/tmp", "another-file.txt"), "Some other content", { encoding: "utf16le", mode: 0o600 });
|
|
3837
|
+
console.log("Another file written with specific options.");
|
|
3838
|
+
} catch (error) {
|
|
3839
|
+
console.error("Failed to write file:", error);
|
|
3840
|
+
}
|
|
3865
3841
|
};
|
|
3866
3842
|
|
|
3867
3843
|
writeMyFile();
|
|
3868
3844
|
```
|
|
3869
3845
|
|
|
3870
|
-
|
|
3846
|
+
---
|
|
3871
3847
|
|
|
3872
3848
|
### writeFileSync()
|
|
3873
3849
|
|
|
3874
3850
|
```ts
|
|
3875
|
-
function writeFileSync(
|
|
3876
|
-
path,
|
|
3877
|
-
content,
|
|
3878
|
-
options?): void;
|
|
3851
|
+
function writeFileSync(path, content, options?): void;
|
|
3879
3852
|
```
|
|
3880
3853
|
|
|
3881
|
-
Defined in: [packages/fs/src/write/write-file-sync.ts:43](https://github.com/visulima/visulima/blob/
|
|
3854
|
+
Defined in: [packages/fs/src/write/write-file-sync.ts:43](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/write/write-file-sync.ts#L43)
|
|
3882
3855
|
|
|
3883
3856
|
Synchronously writes data to a file, replacing the file if it already exists.
|
|
3884
3857
|
This function includes safeguards like writing to a temporary file first and then renaming, and handling permissions.
|
|
@@ -3916,32 +3889,29 @@ import { writeFileSync } from "@visulima/fs";
|
|
|
3916
3889
|
import { join } from "node:path";
|
|
3917
3890
|
|
|
3918
3891
|
const writeMyFileSync = () => {
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3892
|
+
try {
|
|
3893
|
+
writeFileSync(join("/tmp", "my-new-file-sync.txt"), "Hello World Synchronously!");
|
|
3894
|
+
console.log("File written successfully (sync).");
|
|
3895
|
+
|
|
3896
|
+
writeFileSync(join("/tmp", "another-file-sync.txt"), "Some other sync content", { encoding: "utf16le", mode: 0o600 });
|
|
3897
|
+
console.log("Another file written with specific options (sync).");
|
|
3898
|
+
} catch (error) {
|
|
3899
|
+
console.error("Failed to write file (sync):", error);
|
|
3900
|
+
}
|
|
3928
3901
|
};
|
|
3929
3902
|
|
|
3930
3903
|
writeMyFileSync();
|
|
3931
3904
|
```
|
|
3932
3905
|
|
|
3933
|
-
|
|
3906
|
+
---
|
|
3934
3907
|
|
|
3935
3908
|
### writeJson()
|
|
3936
3909
|
|
|
3937
3910
|
```ts
|
|
3938
|
-
function writeJson(
|
|
3939
|
-
path,
|
|
3940
|
-
data,
|
|
3941
|
-
options): Promise<void>;
|
|
3911
|
+
function writeJson(path, data, options): Promise<void>;
|
|
3942
3912
|
```
|
|
3943
3913
|
|
|
3944
|
-
Defined in: [packages/fs/src/write/write-json.ts:39](https://github.com/visulima/visulima/blob/
|
|
3914
|
+
Defined in: [packages/fs/src/write/write-json.ts:39](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/write/write-json.ts#L39)
|
|
3945
3915
|
|
|
3946
3916
|
Asynchronously writes an object to a JSON file.
|
|
3947
3917
|
Handles indentation detection, custom stringifiers, and gracefully manages existing files.
|
|
@@ -3979,32 +3949,29 @@ import { writeJson } from "@visulima/fs";
|
|
|
3979
3949
|
import { join } from "node:path";
|
|
3980
3950
|
|
|
3981
3951
|
const writeMyJson = async () => {
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3952
|
+
try {
|
|
3953
|
+
await writeJson(join("/tmp", "my-config.json"), { setting: "enabled", value: 123 });
|
|
3954
|
+
console.log("JSON file written successfully.");
|
|
3955
|
+
|
|
3956
|
+
await writeJson(join("/tmp", "another-config.json"), { user: "test", id: "abc" }, { indent: 2, replacer: ["user"] });
|
|
3957
|
+
console.log("Another JSON file written with specific options (indent 2, only 'user' key).");
|
|
3958
|
+
} catch (error) {
|
|
3959
|
+
console.error("Failed to write JSON file:", error);
|
|
3960
|
+
}
|
|
3991
3961
|
};
|
|
3992
3962
|
|
|
3993
3963
|
writeMyJson();
|
|
3994
3964
|
```
|
|
3995
3965
|
|
|
3996
|
-
|
|
3966
|
+
---
|
|
3997
3967
|
|
|
3998
3968
|
### writeJsonSync()
|
|
3999
3969
|
|
|
4000
3970
|
```ts
|
|
4001
|
-
function writeJsonSync(
|
|
4002
|
-
path,
|
|
4003
|
-
data,
|
|
4004
|
-
options): void;
|
|
3971
|
+
function writeJsonSync(path, data, options): void;
|
|
4005
3972
|
```
|
|
4006
3973
|
|
|
4007
|
-
Defined in: [packages/fs/src/write/write-json-sync.ts:39](https://github.com/visulima/visulima/blob/
|
|
3974
|
+
Defined in: [packages/fs/src/write/write-json-sync.ts:39](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/write/write-json-sync.ts#L39)
|
|
4008
3975
|
|
|
4009
3976
|
Synchronously writes an object to a JSON file.
|
|
4010
3977
|
Handles indentation detection, custom stringifiers, and gracefully manages existing files.
|
|
@@ -4042,15 +4009,15 @@ import { writeJsonSync } from "@visulima/fs";
|
|
|
4042
4009
|
import { join } from "node:path";
|
|
4043
4010
|
|
|
4044
4011
|
const writeMyJsonSync = () => {
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4012
|
+
try {
|
|
4013
|
+
writeJsonSync(join("/tmp", "my-config-sync.json"), { setting: "enabled", value: 456 });
|
|
4014
|
+
console.log("JSON file written successfully (sync).");
|
|
4015
|
+
|
|
4016
|
+
writeJsonSync(join("/tmp", "another-config-sync.json"), { user: "testSync", id: "def" }, { indent: 4, replacer: ["id"] });
|
|
4017
|
+
console.log("Another JSON file written with specific options (sync, indent 4, only 'id' key).");
|
|
4018
|
+
} catch (error) {
|
|
4019
|
+
console.error("Failed to write JSON file (sync):", error);
|
|
4020
|
+
}
|
|
4054
4021
|
};
|
|
4055
4022
|
|
|
4056
4023
|
writeMyJsonSync();
|
|
@@ -4058,65 +4025,65 @@ writeMyJsonSync();
|
|
|
4058
4025
|
|
|
4059
4026
|
## Variables
|
|
4060
4027
|
|
|
4061
|
-
###
|
|
4028
|
+
### F_OK
|
|
4062
4029
|
|
|
4063
4030
|
```ts
|
|
4064
4031
|
const F_OK: 0 = 0;
|
|
4065
4032
|
```
|
|
4066
4033
|
|
|
4067
|
-
Defined in: [packages/fs/src/constants.ts:5](https://github.com/visulima/visulima/blob/
|
|
4034
|
+
Defined in: [packages/fs/src/constants.ts:5](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/constants.ts#L5)
|
|
4068
4035
|
|
|
4069
4036
|
Constant to check if the path is visible to the calling process.
|
|
4070
4037
|
Corresponds to `node:fs.constants.F_OK`.
|
|
4071
4038
|
|
|
4072
|
-
|
|
4039
|
+
---
|
|
4073
4040
|
|
|
4074
|
-
###
|
|
4041
|
+
### FIND_UP_STOP
|
|
4075
4042
|
|
|
4076
4043
|
```ts
|
|
4077
4044
|
const FIND_UP_STOP: typeof FIND_UP_STOP;
|
|
4078
4045
|
```
|
|
4079
4046
|
|
|
4080
|
-
Defined in: [packages/fs/src/constants.ts:29](https://github.com/visulima/visulima/blob/
|
|
4047
|
+
Defined in: [packages/fs/src/constants.ts:29](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/constants.ts#L29)
|
|
4081
4048
|
|
|
4082
4049
|
A special symbol that can be returned by the matcher function in `findUp` or `findUpSync`
|
|
4083
4050
|
to stop the search process prematurely.
|
|
4084
4051
|
|
|
4085
|
-
|
|
4052
|
+
---
|
|
4086
4053
|
|
|
4087
|
-
###
|
|
4054
|
+
### R_OK
|
|
4088
4055
|
|
|
4089
4056
|
```ts
|
|
4090
4057
|
const R_OK: 4 = 4;
|
|
4091
4058
|
```
|
|
4092
4059
|
|
|
4093
|
-
Defined in: [packages/fs/src/constants.ts:11](https://github.com/visulima/visulima/blob/
|
|
4060
|
+
Defined in: [packages/fs/src/constants.ts:11](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/constants.ts#L11)
|
|
4094
4061
|
|
|
4095
4062
|
Constant to check if the path is readable to the calling process.
|
|
4096
4063
|
Corresponds to `node:fs.constants.R_OK`.
|
|
4097
4064
|
|
|
4098
|
-
|
|
4065
|
+
---
|
|
4099
4066
|
|
|
4100
|
-
###
|
|
4067
|
+
### W_OK
|
|
4101
4068
|
|
|
4102
4069
|
```ts
|
|
4103
4070
|
const W_OK: 2 = 2;
|
|
4104
4071
|
```
|
|
4105
4072
|
|
|
4106
|
-
Defined in: [packages/fs/src/constants.ts:17](https://github.com/visulima/visulima/blob/
|
|
4073
|
+
Defined in: [packages/fs/src/constants.ts:17](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/constants.ts#L17)
|
|
4107
4074
|
|
|
4108
4075
|
Constant to check if the path is writable to the calling process.
|
|
4109
4076
|
Corresponds to `node:fs.constants.W_OK`.
|
|
4110
4077
|
|
|
4111
|
-
|
|
4078
|
+
---
|
|
4112
4079
|
|
|
4113
|
-
###
|
|
4080
|
+
### X_OK
|
|
4114
4081
|
|
|
4115
4082
|
```ts
|
|
4116
4083
|
const X_OK: 1 = 1;
|
|
4117
4084
|
```
|
|
4118
4085
|
|
|
4119
|
-
Defined in: [packages/fs/src/constants.ts:23](https://github.com/visulima/visulima/blob/
|
|
4086
|
+
Defined in: [packages/fs/src/constants.ts:23](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/constants.ts#L23)
|
|
4120
4087
|
|
|
4121
4088
|
Constant to check if the path is executable by the calling process.
|
|
4122
4089
|
Corresponds to `node:fs.constants.X_OK`.
|
|
@@ -4125,7 +4092,7 @@ Corresponds to `node:fs.constants.X_OK`.
|
|
|
4125
4092
|
|
|
4126
4093
|
### WalkEntry
|
|
4127
4094
|
|
|
4128
|
-
Defined in: [packages/fs/src/types.ts:62](https://github.com/visulima/visulima/blob/
|
|
4095
|
+
Defined in: [packages/fs/src/types.ts:62](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L62)
|
|
4129
4096
|
|
|
4130
4097
|
Represents an entry found by `walk` or `walkSync`.
|
|
4131
4098
|
|
|
@@ -4141,7 +4108,7 @@ Represents an entry found by `walk` or `walkSync`.
|
|
|
4141
4108
|
isDirectory(): boolean;
|
|
4142
4109
|
```
|
|
4143
4110
|
|
|
4144
|
-
Defined in:
|
|
4111
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/fs.d.ts:190
|
|
4145
4112
|
|
|
4146
4113
|
Returns `true` if the `fs.Dirent` object describes a file system
|
|
4147
4114
|
directory.
|
|
@@ -4157,7 +4124,7 @@ v10.10.0
|
|
|
4157
4124
|
###### Inherited from
|
|
4158
4125
|
|
|
4159
4126
|
```ts
|
|
4160
|
-
Pick.isDirectory
|
|
4127
|
+
Pick.isDirectory;
|
|
4161
4128
|
```
|
|
4162
4129
|
|
|
4163
4130
|
##### isFile()
|
|
@@ -4166,7 +4133,7 @@ Pick.isDirectory
|
|
|
4166
4133
|
isFile(): boolean;
|
|
4167
4134
|
```
|
|
4168
4135
|
|
|
4169
|
-
Defined in:
|
|
4136
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/fs.d.ts:184
|
|
4170
4137
|
|
|
4171
4138
|
Returns `true` if the `fs.Dirent` object describes a regular file.
|
|
4172
4139
|
|
|
@@ -4181,7 +4148,7 @@ v10.10.0
|
|
|
4181
4148
|
###### Inherited from
|
|
4182
4149
|
|
|
4183
4150
|
```ts
|
|
4184
|
-
Pick.isFile
|
|
4151
|
+
Pick.isFile;
|
|
4185
4152
|
```
|
|
4186
4153
|
|
|
4187
4154
|
##### isSymbolicLink()
|
|
@@ -4190,7 +4157,7 @@ Pick.isFile
|
|
|
4190
4157
|
isSymbolicLink(): boolean;
|
|
4191
4158
|
```
|
|
4192
4159
|
|
|
4193
|
-
Defined in:
|
|
4160
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/fs.d.ts:205
|
|
4194
4161
|
|
|
4195
4162
|
Returns `true` if the `fs.Dirent` object describes a symbolic link.
|
|
4196
4163
|
|
|
@@ -4205,7 +4172,7 @@ v10.10.0
|
|
|
4205
4172
|
###### Inherited from
|
|
4206
4173
|
|
|
4207
4174
|
```ts
|
|
4208
|
-
Pick.isSymbolicLink
|
|
4175
|
+
Pick.isSymbolicLink;
|
|
4209
4176
|
```
|
|
4210
4177
|
|
|
4211
4178
|
#### Properties
|
|
@@ -4216,7 +4183,7 @@ Pick.isSymbolicLink
|
|
|
4216
4183
|
name: string;
|
|
4217
4184
|
```
|
|
4218
4185
|
|
|
4219
|
-
Defined in:
|
|
4186
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/fs.d.ts:222
|
|
4220
4187
|
|
|
4221
4188
|
The file name that this `fs.Dirent` object refers to. The type of this
|
|
4222
4189
|
value is determined by the `options.encoding` passed to readdir or readdirSync.
|
|
@@ -4228,7 +4195,7 @@ v10.10.0
|
|
|
4228
4195
|
###### Inherited from
|
|
4229
4196
|
|
|
4230
4197
|
```ts
|
|
4231
|
-
Pick.name
|
|
4198
|
+
Pick.name;
|
|
4232
4199
|
```
|
|
4233
4200
|
|
|
4234
4201
|
##### path
|
|
@@ -4237,15 +4204,15 @@ Pick.name
|
|
|
4237
4204
|
path: string;
|
|
4238
4205
|
```
|
|
4239
4206
|
|
|
4240
|
-
Defined in: [packages/fs/src/types.ts:64](https://github.com/visulima/visulima/blob/
|
|
4207
|
+
Defined in: [packages/fs/src/types.ts:64](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L64)
|
|
4241
4208
|
|
|
4242
4209
|
The full path to the entry.
|
|
4243
4210
|
|
|
4244
|
-
|
|
4211
|
+
---
|
|
4245
4212
|
|
|
4246
4213
|
### WalkOptions
|
|
4247
4214
|
|
|
4248
|
-
Defined in: [packages/fs/src/types.ts:12](https://github.com/visulima/visulima/blob/
|
|
4215
|
+
Defined in: [packages/fs/src/types.ts:12](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L12)
|
|
4249
4216
|
|
|
4250
4217
|
Options for the `walk` and `walkSync` functions.
|
|
4251
4218
|
|
|
@@ -4257,7 +4224,7 @@ Options for the `walk` and `walkSync` functions.
|
|
|
4257
4224
|
optional extensions: string[];
|
|
4258
4225
|
```
|
|
4259
4226
|
|
|
4260
|
-
Defined in: [packages/fs/src/types.ts:18](https://github.com/visulima/visulima/blob/
|
|
4227
|
+
Defined in: [packages/fs/src/types.ts:18](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L18)
|
|
4261
4228
|
|
|
4262
4229
|
List of file extensions used to filter entries.
|
|
4263
4230
|
If specified, entries without the file extension specified by this option are excluded.
|
|
@@ -4265,7 +4232,9 @@ If specified, entries without the file extension specified by this option are ex
|
|
|
4265
4232
|
###### Default
|
|
4266
4233
|
|
|
4267
4234
|
```ts
|
|
4268
|
-
{
|
|
4235
|
+
{
|
|
4236
|
+
undefined;
|
|
4237
|
+
}
|
|
4269
4238
|
```
|
|
4270
4239
|
|
|
4271
4240
|
##### followSymlinks?
|
|
@@ -4274,14 +4243,16 @@ If specified, entries without the file extension specified by this option are ex
|
|
|
4274
4243
|
optional followSymlinks: boolean;
|
|
4275
4244
|
```
|
|
4276
4245
|
|
|
4277
|
-
Defined in: [packages/fs/src/types.ts:23](https://github.com/visulima/visulima/blob/
|
|
4246
|
+
Defined in: [packages/fs/src/types.ts:23](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L23)
|
|
4278
4247
|
|
|
4279
4248
|
Indicates whether symlinks should be resolved or not.
|
|
4280
4249
|
|
|
4281
4250
|
###### Default
|
|
4282
4251
|
|
|
4283
4252
|
```ts
|
|
4284
|
-
{
|
|
4253
|
+
{
|
|
4254
|
+
false;
|
|
4255
|
+
}
|
|
4285
4256
|
```
|
|
4286
4257
|
|
|
4287
4258
|
##### includeDirs?
|
|
@@ -4290,14 +4261,16 @@ Indicates whether symlinks should be resolved or not.
|
|
|
4290
4261
|
optional includeDirs: boolean;
|
|
4291
4262
|
```
|
|
4292
4263
|
|
|
4293
|
-
Defined in: [packages/fs/src/types.ts:28](https://github.com/visulima/visulima/blob/
|
|
4264
|
+
Defined in: [packages/fs/src/types.ts:28](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L28)
|
|
4294
4265
|
|
|
4295
4266
|
Indicates whether directory entries should be included or not.
|
|
4296
4267
|
|
|
4297
4268
|
###### Default
|
|
4298
4269
|
|
|
4299
4270
|
```ts
|
|
4300
|
-
{
|
|
4271
|
+
{
|
|
4272
|
+
true;
|
|
4273
|
+
}
|
|
4301
4274
|
```
|
|
4302
4275
|
|
|
4303
4276
|
##### includeFiles?
|
|
@@ -4306,14 +4279,16 @@ Indicates whether directory entries should be included or not.
|
|
|
4306
4279
|
optional includeFiles: boolean;
|
|
4307
4280
|
```
|
|
4308
4281
|
|
|
4309
|
-
Defined in: [packages/fs/src/types.ts:33](https://github.com/visulima/visulima/blob/
|
|
4282
|
+
Defined in: [packages/fs/src/types.ts:33](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L33)
|
|
4310
4283
|
|
|
4311
4284
|
Indicates whether file entries should be included or not.
|
|
4312
4285
|
|
|
4313
4286
|
###### Default
|
|
4314
4287
|
|
|
4315
4288
|
```ts
|
|
4316
|
-
{
|
|
4289
|
+
{
|
|
4290
|
+
true;
|
|
4291
|
+
}
|
|
4317
4292
|
```
|
|
4318
4293
|
|
|
4319
4294
|
##### includeSymlinks?
|
|
@@ -4322,7 +4297,7 @@ Indicates whether file entries should be included or not.
|
|
|
4322
4297
|
optional includeSymlinks: boolean;
|
|
4323
4298
|
```
|
|
4324
4299
|
|
|
4325
|
-
Defined in: [packages/fs/src/types.ts:39](https://github.com/visulima/visulima/blob/
|
|
4300
|
+
Defined in: [packages/fs/src/types.ts:39](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L39)
|
|
4326
4301
|
|
|
4327
4302
|
Indicates whether symlink entries should be included or not.
|
|
4328
4303
|
This option is meaningful only if `followSymlinks` is set to `false`.
|
|
@@ -4330,7 +4305,9 @@ This option is meaningful only if `followSymlinks` is set to `false`.
|
|
|
4330
4305
|
###### Default
|
|
4331
4306
|
|
|
4332
4307
|
```ts
|
|
4333
|
-
{
|
|
4308
|
+
{
|
|
4309
|
+
true;
|
|
4310
|
+
}
|
|
4334
4311
|
```
|
|
4335
4312
|
|
|
4336
4313
|
##### match?
|
|
@@ -4339,7 +4316,7 @@ This option is meaningful only if `followSymlinks` is set to `false`.
|
|
|
4339
4316
|
optional match: (string | RegExp)[];
|
|
4340
4317
|
```
|
|
4341
4318
|
|
|
4342
|
-
Defined in: [packages/fs/src/types.ts:45](https://github.com/visulima/visulima/blob/
|
|
4319
|
+
Defined in: [packages/fs/src/types.ts:45](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L45)
|
|
4343
4320
|
|
|
4344
4321
|
List of regular expression or glob patterns used to filter entries.
|
|
4345
4322
|
If specified, entries that do not match the patterns specified by this option are excluded.
|
|
@@ -4347,7 +4324,9 @@ If specified, entries that do not match the patterns specified by this option ar
|
|
|
4347
4324
|
###### Default
|
|
4348
4325
|
|
|
4349
4326
|
```ts
|
|
4350
|
-
{
|
|
4327
|
+
{
|
|
4328
|
+
undefined;
|
|
4329
|
+
}
|
|
4351
4330
|
```
|
|
4352
4331
|
|
|
4353
4332
|
##### maxDepth?
|
|
@@ -4356,14 +4335,16 @@ If specified, entries that do not match the patterns specified by this option ar
|
|
|
4356
4335
|
optional maxDepth: number;
|
|
4357
4336
|
```
|
|
4358
4337
|
|
|
4359
|
-
Defined in: [packages/fs/src/types.ts:50](https://github.com/visulima/visulima/blob/
|
|
4338
|
+
Defined in: [packages/fs/src/types.ts:50](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L50)
|
|
4360
4339
|
|
|
4361
4340
|
The maximum depth of the file tree to be walked recursively.
|
|
4362
4341
|
|
|
4363
4342
|
###### Default
|
|
4364
4343
|
|
|
4365
4344
|
```ts
|
|
4366
|
-
{
|
|
4345
|
+
{
|
|
4346
|
+
Infinity;
|
|
4347
|
+
}
|
|
4367
4348
|
```
|
|
4368
4349
|
|
|
4369
4350
|
##### skip?
|
|
@@ -4372,7 +4353,7 @@ The maximum depth of the file tree to be walked recursively.
|
|
|
4372
4353
|
optional skip: (string | RegExp)[];
|
|
4373
4354
|
```
|
|
4374
4355
|
|
|
4375
|
-
Defined in: [packages/fs/src/types.ts:56](https://github.com/visulima/visulima/blob/
|
|
4356
|
+
Defined in: [packages/fs/src/types.ts:56](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L56)
|
|
4376
4357
|
|
|
4377
4358
|
List of regular expression or glob patterns used to filter entries.
|
|
4378
4359
|
If specified, entries matching the patterns specified by this option are excluded.
|
|
@@ -4380,7 +4361,9 @@ If specified, entries matching the patterns specified by this option are exclude
|
|
|
4380
4361
|
###### Default
|
|
4381
4362
|
|
|
4382
4363
|
```ts
|
|
4383
|
-
{
|
|
4364
|
+
{
|
|
4365
|
+
undefined;
|
|
4366
|
+
}
|
|
4384
4367
|
```
|
|
4385
4368
|
|
|
4386
4369
|
## Type Aliases
|
|
@@ -4391,7 +4374,7 @@ If specified, entries matching the patterns specified by this option are exclude
|
|
|
4391
4374
|
type CodeFrameLocation = object;
|
|
4392
4375
|
```
|
|
4393
4376
|
|
|
4394
|
-
Defined in: [packages/fs/src/types.ts:117](https://github.com/visulima/visulima/blob/
|
|
4377
|
+
Defined in: [packages/fs/src/types.ts:117](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L117)
|
|
4395
4378
|
|
|
4396
4379
|
Specifies a location (line and column) in a file for code frame generation.
|
|
4397
4380
|
|
|
@@ -4403,7 +4386,7 @@ Specifies a location (line and column) in a file for code frame generation.
|
|
|
4403
4386
|
optional column: number;
|
|
4404
4387
|
```
|
|
4405
4388
|
|
|
4406
|
-
Defined in: [packages/fs/src/types.ts:119](https://github.com/visulima/visulima/blob/
|
|
4389
|
+
Defined in: [packages/fs/src/types.ts:119](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L119)
|
|
4407
4390
|
|
|
4408
4391
|
The column number.
|
|
4409
4392
|
|
|
@@ -4413,11 +4396,11 @@ The column number.
|
|
|
4413
4396
|
line: number;
|
|
4414
4397
|
```
|
|
4415
4398
|
|
|
4416
|
-
Defined in: [packages/fs/src/types.ts:121](https://github.com/visulima/visulima/blob/
|
|
4399
|
+
Defined in: [packages/fs/src/types.ts:121](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L121)
|
|
4417
4400
|
|
|
4418
4401
|
The line number.
|
|
4419
4402
|
|
|
4420
|
-
|
|
4403
|
+
---
|
|
4421
4404
|
|
|
4422
4405
|
### CodeFrameOptions
|
|
4423
4406
|
|
|
@@ -4425,7 +4408,7 @@ The line number.
|
|
|
4425
4408
|
type CodeFrameOptions = object;
|
|
4426
4409
|
```
|
|
4427
4410
|
|
|
4428
|
-
Defined in: [packages/fs/src/types.ts:127](https://github.com/visulima/visulima/blob/
|
|
4411
|
+
Defined in: [packages/fs/src/types.ts:127](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L127)
|
|
4429
4412
|
|
|
4430
4413
|
Options for customizing the appearance of code frames.
|
|
4431
4414
|
|
|
@@ -4437,7 +4420,7 @@ Options for customizing the appearance of code frames.
|
|
|
4437
4420
|
optional color: object;
|
|
4438
4421
|
```
|
|
4439
4422
|
|
|
4440
|
-
Defined in: [packages/fs/src/types.ts:129](https://github.com/visulima/visulima/blob/
|
|
4423
|
+
Defined in: [packages/fs/src/types.ts:129](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L129)
|
|
4441
4424
|
|
|
4442
4425
|
Colorization methods for different parts of the code frame.
|
|
4443
4426
|
|
|
@@ -4465,7 +4448,7 @@ optional message: ColorizeMethod;
|
|
|
4465
4448
|
|
|
4466
4449
|
Color for the message.
|
|
4467
4450
|
|
|
4468
|
-
|
|
4451
|
+
---
|
|
4469
4452
|
|
|
4470
4453
|
### ContentType\<O\>
|
|
4471
4454
|
|
|
@@ -4473,7 +4456,7 @@ Color for the message.
|
|
|
4473
4456
|
type ContentType<O> = O extends object ? Buffer : string;
|
|
4474
4457
|
```
|
|
4475
4458
|
|
|
4476
|
-
Defined in: [packages/fs/src/types.ts:104](https://github.com/visulima/visulima/blob/
|
|
4459
|
+
Defined in: [packages/fs/src/types.ts:104](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L104)
|
|
4477
4460
|
|
|
4478
4461
|
Represents the content type of a read file, which can be a Buffer or a string based on options.
|
|
4479
4462
|
|
|
@@ -4485,57 +4468,53 @@ Represents the content type of a read file, which can be a Buffer or a string ba
|
|
|
4485
4468
|
|
|
4486
4469
|
The ReadFileOptions type.
|
|
4487
4470
|
|
|
4488
|
-
|
|
4471
|
+
---
|
|
4489
4472
|
|
|
4490
4473
|
### FindUpName
|
|
4491
4474
|
|
|
4492
4475
|
```ts
|
|
4493
|
-
type FindUpName =
|
|
4476
|
+
type FindUpName =
|
|
4494
4477
|
| string[]
|
|
4495
4478
|
| string
|
|
4496
4479
|
| (directory) => FindUpNameFnResult;
|
|
4497
4480
|
```
|
|
4498
4481
|
|
|
4499
|
-
Defined in: [packages/fs/src/types.ts:270](https://github.com/visulima/visulima/blob/
|
|
4482
|
+
Defined in: [packages/fs/src/types.ts:270](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L270)
|
|
4500
4483
|
|
|
4501
4484
|
Specifies the name(s) of the file or directory to search for in `findUp`.
|
|
4502
4485
|
Can be a single name, an array of names, or a function that returns a name or `FIND_UP_STOP`.
|
|
4503
4486
|
|
|
4504
|
-
|
|
4487
|
+
---
|
|
4505
4488
|
|
|
4506
4489
|
### FindUpNameFnResult
|
|
4507
4490
|
|
|
4508
4491
|
```ts
|
|
4509
|
-
type FindUpNameFnResult =
|
|
4510
|
-
| PathLike
|
|
4511
|
-
| Promise<PathLike | typeof FIND_UP_STOP>
|
|
4512
|
-
| typeof FIND_UP_STOP
|
|
4513
|
-
| undefined;
|
|
4492
|
+
type FindUpNameFnResult = PathLike | Promise<PathLike | typeof FIND_UP_STOP> | typeof FIND_UP_STOP | undefined;
|
|
4514
4493
|
```
|
|
4515
4494
|
|
|
4516
|
-
Defined in: [packages/fs/src/types.ts:264](https://github.com/visulima/visulima/blob/
|
|
4495
|
+
Defined in: [packages/fs/src/types.ts:264](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L264)
|
|
4517
4496
|
|
|
4518
4497
|
The result type for the name matcher function used in `findUp`.
|
|
4519
4498
|
It can be a `PathLike` (string, Buffer, or URL), a Promise resolving to `PathLike` or `FIND_UP_STOP`,
|
|
4520
4499
|
`FIND_UP_STOP` to stop the search, or `undefined` to continue.
|
|
4521
4500
|
|
|
4522
|
-
|
|
4501
|
+
---
|
|
4523
4502
|
|
|
4524
4503
|
### FindUpNameSync
|
|
4525
4504
|
|
|
4526
4505
|
```ts
|
|
4527
|
-
type FindUpNameSync =
|
|
4506
|
+
type FindUpNameSync =
|
|
4528
4507
|
| string[]
|
|
4529
4508
|
| string
|
|
4530
4509
|
| (directory) => FindUpNameSyncFnResult;
|
|
4531
4510
|
```
|
|
4532
4511
|
|
|
4533
|
-
Defined in: [packages/fs/src/types.ts:284](https://github.com/visulima/visulima/blob/
|
|
4512
|
+
Defined in: [packages/fs/src/types.ts:284](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L284)
|
|
4534
4513
|
|
|
4535
4514
|
Specifies the name(s) of the file or directory to search for in `findUpSync`.
|
|
4536
4515
|
Can be a single name, an array of names, or a function that returns a name or `FIND_UP_STOP`.
|
|
4537
4516
|
|
|
4538
|
-
|
|
4517
|
+
---
|
|
4539
4518
|
|
|
4540
4519
|
### FindUpNameSyncFnResult
|
|
4541
4520
|
|
|
@@ -4543,13 +4522,13 @@ Can be a single name, an array of names, or a function that returns a name or `F
|
|
|
4543
4522
|
type FindUpNameSyncFnResult = PathLike | typeof FIND_UP_STOP | undefined;
|
|
4544
4523
|
```
|
|
4545
4524
|
|
|
4546
|
-
Defined in: [packages/fs/src/types.ts:278](https://github.com/visulima/visulima/blob/
|
|
4525
|
+
Defined in: [packages/fs/src/types.ts:278](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L278)
|
|
4547
4526
|
|
|
4548
4527
|
The result type for the name matcher function used in `findUpSync`.
|
|
4549
4528
|
It can be a `PathLike` (string, Buffer, or URL), `FIND_UP_STOP` to stop the search,
|
|
4550
4529
|
or `undefined` to continue.
|
|
4551
4530
|
|
|
4552
|
-
|
|
4531
|
+
---
|
|
4553
4532
|
|
|
4554
4533
|
### FindUpOptions
|
|
4555
4534
|
|
|
@@ -4557,7 +4536,7 @@ or `undefined` to continue.
|
|
|
4557
4536
|
type FindUpOptions = object;
|
|
4558
4537
|
```
|
|
4559
4538
|
|
|
4560
|
-
Defined in: [packages/fs/src/types.ts:235](https://github.com/visulima/visulima/blob/
|
|
4539
|
+
Defined in: [packages/fs/src/types.ts:235](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L235)
|
|
4561
4540
|
|
|
4562
4541
|
Options for the `findUp` and `findUpSync` functions.
|
|
4563
4542
|
|
|
@@ -4569,7 +4548,7 @@ Options for the `findUp` and `findUpSync` functions.
|
|
|
4569
4548
|
optional allowSymlinks: boolean;
|
|
4570
4549
|
```
|
|
4571
4550
|
|
|
4572
|
-
Defined in: [packages/fs/src/types.ts:240](https://github.com/visulima/visulima/blob/
|
|
4551
|
+
Defined in: [packages/fs/src/types.ts:240](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L240)
|
|
4573
4552
|
|
|
4574
4553
|
Whether to follow symbolic links.
|
|
4575
4554
|
|
|
@@ -4583,14 +4562,14 @@ undefined (behaves like `true` for `findUp`, `false` for `findUpSync` due to `fs
|
|
|
4583
4562
|
optional cwd: URL | string;
|
|
4584
4563
|
```
|
|
4585
4564
|
|
|
4586
|
-
Defined in: [packages/fs/src/types.ts:245](https://github.com/visulima/visulima/blob/
|
|
4565
|
+
Defined in: [packages/fs/src/types.ts:245](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L245)
|
|
4587
4566
|
|
|
4588
4567
|
The current working directory.
|
|
4589
4568
|
|
|
4590
4569
|
###### Default
|
|
4591
4570
|
|
|
4592
4571
|
```ts
|
|
4593
|
-
process.cwd()
|
|
4572
|
+
process.cwd();
|
|
4594
4573
|
```
|
|
4595
4574
|
|
|
4596
4575
|
##### stopAt?
|
|
@@ -4599,14 +4578,14 @@ process.cwd()
|
|
|
4599
4578
|
optional stopAt: URL | string;
|
|
4600
4579
|
```
|
|
4601
4580
|
|
|
4602
|
-
Defined in: [packages/fs/src/types.ts:250](https://github.com/visulima/visulima/blob/
|
|
4581
|
+
Defined in: [packages/fs/src/types.ts:250](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L250)
|
|
4603
4582
|
|
|
4604
4583
|
The directory to stop searching at.
|
|
4605
4584
|
|
|
4606
4585
|
###### Default
|
|
4607
4586
|
|
|
4608
4587
|
```ts
|
|
4609
|
-
path.parse(cwd).root
|
|
4588
|
+
path.parse(cwd).root;
|
|
4610
4589
|
```
|
|
4611
4590
|
|
|
4612
4591
|
##### type?
|
|
@@ -4615,17 +4594,17 @@ path.parse(cwd).root
|
|
|
4615
4594
|
optional type: "directory" | "file";
|
|
4616
4595
|
```
|
|
4617
4596
|
|
|
4618
|
-
Defined in: [packages/fs/src/types.ts:255](https://github.com/visulima/visulima/blob/
|
|
4597
|
+
Defined in: [packages/fs/src/types.ts:255](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L255)
|
|
4619
4598
|
|
|
4620
4599
|
The type of path to find.
|
|
4621
4600
|
|
|
4622
4601
|
###### Default
|
|
4623
4602
|
|
|
4624
4603
|
```ts
|
|
4625
|
-
"file"
|
|
4604
|
+
"file";
|
|
4626
4605
|
```
|
|
4627
4606
|
|
|
4628
|
-
|
|
4607
|
+
---
|
|
4629
4608
|
|
|
4630
4609
|
### JsonReplacer
|
|
4631
4610
|
|
|
@@ -4633,7 +4612,7 @@ The type of path to find.
|
|
|
4633
4612
|
type JsonReplacer = (number | string)[] | (this, key, value) => unknown | null;
|
|
4634
4613
|
```
|
|
4635
4614
|
|
|
4636
|
-
Defined in: [packages/fs/src/types.ts:197](https://github.com/visulima/visulima/blob/
|
|
4615
|
+
Defined in: [packages/fs/src/types.ts:197](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L197)
|
|
4637
4616
|
|
|
4638
4617
|
Type for the `replacer` parameter of `JSON.stringify()`.
|
|
4639
4618
|
Can be a function that alters the behavior of the stringification process,
|
|
@@ -4641,21 +4620,21 @@ or an array of strings and numbers that acts as a whitelist for selecting
|
|
|
4641
4620
|
the properties of the value object to be included in the JSON string.
|
|
4642
4621
|
If this value is null or not provided, all properties of the object are included in the resulting JSON string.
|
|
4643
4622
|
|
|
4644
|
-
|
|
4623
|
+
---
|
|
4645
4624
|
|
|
4646
4625
|
### JsonReviver
|
|
4647
4626
|
|
|
4648
4627
|
```ts
|
|
4649
|
-
type JsonReviver = Parameters<typeof JSON["parse"]>["1"];
|
|
4628
|
+
type JsonReviver = Parameters<(typeof JSON)["parse"]>["1"];
|
|
4650
4629
|
```
|
|
4651
4630
|
|
|
4652
|
-
Defined in: [packages/fs/src/types.ts:112](https://github.com/visulima/visulima/blob/
|
|
4631
|
+
Defined in: [packages/fs/src/types.ts:112](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L112)
|
|
4653
4632
|
|
|
4654
4633
|
Type for the `reviver` parameter of `JSON.parse()`.
|
|
4655
4634
|
A function that transforms the results. This function is called for each member of the object.
|
|
4656
4635
|
If a member contains nested objects, the nested objects are transformed before the parent object is.
|
|
4657
4636
|
|
|
4658
|
-
|
|
4637
|
+
---
|
|
4659
4638
|
|
|
4660
4639
|
### MoveOptions
|
|
4661
4640
|
|
|
@@ -4663,7 +4642,7 @@ If a member contains nested objects, the nested objects are transformed before t
|
|
|
4663
4642
|
type MoveOptions = object;
|
|
4664
4643
|
```
|
|
4665
4644
|
|
|
4666
|
-
Defined in: [packages/fs/src/move/types.ts:3](https://github.com/visulima/visulima/blob/
|
|
4645
|
+
Defined in: [packages/fs/src/move/types.ts:3](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/move/types.ts#L3)
|
|
4667
4646
|
|
|
4668
4647
|
#### Properties
|
|
4669
4648
|
|
|
@@ -4673,7 +4652,7 @@ Defined in: [packages/fs/src/move/types.ts:3](https://github.com/visulima/visuli
|
|
|
4673
4652
|
optional cwd: URL | string;
|
|
4674
4653
|
```
|
|
4675
4654
|
|
|
4676
|
-
Defined in: [packages/fs/src/move/types.ts:10](https://github.com/visulima/visulima/blob/
|
|
4655
|
+
Defined in: [packages/fs/src/move/types.ts:10](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/move/types.ts#L10)
|
|
4677
4656
|
|
|
4678
4657
|
The working directory to find source files.
|
|
4679
4658
|
The source and destination path are relative to this.
|
|
@@ -4681,7 +4660,7 @@ The source and destination path are relative to this.
|
|
|
4681
4660
|
###### Default
|
|
4682
4661
|
|
|
4683
4662
|
```ts
|
|
4684
|
-
process.cwd()
|
|
4663
|
+
process.cwd();
|
|
4685
4664
|
```
|
|
4686
4665
|
|
|
4687
4666
|
##### directoryMode?
|
|
@@ -4690,7 +4669,7 @@ process.cwd()
|
|
|
4690
4669
|
readonly optional directoryMode: FilePermissions;
|
|
4691
4670
|
```
|
|
4692
4671
|
|
|
4693
|
-
Defined in: [packages/fs/src/move/types.ts:19](https://github.com/visulima/visulima/blob/
|
|
4672
|
+
Defined in: [packages/fs/src/move/types.ts:19](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/move/types.ts#L19)
|
|
4694
4673
|
|
|
4695
4674
|
[Permissions](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) for created directories.
|
|
4696
4675
|
|
|
@@ -4699,7 +4678,7 @@ It has no effect on Windows.
|
|
|
4699
4678
|
###### Default
|
|
4700
4679
|
|
|
4701
4680
|
```ts
|
|
4702
|
-
0o777
|
|
4681
|
+
0o777;
|
|
4703
4682
|
```
|
|
4704
4683
|
|
|
4705
4684
|
##### overwrite?
|
|
@@ -4708,40 +4687,29 @@ It has no effect on Windows.
|
|
|
4708
4687
|
readonly optional overwrite: boolean;
|
|
4709
4688
|
```
|
|
4710
4689
|
|
|
4711
|
-
Defined in: [packages/fs/src/move/types.ts:26](https://github.com/visulima/visulima/blob/
|
|
4690
|
+
Defined in: [packages/fs/src/move/types.ts:26](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/move/types.ts#L26)
|
|
4712
4691
|
|
|
4713
4692
|
Overwrite existing destination file.
|
|
4714
4693
|
|
|
4715
4694
|
###### Default
|
|
4716
4695
|
|
|
4717
4696
|
```ts
|
|
4718
|
-
true
|
|
4697
|
+
true;
|
|
4719
4698
|
```
|
|
4720
4699
|
|
|
4721
|
-
|
|
4700
|
+
---
|
|
4722
4701
|
|
|
4723
4702
|
### ReadFileEncoding
|
|
4724
4703
|
|
|
4725
4704
|
```ts
|
|
4726
|
-
type ReadFileEncoding =
|
|
4727
|
-
| "ascii"
|
|
4728
|
-
| "base64"
|
|
4729
|
-
| "base64url"
|
|
4730
|
-
| "hex"
|
|
4731
|
-
| "latin1"
|
|
4732
|
-
| "ucs-2"
|
|
4733
|
-
| "ucs2"
|
|
4734
|
-
| "utf-8"
|
|
4735
|
-
| "utf-16le"
|
|
4736
|
-
| "utf8"
|
|
4737
|
-
| "utf16le";
|
|
4705
|
+
type ReadFileEncoding = "ascii" | "base64" | "base64url" | "hex" | "latin1" | "ucs-2" | "ucs2" | "utf-8" | "utf-16le" | "utf8" | "utf16le";
|
|
4738
4706
|
```
|
|
4739
4707
|
|
|
4740
|
-
Defined in: [packages/fs/src/types.ts:71](https://github.com/visulima/visulima/blob/
|
|
4708
|
+
Defined in: [packages/fs/src/types.ts:71](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L71)
|
|
4741
4709
|
|
|
4742
4710
|
Supported file encodings for reading files.
|
|
4743
4711
|
|
|
4744
|
-
|
|
4712
|
+
---
|
|
4745
4713
|
|
|
4746
4714
|
### ReadFileOptions\<C\>
|
|
4747
4715
|
|
|
@@ -4749,7 +4717,7 @@ Supported file encodings for reading files.
|
|
|
4749
4717
|
type ReadFileOptions<C> = object;
|
|
4750
4718
|
```
|
|
4751
4719
|
|
|
4752
|
-
Defined in: [packages/fs/src/types.ts:77](https://github.com/visulima/visulima/blob/
|
|
4720
|
+
Defined in: [packages/fs/src/types.ts:77](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L77)
|
|
4753
4721
|
|
|
4754
4722
|
Options for reading files.
|
|
4755
4723
|
|
|
@@ -4769,7 +4737,7 @@ The type of compression used.
|
|
|
4769
4737
|
optional buffer: boolean;
|
|
4770
4738
|
```
|
|
4771
4739
|
|
|
4772
|
-
Defined in: [packages/fs/src/types.ts:81](https://github.com/visulima/visulima/blob/
|
|
4740
|
+
Defined in: [packages/fs/src/types.ts:81](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L81)
|
|
4773
4741
|
|
|
4774
4742
|
Return content as a Buffer. Default: `false`
|
|
4775
4743
|
|
|
@@ -4779,7 +4747,7 @@ Return content as a Buffer. Default: `false`
|
|
|
4779
4747
|
optional compression: C;
|
|
4780
4748
|
```
|
|
4781
4749
|
|
|
4782
|
-
Defined in: [packages/fs/src/types.ts:86](https://github.com/visulima/visulima/blob/
|
|
4750
|
+
Defined in: [packages/fs/src/types.ts:86](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L86)
|
|
4783
4751
|
|
|
4784
4752
|
Compression method to decompress the file against. Default: `none`
|
|
4785
4753
|
|
|
@@ -4789,7 +4757,7 @@ Compression method to decompress the file against. Default: `none`
|
|
|
4789
4757
|
optional encoding: ReadFileEncoding;
|
|
4790
4758
|
```
|
|
4791
4759
|
|
|
4792
|
-
Defined in: [packages/fs/src/types.ts:92](https://github.com/visulima/visulima/blob/
|
|
4760
|
+
Defined in: [packages/fs/src/types.ts:92](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L92)
|
|
4793
4761
|
|
|
4794
4762
|
The encoding to use. Default: `utf8`
|
|
4795
4763
|
|
|
@@ -4803,11 +4771,11 @@ https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings
|
|
|
4803
4771
|
optional flag: number | string;
|
|
4804
4772
|
```
|
|
4805
4773
|
|
|
4806
|
-
Defined in: [packages/fs/src/types.ts:97](https://github.com/visulima/visulima/blob/
|
|
4774
|
+
Defined in: [packages/fs/src/types.ts:97](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L97)
|
|
4807
4775
|
|
|
4808
4776
|
The flag used to open the file. Default: `r`
|
|
4809
4777
|
|
|
4810
|
-
|
|
4778
|
+
---
|
|
4811
4779
|
|
|
4812
4780
|
### ReadJsonOptions
|
|
4813
4781
|
|
|
@@ -4815,7 +4783,7 @@ The flag used to open the file. Default: `r`
|
|
|
4815
4783
|
type ReadJsonOptions = CodeFrameOptions & object;
|
|
4816
4784
|
```
|
|
4817
4785
|
|
|
4818
|
-
Defined in: [packages/fs/src/types.ts:143](https://github.com/visulima/visulima/blob/
|
|
4786
|
+
Defined in: [packages/fs/src/types.ts:143](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L143)
|
|
4819
4787
|
|
|
4820
4788
|
Options for reading and parsing JSON files.
|
|
4821
4789
|
Extends [CodeFrameOptions](#codeframeoptions).
|
|
@@ -4844,7 +4812,7 @@ The raw string content of the file.
|
|
|
4844
4812
|
|
|
4845
4813
|
The transformed string content.
|
|
4846
4814
|
|
|
4847
|
-
|
|
4815
|
+
---
|
|
4848
4816
|
|
|
4849
4817
|
### WriteFileOptions
|
|
4850
4818
|
|
|
@@ -4852,7 +4820,7 @@ The transformed string content.
|
|
|
4852
4820
|
type WriteFileOptions = object;
|
|
4853
4821
|
```
|
|
4854
4822
|
|
|
4855
|
-
Defined in: [packages/fs/src/types.ts:155](https://github.com/visulima/visulima/blob/
|
|
4823
|
+
Defined in: [packages/fs/src/types.ts:155](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L155)
|
|
4856
4824
|
|
|
4857
4825
|
Options for writing files.
|
|
4858
4826
|
|
|
@@ -4864,7 +4832,7 @@ Options for writing files.
|
|
|
4864
4832
|
optional chown: object;
|
|
4865
4833
|
```
|
|
4866
4834
|
|
|
4867
|
-
Defined in: [packages/fs/src/types.ts:159](https://github.com/visulima/visulima/blob/
|
|
4835
|
+
Defined in: [packages/fs/src/types.ts:159](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L159)
|
|
4868
4836
|
|
|
4869
4837
|
The group and user ID used to set the file ownership. Default: `undefined`
|
|
4870
4838
|
|
|
@@ -4886,7 +4854,7 @@ uid: number;
|
|
|
4886
4854
|
optional encoding: BufferEncoding | null;
|
|
4887
4855
|
```
|
|
4888
4856
|
|
|
4889
|
-
Defined in: [packages/fs/src/types.ts:167](https://github.com/visulima/visulima/blob/
|
|
4857
|
+
Defined in: [packages/fs/src/types.ts:167](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L167)
|
|
4890
4858
|
|
|
4891
4859
|
The encoding to use. Default: `utf8`
|
|
4892
4860
|
|
|
@@ -4896,7 +4864,7 @@ The encoding to use. Default: `utf8`
|
|
|
4896
4864
|
optional flag: string;
|
|
4897
4865
|
```
|
|
4898
4866
|
|
|
4899
|
-
Defined in: [packages/fs/src/types.ts:172](https://github.com/visulima/visulima/blob/
|
|
4867
|
+
Defined in: [packages/fs/src/types.ts:172](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L172)
|
|
4900
4868
|
|
|
4901
4869
|
The flag used to write the file. Default: `w`
|
|
4902
4870
|
|
|
@@ -4906,7 +4874,7 @@ The flag used to write the file. Default: `w`
|
|
|
4906
4874
|
optional mode: number;
|
|
4907
4875
|
```
|
|
4908
4876
|
|
|
4909
|
-
Defined in: [packages/fs/src/types.ts:177](https://github.com/visulima/visulima/blob/
|
|
4877
|
+
Defined in: [packages/fs/src/types.ts:177](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L177)
|
|
4910
4878
|
|
|
4911
4879
|
The file mode (permission and sticky bits). Default: `0o666`
|
|
4912
4880
|
|
|
@@ -4916,7 +4884,7 @@ The file mode (permission and sticky bits). Default: `0o666`
|
|
|
4916
4884
|
optional overwrite: boolean;
|
|
4917
4885
|
```
|
|
4918
4886
|
|
|
4919
|
-
Defined in: [packages/fs/src/types.ts:182](https://github.com/visulima/visulima/blob/
|
|
4887
|
+
Defined in: [packages/fs/src/types.ts:182](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L182)
|
|
4920
4888
|
|
|
4921
4889
|
Indicates whether the file should be overwritten if it already exists. Default: `false`
|
|
4922
4890
|
|
|
@@ -4926,11 +4894,11 @@ Indicates whether the file should be overwritten if it already exists. Default:
|
|
|
4926
4894
|
optional recursive: boolean;
|
|
4927
4895
|
```
|
|
4928
4896
|
|
|
4929
|
-
Defined in: [packages/fs/src/types.ts:187](https://github.com/visulima/visulima/blob/
|
|
4897
|
+
Defined in: [packages/fs/src/types.ts:187](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L187)
|
|
4930
4898
|
|
|
4931
4899
|
Recursively create parent directories if needed. Default: `true`
|
|
4932
4900
|
|
|
4933
|
-
|
|
4901
|
+
---
|
|
4934
4902
|
|
|
4935
4903
|
### WriteJsonOptions
|
|
4936
4904
|
|
|
@@ -4938,7 +4906,7 @@ Recursively create parent directories if needed. Default: `true`
|
|
|
4938
4906
|
type WriteJsonOptions = WriteFileOptions & object;
|
|
4939
4907
|
```
|
|
4940
4908
|
|
|
4941
|
-
Defined in: [packages/fs/src/types.ts:208](https://github.com/visulima/visulima/blob/
|
|
4909
|
+
Defined in: [packages/fs/src/types.ts:208](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L208)
|
|
4942
4910
|
|
|
4943
4911
|
Options for writing JSON files.
|
|
4944
4912
|
Extends [WriteFileOptions](#writefileoptions).
|
|
@@ -5003,29 +4971,30 @@ Override the default `JSON.stringify` method.
|
|
|
5003
4971
|
|
|
5004
4972
|
Re-exports [CRLF](eol.md#crlf)
|
|
5005
4973
|
|
|
5006
|
-
|
|
4974
|
+
---
|
|
5007
4975
|
|
|
5008
4976
|
### detect
|
|
5009
4977
|
|
|
5010
4978
|
Re-exports [detect](eol.md#detect)
|
|
5011
4979
|
|
|
5012
|
-
|
|
4980
|
+
---
|
|
5013
4981
|
|
|
5014
4982
|
### EOL
|
|
5015
4983
|
|
|
5016
4984
|
Re-exports [EOL](eol.md#eol)
|
|
5017
4985
|
|
|
5018
|
-
|
|
4986
|
+
---
|
|
5019
4987
|
|
|
5020
4988
|
### format
|
|
5021
4989
|
|
|
5022
4990
|
Re-exports [format](eol.md#format)
|
|
5023
4991
|
|
|
5024
|
-
|
|
4992
|
+
---
|
|
5025
4993
|
|
|
5026
4994
|
### LF
|
|
5027
4995
|
|
|
5028
4996
|
Re-exports [LF](eol.md#lf)
|
|
4997
|
+
|
|
5029
4998
|
# size
|
|
5030
4999
|
|
|
5031
5000
|
## Functions
|
|
@@ -5036,7 +5005,7 @@ Re-exports [LF](eol.md#lf)
|
|
|
5036
5005
|
function brotliSize(input, options?): Promise<number>;
|
|
5037
5006
|
```
|
|
5038
5007
|
|
|
5039
|
-
Defined in: [packages/fs/src/size.ts:222](https://github.com/visulima/visulima/blob/
|
|
5008
|
+
Defined in: [packages/fs/src/size.ts:222](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/size.ts#L222)
|
|
5040
5009
|
|
|
5041
5010
|
Asynchronously calculates the Brotli compressed size of the given input.
|
|
5042
5011
|
The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
@@ -5074,32 +5043,32 @@ const text = "This is a test string for Brotli compression efficiency.";
|
|
|
5074
5043
|
const filePath = join("temp-brotli-file.txt");
|
|
5075
5044
|
|
|
5076
5045
|
async function main() {
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5046
|
+
// From Buffer
|
|
5047
|
+
const buffer = Buffer.from(text);
|
|
5048
|
+
console.log(`Brotli size of buffer: ${await brotliSize(buffer)} bytes`);
|
|
5080
5049
|
|
|
5081
|
-
|
|
5082
|
-
|
|
5050
|
+
// From string (content)
|
|
5051
|
+
console.log(`Brotli size of string content: ${await brotliSize(text)} bytes`);
|
|
5083
5052
|
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5053
|
+
// From file path
|
|
5054
|
+
await writeFile(filePath, text);
|
|
5055
|
+
console.log(`Brotli size of file: ${await brotliSize(filePath)} bytes`);
|
|
5087
5056
|
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5057
|
+
// From URL
|
|
5058
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5059
|
+
console.log(`Brotli size of URL: ${await brotliSize(fileUrl)} bytes`);
|
|
5091
5060
|
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5061
|
+
// From Readable stream
|
|
5062
|
+
const stream = Readable.from(text);
|
|
5063
|
+
console.log(`Brotli size of stream: ${await brotliSize(stream)} bytes`);
|
|
5095
5064
|
|
|
5096
|
-
|
|
5065
|
+
await unlink(filePath); // Clean up temp file
|
|
5097
5066
|
}
|
|
5098
5067
|
|
|
5099
5068
|
main().catch(console.error);
|
|
5100
5069
|
```
|
|
5101
5070
|
|
|
5102
|
-
|
|
5071
|
+
---
|
|
5103
5072
|
|
|
5104
5073
|
### brotliSizeSync()
|
|
5105
5074
|
|
|
@@ -5107,7 +5076,7 @@ main().catch(console.error);
|
|
|
5107
5076
|
function brotliSizeSync(input, options?): number;
|
|
5108
5077
|
```
|
|
5109
5078
|
|
|
5110
|
-
Defined in: [packages/fs/src/size.ts:370](https://github.com/visulima/visulima/blob/
|
|
5079
|
+
Defined in: [packages/fs/src/size.ts:370](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/size.ts#L370)
|
|
5111
5080
|
|
|
5112
5081
|
Synchronously calculates the Brotli compressed size of the given input.
|
|
5113
5082
|
The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
@@ -5152,18 +5121,20 @@ console.log(`Sync Brotli size of string content: ${brotliSizeSync(text)} bytes`)
|
|
|
5152
5121
|
|
|
5153
5122
|
// From file path
|
|
5154
5123
|
try {
|
|
5155
|
-
|
|
5156
|
-
|
|
5124
|
+
writeFileSync(filePath, text);
|
|
5125
|
+
console.log(`Sync Brotli size of file: ${brotliSizeSync(filePath)} bytes`);
|
|
5157
5126
|
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5127
|
+
// From URL
|
|
5128
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5129
|
+
console.log(`Sync Brotli size of URL: ${brotliSizeSync(fileUrl)} bytes`);
|
|
5161
5130
|
} finally {
|
|
5162
|
-
|
|
5131
|
+
try {
|
|
5132
|
+
unlinkSync(filePath);
|
|
5133
|
+
} catch {} // Clean up temp file
|
|
5163
5134
|
}
|
|
5164
5135
|
```
|
|
5165
5136
|
|
|
5166
|
-
|
|
5137
|
+
---
|
|
5167
5138
|
|
|
5168
5139
|
### gzipSize()
|
|
5169
5140
|
|
|
@@ -5171,7 +5142,7 @@ try {
|
|
|
5171
5142
|
function gzipSize(input, options?): Promise<number>;
|
|
5172
5143
|
```
|
|
5173
5144
|
|
|
5174
|
-
Defined in: [packages/fs/src/size.ts:171](https://github.com/visulima/visulima/blob/
|
|
5145
|
+
Defined in: [packages/fs/src/size.ts:171](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/size.ts#L171)
|
|
5175
5146
|
|
|
5176
5147
|
Asynchronously calculates the gzipped size of the given input.
|
|
5177
5148
|
The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
@@ -5209,32 +5180,32 @@ const text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
|
|
5209
5180
|
const filePath = join("temp-file.txt");
|
|
5210
5181
|
|
|
5211
5182
|
async function main() {
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5183
|
+
// From Buffer
|
|
5184
|
+
const buffer = Buffer.from(text);
|
|
5185
|
+
console.log(`Gzip size of buffer: ${await gzipSize(buffer)} bytes`);
|
|
5215
5186
|
|
|
5216
|
-
|
|
5217
|
-
|
|
5187
|
+
// From string (content)
|
|
5188
|
+
console.log(`Gzip size of string content: ${await gzipSize(text)} bytes`);
|
|
5218
5189
|
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5190
|
+
// From file path
|
|
5191
|
+
await writeFile(filePath, text);
|
|
5192
|
+
console.log(`Gzip size of file: ${await gzipSize(filePath)} bytes`);
|
|
5222
5193
|
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5194
|
+
// From URL
|
|
5195
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5196
|
+
console.log(`Gzip size of URL: ${await gzipSize(fileUrl)} bytes`);
|
|
5226
5197
|
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5198
|
+
// From Readable stream
|
|
5199
|
+
const stream = Readable.from(text);
|
|
5200
|
+
console.log(`Gzip size of stream: ${await gzipSize(stream)} bytes`);
|
|
5230
5201
|
|
|
5231
|
-
|
|
5202
|
+
await unlink(filePath); // Clean up temp file
|
|
5232
5203
|
}
|
|
5233
5204
|
|
|
5234
5205
|
main().catch(console.error);
|
|
5235
5206
|
```
|
|
5236
5207
|
|
|
5237
|
-
|
|
5208
|
+
---
|
|
5238
5209
|
|
|
5239
5210
|
### gzipSizeSync()
|
|
5240
5211
|
|
|
@@ -5242,7 +5213,7 @@ main().catch(console.error);
|
|
|
5242
5213
|
function gzipSizeSync(input, options?): number;
|
|
5243
5214
|
```
|
|
5244
5215
|
|
|
5245
|
-
Defined in: [packages/fs/src/size.ts:316](https://github.com/visulima/visulima/blob/
|
|
5216
|
+
Defined in: [packages/fs/src/size.ts:316](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/size.ts#L316)
|
|
5246
5217
|
|
|
5247
5218
|
Synchronously calculates the gzipped size of the given input.
|
|
5248
5219
|
The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
@@ -5287,18 +5258,20 @@ console.log(`Sync Gzip size of string content: ${gzipSizeSync(text)} bytes`);
|
|
|
5287
5258
|
|
|
5288
5259
|
// From file path
|
|
5289
5260
|
try {
|
|
5290
|
-
|
|
5291
|
-
|
|
5261
|
+
writeFileSync(filePath, text);
|
|
5262
|
+
console.log(`Sync Gzip size of file: ${gzipSizeSync(filePath)} bytes`);
|
|
5292
5263
|
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5264
|
+
// From URL
|
|
5265
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5266
|
+
console.log(`Sync Gzip size of URL: ${gzipSizeSync(fileUrl)} bytes`);
|
|
5296
5267
|
} finally {
|
|
5297
|
-
|
|
5268
|
+
try {
|
|
5269
|
+
unlinkSync(filePath);
|
|
5270
|
+
} catch {} // Clean up temp file
|
|
5298
5271
|
}
|
|
5299
5272
|
```
|
|
5300
5273
|
|
|
5301
|
-
|
|
5274
|
+
---
|
|
5302
5275
|
|
|
5303
5276
|
### rawSize()
|
|
5304
5277
|
|
|
@@ -5306,7 +5279,7 @@ try {
|
|
|
5306
5279
|
function rawSize(input): Promise<number>;
|
|
5307
5280
|
```
|
|
5308
5281
|
|
|
5309
|
-
Defined in: [packages/fs/src/size.ts:272](https://github.com/visulima/visulima/blob/
|
|
5282
|
+
Defined in: [packages/fs/src/size.ts:272](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/size.ts#L272)
|
|
5310
5283
|
|
|
5311
5284
|
Asynchronously calculates the raw (uncompressed) size of the given input.
|
|
5312
5285
|
The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
@@ -5338,32 +5311,32 @@ const text = "Hello, World!";
|
|
|
5338
5311
|
const filePath = join("temp-raw-file.txt");
|
|
5339
5312
|
|
|
5340
5313
|
async function main() {
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5314
|
+
// From Buffer
|
|
5315
|
+
const buffer = Buffer.from(text);
|
|
5316
|
+
console.log(`Raw size of buffer: ${await rawSize(buffer)} bytes`);
|
|
5344
5317
|
|
|
5345
|
-
|
|
5346
|
-
|
|
5318
|
+
// From string (content)
|
|
5319
|
+
console.log(`Raw size of string content: ${await rawSize(text)} bytes`);
|
|
5347
5320
|
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5321
|
+
// From file path
|
|
5322
|
+
await writeFile(filePath, text);
|
|
5323
|
+
console.log(`Raw size of file: ${await rawSize(filePath)} bytes`);
|
|
5351
5324
|
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5325
|
+
// From URL
|
|
5326
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5327
|
+
console.log(`Raw size of URL: ${await rawSize(fileUrl)} bytes`);
|
|
5355
5328
|
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5329
|
+
// From Readable stream
|
|
5330
|
+
const stream = Readable.from(text);
|
|
5331
|
+
console.log(`Raw size of stream: ${await rawSize(stream)} bytes`);
|
|
5359
5332
|
|
|
5360
|
-
|
|
5333
|
+
await unlink(filePath); // Clean up temp file
|
|
5361
5334
|
}
|
|
5362
5335
|
|
|
5363
5336
|
main().catch(console.error);
|
|
5364
5337
|
```
|
|
5365
5338
|
|
|
5366
|
-
|
|
5339
|
+
---
|
|
5367
5340
|
|
|
5368
5341
|
### rawSizeSync()
|
|
5369
5342
|
|
|
@@ -5371,7 +5344,7 @@ main().catch(console.error);
|
|
|
5371
5344
|
function rawSizeSync(input): number;
|
|
5372
5345
|
```
|
|
5373
5346
|
|
|
5374
|
-
Defined in: [packages/fs/src/size.ts:424](https://github.com/visulima/visulima/blob/
|
|
5347
|
+
Defined in: [packages/fs/src/size.ts:424](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/size.ts#L424)
|
|
5375
5348
|
|
|
5376
5349
|
Synchronously calculates the raw (uncompressed) size of the given input.
|
|
5377
5350
|
The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
@@ -5411,23 +5384,26 @@ console.log(`Sync Raw size of string content: ${rawSizeSync(text)} bytes`);
|
|
|
5411
5384
|
|
|
5412
5385
|
// From file path
|
|
5413
5386
|
try {
|
|
5414
|
-
|
|
5415
|
-
|
|
5387
|
+
writeFileSync(filePath, text);
|
|
5388
|
+
console.log(`Sync Raw size of file: ${rawSizeSync(filePath)} bytes`);
|
|
5416
5389
|
|
|
5417
|
-
|
|
5418
|
-
|
|
5419
|
-
|
|
5390
|
+
// From URL
|
|
5391
|
+
const fileUrl = new URL(`file://${filePath}`);
|
|
5392
|
+
console.log(`Sync Raw size of URL: ${rawSizeSync(fileUrl)} bytes`);
|
|
5420
5393
|
} finally {
|
|
5421
|
-
|
|
5394
|
+
try {
|
|
5395
|
+
unlinkSync(filePath);
|
|
5396
|
+
} catch {} // Clean up temp file
|
|
5422
5397
|
}
|
|
5423
5398
|
```
|
|
5399
|
+
|
|
5424
5400
|
# utils
|
|
5425
5401
|
|
|
5426
5402
|
## Classes
|
|
5427
5403
|
|
|
5428
5404
|
### JSONError
|
|
5429
5405
|
|
|
5430
|
-
Defined in: [packages/fs/src/error/json-error.ts:39](https://github.com/visulima/visulima/blob/
|
|
5406
|
+
Defined in: [packages/fs/src/error/json-error.ts:39](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/json-error.ts#L39)
|
|
5431
5407
|
|
|
5432
5408
|
Custom error class for handling JSON parsing or related errors.
|
|
5433
5409
|
It can optionally include a file name and a code frame for better debugging.
|
|
@@ -5440,31 +5416,31 @@ import { readJsonSync } from "@visulima/fs"; // Or any function that might throw
|
|
|
5440
5416
|
import { join } from "node:path";
|
|
5441
5417
|
|
|
5442
5418
|
try {
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5419
|
+
// Imagine readJsonSync encounters a malformed JSON file and throws JSONError
|
|
5420
|
+
// Forcing the scenario for demonstration:
|
|
5421
|
+
const simulateJsonError = (filePath, content) => {
|
|
5422
|
+
const err = new JSONError(`Unexpected token '}' at position 15`);
|
|
5423
|
+
err.fileName = filePath;
|
|
5424
|
+
// A real implementation might generate a code frame using a library
|
|
5425
|
+
err.codeFrame = ` 13 | "key": "value",
|
|
5450
5426
|
> 14 | "anotherKey": "anotherValue",}
|
|
5451
5427
|
| ^
|
|
5452
5428
|
15 | "lastKey": "end"
|
|
5453
5429
|
`;
|
|
5454
|
-
|
|
5455
|
-
|
|
5430
|
+
throw err;
|
|
5431
|
+
};
|
|
5456
5432
|
|
|
5457
|
-
|
|
5458
|
-
|
|
5433
|
+
simulateJsonError(join("path", "to", "corrupted.json"), '{ "key": "value", "anotherKey": "anotherValue",} ');
|
|
5434
|
+
// const jsonData = readJsonSync(join("path", "to", "corrupted.json"));
|
|
5459
5435
|
} catch (error) {
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
5436
|
+
if (error instanceof JSONError) {
|
|
5437
|
+
console.error(`JSON Error: ${error.message}`);
|
|
5438
|
+
// message property will include fileName and codeFrame if they were set.
|
|
5439
|
+
// console.error(`File: ${error.fileName}`);
|
|
5440
|
+
// console.error(`Code Frame:\n${error.codeFrame}`);
|
|
5441
|
+
} else {
|
|
5442
|
+
console.error("An unexpected error occurred:", error);
|
|
5443
|
+
}
|
|
5468
5444
|
}
|
|
5469
5445
|
```
|
|
5470
5446
|
|
|
@@ -5480,7 +5456,7 @@ try {
|
|
|
5480
5456
|
new JSONError(message): JSONError;
|
|
5481
5457
|
```
|
|
5482
5458
|
|
|
5483
|
-
Defined in: [packages/fs/src/error/json-error.ts:53](https://github.com/visulima/visulima/blob/
|
|
5459
|
+
Defined in: [packages/fs/src/error/json-error.ts:53](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/json-error.ts#L53)
|
|
5484
5460
|
|
|
5485
5461
|
Creates a new JSONError instance.
|
|
5486
5462
|
|
|
@@ -5499,7 +5475,7 @@ The primary error message.
|
|
|
5499
5475
|
###### Overrides
|
|
5500
5476
|
|
|
5501
5477
|
```ts
|
|
5502
|
-
Error.constructor
|
|
5478
|
+
Error.constructor;
|
|
5503
5479
|
```
|
|
5504
5480
|
|
|
5505
5481
|
#### Accessors
|
|
@@ -5512,7 +5488,7 @@ Error.constructor
|
|
|
5512
5488
|
get message(): string;
|
|
5513
5489
|
```
|
|
5514
5490
|
|
|
5515
|
-
Defined in: [packages/fs/src/error/json-error.ts:63](https://github.com/visulima/visulima/blob/
|
|
5491
|
+
Defined in: [packages/fs/src/error/json-error.ts:63](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/json-error.ts#L63)
|
|
5516
5492
|
|
|
5517
5493
|
###### Returns
|
|
5518
5494
|
|
|
@@ -5524,7 +5500,7 @@ Defined in: [packages/fs/src/error/json-error.ts:63](https://github.com/visulima
|
|
|
5524
5500
|
set message(message): void;
|
|
5525
5501
|
```
|
|
5526
5502
|
|
|
5527
|
-
Defined in: [packages/fs/src/error/json-error.ts:67](https://github.com/visulima/visulima/blob/
|
|
5503
|
+
Defined in: [packages/fs/src/error/json-error.ts:67](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/json-error.ts#L67)
|
|
5528
5504
|
|
|
5529
5505
|
###### Parameters
|
|
5530
5506
|
|
|
@@ -5539,7 +5515,7 @@ Defined in: [packages/fs/src/error/json-error.ts:67](https://github.com/visulima
|
|
|
5539
5515
|
###### Overrides
|
|
5540
5516
|
|
|
5541
5517
|
```ts
|
|
5542
|
-
Error.message
|
|
5518
|
+
Error.message;
|
|
5543
5519
|
```
|
|
5544
5520
|
|
|
5545
5521
|
#### Methods
|
|
@@ -5550,7 +5526,7 @@ Error.message
|
|
|
5550
5526
|
static captureStackTrace(targetObject, constructorOpt?): void;
|
|
5551
5527
|
```
|
|
5552
5528
|
|
|
5553
|
-
Defined in:
|
|
5529
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:91
|
|
5554
5530
|
|
|
5555
5531
|
Create .stack property on a target object
|
|
5556
5532
|
|
|
@@ -5571,7 +5547,7 @@ Create .stack property on a target object
|
|
|
5571
5547
|
###### Inherited from
|
|
5572
5548
|
|
|
5573
5549
|
```ts
|
|
5574
|
-
Error.captureStackTrace
|
|
5550
|
+
Error.captureStackTrace;
|
|
5575
5551
|
```
|
|
5576
5552
|
|
|
5577
5553
|
#### Properties
|
|
@@ -5582,12 +5558,12 @@ Error.captureStackTrace
|
|
|
5582
5558
|
optional cause: unknown;
|
|
5583
5559
|
```
|
|
5584
5560
|
|
|
5585
|
-
Defined in:
|
|
5561
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26
|
|
5586
5562
|
|
|
5587
5563
|
###### Inherited from
|
|
5588
5564
|
|
|
5589
5565
|
```ts
|
|
5590
|
-
Error.cause
|
|
5566
|
+
Error.cause;
|
|
5591
5567
|
```
|
|
5592
5568
|
|
|
5593
5569
|
##### codeFrame
|
|
@@ -5596,7 +5572,7 @@ Error.cause
|
|
|
5596
5572
|
codeFrame: string;
|
|
5597
5573
|
```
|
|
5598
5574
|
|
|
5599
|
-
Defined in: [packages/fs/src/error/json-error.ts:42](https://github.com/visulima/visulima/blob/
|
|
5575
|
+
Defined in: [packages/fs/src/error/json-error.ts:42](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/json-error.ts#L42)
|
|
5600
5576
|
|
|
5601
5577
|
##### fileName
|
|
5602
5578
|
|
|
@@ -5604,7 +5580,7 @@ Defined in: [packages/fs/src/error/json-error.ts:42](https://github.com/visulima
|
|
|
5604
5580
|
fileName: string;
|
|
5605
5581
|
```
|
|
5606
5582
|
|
|
5607
|
-
Defined in: [packages/fs/src/error/json-error.ts:40](https://github.com/visulima/visulima/blob/
|
|
5583
|
+
Defined in: [packages/fs/src/error/json-error.ts:40](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/json-error.ts#L40)
|
|
5608
5584
|
|
|
5609
5585
|
##### name
|
|
5610
5586
|
|
|
@@ -5612,12 +5588,12 @@ Defined in: [packages/fs/src/error/json-error.ts:40](https://github.com/visulima
|
|
|
5612
5588
|
readonly name: "JSONError" = "JSONError";
|
|
5613
5589
|
```
|
|
5614
5590
|
|
|
5615
|
-
Defined in: [packages/fs/src/error/json-error.ts:45](https://github.com/visulima/visulima/blob/
|
|
5591
|
+
Defined in: [packages/fs/src/error/json-error.ts:45](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/error/json-error.ts#L45)
|
|
5616
5592
|
|
|
5617
5593
|
###### Overrides
|
|
5618
5594
|
|
|
5619
5595
|
```ts
|
|
5620
|
-
Error.name
|
|
5596
|
+
Error.name;
|
|
5621
5597
|
```
|
|
5622
5598
|
|
|
5623
5599
|
##### stack?
|
|
@@ -5626,12 +5602,12 @@ Error.name
|
|
|
5626
5602
|
optional stack: string;
|
|
5627
5603
|
```
|
|
5628
5604
|
|
|
5629
|
-
Defined in:
|
|
5605
|
+
Defined in: node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts:1078
|
|
5630
5606
|
|
|
5631
5607
|
###### Inherited from
|
|
5632
5608
|
|
|
5633
5609
|
```ts
|
|
5634
|
-
Error.stack
|
|
5610
|
+
Error.stack;
|
|
5635
5611
|
```
|
|
5636
5612
|
|
|
5637
5613
|
##### prepareStackTrace()?
|
|
@@ -5640,7 +5616,7 @@ Error.stack
|
|
|
5640
5616
|
static optional prepareStackTrace: (err, stackTraces) => any;
|
|
5641
5617
|
```
|
|
5642
5618
|
|
|
5643
|
-
Defined in:
|
|
5619
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:98
|
|
5644
5620
|
|
|
5645
5621
|
Optional override for formatting stack traces
|
|
5646
5622
|
|
|
@@ -5665,7 +5641,7 @@ https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
|
|
5665
5641
|
###### Inherited from
|
|
5666
5642
|
|
|
5667
5643
|
```ts
|
|
5668
|
-
Error.prepareStackTrace
|
|
5644
|
+
Error.prepareStackTrace;
|
|
5669
5645
|
```
|
|
5670
5646
|
|
|
5671
5647
|
##### stackTraceLimit
|
|
@@ -5674,12 +5650,12 @@ Error.prepareStackTrace
|
|
|
5674
5650
|
static stackTraceLimit: number;
|
|
5675
5651
|
```
|
|
5676
5652
|
|
|
5677
|
-
Defined in:
|
|
5653
|
+
Defined in: node_modules/.pnpm/@types+node@18.19.71/node_modules/@types/node/globals.d.ts:100
|
|
5678
5654
|
|
|
5679
5655
|
###### Inherited from
|
|
5680
5656
|
|
|
5681
5657
|
```ts
|
|
5682
|
-
Error.stackTraceLimit
|
|
5658
|
+
Error.stackTraceLimit;
|
|
5683
5659
|
```
|
|
5684
5660
|
|
|
5685
5661
|
## Functions
|
|
@@ -5690,7 +5666,7 @@ Error.stackTraceLimit
|
|
|
5690
5666
|
function assertValidFileContents(contents): void;
|
|
5691
5667
|
```
|
|
5692
5668
|
|
|
5693
|
-
Defined in: [packages/fs/src/utils/assert-valid-file-contents.ts:28](https://github.com/visulima/visulima/blob/
|
|
5669
|
+
Defined in: [packages/fs/src/utils/assert-valid-file-contents.ts:28](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/utils/assert-valid-file-contents.ts#L28)
|
|
5694
5670
|
|
|
5695
5671
|
Asserts that the provided contents are valid for writing to a file.
|
|
5696
5672
|
Valid contents can be a string, an ArrayBuffer, or an ArrayBuffer view (e.g., Uint8Array).
|
|
@@ -5717,22 +5693,22 @@ If the contents are not a string, ArrayBuffer, or ArrayBuffer view.
|
|
|
5717
5693
|
import { assertValidFileContents } from "@visulima/fs"; // Assuming this util is exported
|
|
5718
5694
|
|
|
5719
5695
|
try {
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5696
|
+
assertValidFileContents("Hello, world!");
|
|
5697
|
+
assertValidFileContents(new Uint8Array([72, 101, 108, 108, 111])); // "Hello"
|
|
5698
|
+
assertValidFileContents(new ArrayBuffer(8));
|
|
5699
|
+
console.log("File contents are valid.");
|
|
5724
5700
|
} catch (error) {
|
|
5725
|
-
|
|
5701
|
+
console.error(error.message); // File contents must be a string, ArrayBuffer, or ArrayBuffer view.
|
|
5726
5702
|
}
|
|
5727
5703
|
|
|
5728
5704
|
try {
|
|
5729
|
-
|
|
5705
|
+
assertValidFileContents(123); // Invalid content type
|
|
5730
5706
|
} catch (error) {
|
|
5731
|
-
|
|
5707
|
+
console.error(error.message); // File contents must be a string, ArrayBuffer, or ArrayBuffer view.
|
|
5732
5708
|
}
|
|
5733
5709
|
```
|
|
5734
5710
|
|
|
5735
|
-
|
|
5711
|
+
---
|
|
5736
5712
|
|
|
5737
5713
|
### assertValidFileOrDirectoryPath()
|
|
5738
5714
|
|
|
@@ -5740,7 +5716,7 @@ try {
|
|
|
5740
5716
|
function assertValidFileOrDirectoryPath(fileOrDirectoryPath): void;
|
|
5741
5717
|
```
|
|
5742
5718
|
|
|
5743
|
-
Defined in: [packages/fs/src/utils/assert-valid-file-or-directory-path.ts:27](https://github.com/visulima/visulima/blob/
|
|
5719
|
+
Defined in: [packages/fs/src/utils/assert-valid-file-or-directory-path.ts:27](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/utils/assert-valid-file-or-directory-path.ts#L27)
|
|
5744
5720
|
|
|
5745
5721
|
Asserts that the provided path is a valid file or directory path.
|
|
5746
5722
|
A valid path must be a non-empty string or a URL instance.
|
|
@@ -5767,21 +5743,21 @@ If the path is not a non-empty string or a URL.
|
|
|
5767
5743
|
import { assertValidFileOrDirectoryPath } from "@visulima/fs"; // Assuming this util is exported
|
|
5768
5744
|
|
|
5769
5745
|
try {
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5746
|
+
assertValidFileOrDirectoryPath("/path/to/file.txt");
|
|
5747
|
+
assertValidFileOrDirectoryPath(new URL("file:///path/to/file.txt"));
|
|
5748
|
+
console.log("Path is valid.");
|
|
5773
5749
|
} catch (error) {
|
|
5774
|
-
|
|
5750
|
+
console.error(error.message); // Path must be a non-empty string or URL.
|
|
5775
5751
|
}
|
|
5776
5752
|
|
|
5777
5753
|
try {
|
|
5778
|
-
|
|
5754
|
+
assertValidFileOrDirectoryPath(""); // Invalid path
|
|
5779
5755
|
} catch (error) {
|
|
5780
|
-
|
|
5756
|
+
console.error(error.message); // Path must be a non-empty string or URL.
|
|
5781
5757
|
}
|
|
5782
5758
|
```
|
|
5783
5759
|
|
|
5784
|
-
|
|
5760
|
+
---
|
|
5785
5761
|
|
|
5786
5762
|
### parseJson()
|
|
5787
5763
|
|
|
@@ -5822,49 +5798,45 @@ const jsonString = '{"name": "John Doe", "age": 30, "city": "New York"}';
|
|
|
5822
5798
|
const malformedJson = '{"name": "Jane Doe", "age": "thirty}'; // Missing quote
|
|
5823
5799
|
|
|
5824
5800
|
try {
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
// With filename for better error reporting
|
|
5837
|
-
const user = parseJson(malformedJson, "user-data.json");
|
|
5801
|
+
const data = parseJson(jsonString);
|
|
5802
|
+
console.log(data.name); // Output: John Doe
|
|
5803
|
+
|
|
5804
|
+
const dataWithReviver = parseJson(jsonString, (key, value) => {
|
|
5805
|
+
if (key === "age") {
|
|
5806
|
+
return value + 5;
|
|
5807
|
+
}
|
|
5808
|
+
return value;
|
|
5809
|
+
});
|
|
5810
|
+
console.log(dataWithReviver.age); // Output: 35
|
|
5838
5811
|
|
|
5812
|
+
// With filename for better error reporting
|
|
5813
|
+
const user = parseJson(malformedJson, "user-data.json");
|
|
5839
5814
|
} catch (error) {
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5815
|
+
// error will be an instance of JsonError
|
|
5816
|
+
console.error(error.message);
|
|
5817
|
+
// Example error message:
|
|
5818
|
+
// Unexpected token } in JSON at position 37 in user-data.json
|
|
5819
|
+
//
|
|
5820
|
+
// 35 | "name": "Jane Doe",
|
|
5821
|
+
// > 36 | "age": "thirty}
|
|
5822
|
+
// | ^
|
|
5823
|
+
// 37 |
|
|
5824
|
+
if (error.fileName) {
|
|
5825
|
+
console.error(`Error in file: ${error.fileName}`);
|
|
5826
|
+
}
|
|
5827
|
+
if (error.codeFrame) {
|
|
5828
|
+
console.error(error.codeFrame);
|
|
5829
|
+
}
|
|
5855
5830
|
}
|
|
5856
5831
|
```
|
|
5857
5832
|
|
|
5858
5833
|
#### Call Signature
|
|
5859
5834
|
|
|
5860
5835
|
```ts
|
|
5861
|
-
function parseJson<T>(
|
|
5862
|
-
string,
|
|
5863
|
-
filename?,
|
|
5864
|
-
options?): T;
|
|
5836
|
+
function parseJson<T>(string, filename?, options?): T;
|
|
5865
5837
|
```
|
|
5866
5838
|
|
|
5867
|
-
Defined in: [packages/fs/src/utils/parse-json.ts:60](https://github.com/visulima/visulima/blob/
|
|
5839
|
+
Defined in: [packages/fs/src/utils/parse-json.ts:60](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/utils/parse-json.ts#L60)
|
|
5868
5840
|
|
|
5869
5841
|
##### Type Parameters
|
|
5870
5842
|
|
|
@@ -5893,14 +5865,10 @@ Defined in: [packages/fs/src/utils/parse-json.ts:60](https://github.com/visulima
|
|
|
5893
5865
|
#### Call Signature
|
|
5894
5866
|
|
|
5895
5867
|
```ts
|
|
5896
|
-
function parseJson<T>(
|
|
5897
|
-
string,
|
|
5898
|
-
reviver,
|
|
5899
|
-
fileName?,
|
|
5900
|
-
options?): T;
|
|
5868
|
+
function parseJson<T>(string, reviver, fileName?, options?): T;
|
|
5901
5869
|
```
|
|
5902
5870
|
|
|
5903
|
-
Defined in: [packages/fs/src/utils/parse-json.ts:61](https://github.com/visulima/visulima/blob/
|
|
5871
|
+
Defined in: [packages/fs/src/utils/parse-json.ts:61](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/utils/parse-json.ts#L61)
|
|
5904
5872
|
|
|
5905
5873
|
##### Type Parameters
|
|
5906
5874
|
|
|
@@ -5930,7 +5898,7 @@ Defined in: [packages/fs/src/utils/parse-json.ts:61](https://github.com/visulima
|
|
|
5930
5898
|
|
|
5931
5899
|
`T`
|
|
5932
5900
|
|
|
5933
|
-
|
|
5901
|
+
---
|
|
5934
5902
|
|
|
5935
5903
|
### stripJsonComments()
|
|
5936
5904
|
|
|
@@ -5938,10 +5906,10 @@ Defined in: [packages/fs/src/utils/parse-json.ts:61](https://github.com/visulima
|
|
|
5938
5906
|
function stripJsonComments(jsonString, options?): string;
|
|
5939
5907
|
```
|
|
5940
5908
|
|
|
5941
|
-
Defined in: [packages/fs/src/utils/strip-json-comments.ts:46](https://github.com/visulima/visulima/blob/
|
|
5909
|
+
Defined in: [packages/fs/src/utils/strip-json-comments.ts:46](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/utils/strip-json-comments.ts#L46)
|
|
5942
5910
|
|
|
5943
5911
|
Strips comments from a JSON string.
|
|
5944
|
-
Handles both single-line (//) and multi-line (
|
|
5912
|
+
Handles both single-line (//) and multi-line (/_ ... _/) comments.
|
|
5945
5913
|
|
|
5946
5914
|
#### Parameters
|
|
5947
5915
|
|
|
@@ -6009,7 +5977,7 @@ console.log(strippedWithoutWhitespace);
|
|
|
6009
5977
|
const toPath: (urlOrPath) => string;
|
|
6010
5978
|
```
|
|
6011
5979
|
|
|
6012
|
-
Defined in:
|
|
5980
|
+
Defined in: node_modules/.pnpm/@visulima+path@1.3.6/node_modules/@visulima/path/dist/utils.d.mts:7
|
|
6013
5981
|
|
|
6014
5982
|
#### Parameters
|
|
6015
5983
|
|
|
@@ -6020,6 +5988,7 @@ Defined in: node\_modules/.pnpm/@visulima+path@1.4.0/node\_modules/@visulima/pat
|
|
|
6020
5988
|
#### Returns
|
|
6021
5989
|
|
|
6022
5990
|
`string`
|
|
5991
|
+
|
|
6023
5992
|
# yaml
|
|
6024
5993
|
|
|
6025
5994
|
## Functions
|
|
@@ -6043,7 +6012,7 @@ An optional reviver function (similar to `JSON.parse` reviver) or the options ob
|
|
|
6043
6012
|
#### Param
|
|
6044
6013
|
|
|
6045
6014
|
Optional configuration for reading and parsing the YAML file. See ReadYamlOptions.
|
|
6046
|
-
|
|
6015
|
+
If `reviver` is an object, this argument is ignored.
|
|
6047
6016
|
|
|
6048
6017
|
#### Example
|
|
6049
6018
|
|
|
@@ -6052,24 +6021,23 @@ import { readYaml } from "@visulima/fs";
|
|
|
6052
6021
|
import { join } from "node:path";
|
|
6053
6022
|
|
|
6054
6023
|
const readMyYaml = async () => {
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
}
|
|
6024
|
+
try {
|
|
6025
|
+
const data = await readYaml(join("path", "to", "my-config.yaml"));
|
|
6026
|
+
console.log("Config data:", data);
|
|
6027
|
+
|
|
6028
|
+
// With a reviver function
|
|
6029
|
+
const dataWithReviver = await readYaml(join("path", "to", "another.yaml"), (key, value) => {
|
|
6030
|
+
if (key === "date") return new Date(value);
|
|
6031
|
+
return value;
|
|
6032
|
+
});
|
|
6033
|
+
console.log("Date field is now a Date object:", dataWithReviver.date);
|
|
6034
|
+
|
|
6035
|
+
// With options (e.g., for schema validation - assuming yaml options are passed correctly)
|
|
6036
|
+
// const dataWithOptions = await readYaml(join("path", "to", "options.yaml"), { schema: 'failsafe' });
|
|
6037
|
+
// console.log(dataWithOptions);
|
|
6038
|
+
} catch (error) {
|
|
6039
|
+
console.error("Failed to read or parse YAML file:", error);
|
|
6040
|
+
}
|
|
6073
6041
|
};
|
|
6074
6042
|
|
|
6075
6043
|
readMyYaml();
|
|
@@ -6081,7 +6049,7 @@ readMyYaml();
|
|
|
6081
6049
|
function readYaml<R>(path, options?): Promise<R>;
|
|
6082
6050
|
```
|
|
6083
6051
|
|
|
6084
|
-
Defined in: [packages/fs/src/read/read-yaml.ts:6](https://github.com/visulima/visulima/blob/
|
|
6052
|
+
Defined in: [packages/fs/src/read/read-yaml.ts:6](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/read/read-yaml.ts#L6)
|
|
6085
6053
|
|
|
6086
6054
|
##### Type Parameters
|
|
6087
6055
|
|
|
@@ -6106,13 +6074,10 @@ Defined in: [packages/fs/src/read/read-yaml.ts:6](https://github.com/visulima/vi
|
|
|
6106
6074
|
#### Call Signature
|
|
6107
6075
|
|
|
6108
6076
|
```ts
|
|
6109
|
-
function readYaml<R>(
|
|
6110
|
-
path,
|
|
6111
|
-
reviver?,
|
|
6112
|
-
options?): Promise<R>;
|
|
6077
|
+
function readYaml<R>(path, reviver?, options?): Promise<R>;
|
|
6113
6078
|
```
|
|
6114
6079
|
|
|
6115
|
-
Defined in: [packages/fs/src/read/read-yaml.ts:7](https://github.com/visulima/visulima/blob/
|
|
6080
|
+
Defined in: [packages/fs/src/read/read-yaml.ts:7](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/read/read-yaml.ts#L7)
|
|
6116
6081
|
|
|
6117
6082
|
##### Type Parameters
|
|
6118
6083
|
|
|
@@ -6138,7 +6103,7 @@ Defined in: [packages/fs/src/read/read-yaml.ts:7](https://github.com/visulima/vi
|
|
|
6138
6103
|
|
|
6139
6104
|
`Promise`\<`R`\>
|
|
6140
6105
|
|
|
6141
|
-
|
|
6106
|
+
---
|
|
6142
6107
|
|
|
6143
6108
|
### readYamlSync()
|
|
6144
6109
|
|
|
@@ -6159,7 +6124,7 @@ An optional reviver function (similar to `JSON.parse` reviver) or the options ob
|
|
|
6159
6124
|
#### Param
|
|
6160
6125
|
|
|
6161
6126
|
Optional configuration for reading and parsing the YAML file. See ReadYamlOptions.
|
|
6162
|
-
|
|
6127
|
+
If `reviver` is an object, this argument is ignored.
|
|
6163
6128
|
|
|
6164
6129
|
#### Example
|
|
6165
6130
|
|
|
@@ -6168,22 +6133,21 @@ import { readYamlSync } from "@visulima/fs";
|
|
|
6168
6133
|
import { join } from "node:path";
|
|
6169
6134
|
|
|
6170
6135
|
try {
|
|
6171
|
-
|
|
6172
|
-
|
|
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);
|
|
6136
|
+
const data = readYamlSync(join("path", "to", "my-config.yaml"));
|
|
6137
|
+
console.log("Config data:", data);
|
|
6180
6138
|
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6139
|
+
// With a reviver function
|
|
6140
|
+
const dataWithReviver = readYamlSync(join("path", "to", "another.yaml"), (key, value) => {
|
|
6141
|
+
if (key === "date") return new Date(value);
|
|
6142
|
+
return value;
|
|
6143
|
+
});
|
|
6144
|
+
console.log("Date field is now a Date object:", dataWithReviver.date);
|
|
6184
6145
|
|
|
6146
|
+
// With options (e.g., for schema validation - assuming yaml options are passed correctly)
|
|
6147
|
+
// const dataWithOptions = readYamlSync(join("path", "to", "options.yaml"), { schema: 'failsafe' });
|
|
6148
|
+
// console.log(dataWithOptions);
|
|
6185
6149
|
} catch (error) {
|
|
6186
|
-
|
|
6150
|
+
console.error("Failed to read or parse YAML file:", error);
|
|
6187
6151
|
}
|
|
6188
6152
|
```
|
|
6189
6153
|
|
|
@@ -6193,7 +6157,7 @@ try {
|
|
|
6193
6157
|
function readYamlSync<R>(path, options?): R;
|
|
6194
6158
|
```
|
|
6195
6159
|
|
|
6196
|
-
Defined in: [packages/fs/src/read/read-yaml-sync.ts:6](https://github.com/visulima/visulima/blob/
|
|
6160
|
+
Defined in: [packages/fs/src/read/read-yaml-sync.ts:6](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/read/read-yaml-sync.ts#L6)
|
|
6197
6161
|
|
|
6198
6162
|
##### Type Parameters
|
|
6199
6163
|
|
|
@@ -6218,13 +6182,10 @@ Defined in: [packages/fs/src/read/read-yaml-sync.ts:6](https://github.com/visuli
|
|
|
6218
6182
|
#### Call Signature
|
|
6219
6183
|
|
|
6220
6184
|
```ts
|
|
6221
|
-
function readYamlSync<R>(
|
|
6222
|
-
path,
|
|
6223
|
-
reviver?,
|
|
6224
|
-
options?): R;
|
|
6185
|
+
function readYamlSync<R>(path, reviver?, options?): R;
|
|
6225
6186
|
```
|
|
6226
6187
|
|
|
6227
|
-
Defined in: [packages/fs/src/read/read-yaml-sync.ts:7](https://github.com/visulima/visulima/blob/
|
|
6188
|
+
Defined in: [packages/fs/src/read/read-yaml-sync.ts:7](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/read/read-yaml-sync.ts#L7)
|
|
6228
6189
|
|
|
6229
6190
|
##### Type Parameters
|
|
6230
6191
|
|
|
@@ -6250,7 +6211,7 @@ Defined in: [packages/fs/src/read/read-yaml-sync.ts:7](https://github.com/visuli
|
|
|
6250
6211
|
|
|
6251
6212
|
`R`
|
|
6252
6213
|
|
|
6253
|
-
|
|
6214
|
+
---
|
|
6254
6215
|
|
|
6255
6216
|
### writeYaml()
|
|
6256
6217
|
|
|
@@ -6267,13 +6228,13 @@ The data to serialize and write. Can be any JavaScript value that can be stringi
|
|
|
6267
6228
|
#### Param
|
|
6268
6229
|
|
|
6269
6230
|
Optional. A replacer function or an array of keys to include, or the options object itself.
|
|
6270
|
-
|
|
6231
|
+
See `yaml.stringify` documentation for more details.
|
|
6271
6232
|
|
|
6272
6233
|
#### Param
|
|
6273
6234
|
|
|
6274
6235
|
Optional. Configuration for writing and stringifying the YAML file. See WriteYamlOptions.
|
|
6275
|
-
|
|
6276
|
-
|
|
6236
|
+
If `replacer` is an object and not a function/array, it's treated as `options`.
|
|
6237
|
+
The `space` property within options can be a number for spaces or a string for tabs/etc.
|
|
6277
6238
|
|
|
6278
6239
|
#### Example
|
|
6279
6240
|
|
|
@@ -6282,19 +6243,19 @@ import { writeYaml } from "@visulima/fs";
|
|
|
6282
6243
|
import { join } from "node:path";
|
|
6283
6244
|
|
|
6284
6245
|
const writeMyYaml = async () => {
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
|
|
6296
|
-
|
|
6297
|
-
|
|
6246
|
+
try {
|
|
6247
|
+
await writeYaml(join("/tmp", "my-data.yaml"), { name: "John Doe", age: 30, city: "New York" });
|
|
6248
|
+
console.log("YAML file written successfully.");
|
|
6249
|
+
|
|
6250
|
+
await writeYaml(join("/tmp", "another-data.yaml"), { user: "jane", details: { id: 1, status: "active" } }, null, 2);
|
|
6251
|
+
console.log("Another YAML file written with 2 spaces indentation.");
|
|
6252
|
+
|
|
6253
|
+
const customReplacer = (key, value) => (key === "age" ? undefined : value);
|
|
6254
|
+
await writeYaml(join("/tmp", "filtered-data.yaml"), { name: "Smith", age: 45, occupation: "Engineer" }, customReplacer, { space: "\t" });
|
|
6255
|
+
console.log("Filtered YAML file written with tab indentation.");
|
|
6256
|
+
} catch (error) {
|
|
6257
|
+
console.error("Failed to write YAML file:", error);
|
|
6258
|
+
}
|
|
6298
6259
|
};
|
|
6299
6260
|
|
|
6300
6261
|
writeMyYaml();
|
|
@@ -6303,13 +6264,10 @@ writeMyYaml();
|
|
|
6303
6264
|
#### Call Signature
|
|
6304
6265
|
|
|
6305
6266
|
```ts
|
|
6306
|
-
function writeYaml(
|
|
6307
|
-
path,
|
|
6308
|
-
data,
|
|
6309
|
-
options?): Promise<void>;
|
|
6267
|
+
function writeYaml(path, data, options?): Promise<void>;
|
|
6310
6268
|
```
|
|
6311
6269
|
|
|
6312
|
-
Defined in: [packages/fs/src/write/write-yaml.ts:6](https://github.com/visulima/visulima/blob/
|
|
6270
|
+
Defined in: [packages/fs/src/write/write-yaml.ts:6](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/write/write-yaml.ts#L6)
|
|
6313
6271
|
|
|
6314
6272
|
##### Parameters
|
|
6315
6273
|
|
|
@@ -6332,14 +6290,10 @@ Defined in: [packages/fs/src/write/write-yaml.ts:6](https://github.com/visulima/
|
|
|
6332
6290
|
#### Call Signature
|
|
6333
6291
|
|
|
6334
6292
|
```ts
|
|
6335
|
-
function writeYaml(
|
|
6336
|
-
path,
|
|
6337
|
-
data,
|
|
6338
|
-
replacer?,
|
|
6339
|
-
options?): Promise<void>;
|
|
6293
|
+
function writeYaml(path, data, replacer?, options?): Promise<void>;
|
|
6340
6294
|
```
|
|
6341
6295
|
|
|
6342
|
-
Defined in: [packages/fs/src/write/write-yaml.ts:12](https://github.com/visulima/visulima/blob/
|
|
6296
|
+
Defined in: [packages/fs/src/write/write-yaml.ts:12](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/write/write-yaml.ts#L12)
|
|
6343
6297
|
|
|
6344
6298
|
##### Parameters
|
|
6345
6299
|
|
|
@@ -6363,7 +6317,7 @@ Defined in: [packages/fs/src/write/write-yaml.ts:12](https://github.com/visulima
|
|
|
6363
6317
|
|
|
6364
6318
|
`Promise`\<`void`\>
|
|
6365
6319
|
|
|
6366
|
-
|
|
6320
|
+
---
|
|
6367
6321
|
|
|
6368
6322
|
### writeYamlSync()
|
|
6369
6323
|
|
|
@@ -6380,13 +6334,13 @@ The data to serialize and write. Can be any JavaScript value that can be stringi
|
|
|
6380
6334
|
#### Param
|
|
6381
6335
|
|
|
6382
6336
|
Optional. A replacer function or an array of keys to include, or the options object itself.
|
|
6383
|
-
|
|
6337
|
+
See `yaml.stringify` documentation for more details.
|
|
6384
6338
|
|
|
6385
6339
|
#### Param
|
|
6386
6340
|
|
|
6387
6341
|
Optional. Configuration for writing and stringifying the YAML file. See WriteYamlOptions.
|
|
6388
|
-
|
|
6389
|
-
|
|
6342
|
+
If `replacer` is an object and not a function/array, it's treated as `options`.
|
|
6343
|
+
The `space` property within options can be a number for spaces or a string for tabs/etc.
|
|
6390
6344
|
|
|
6391
6345
|
#### Example
|
|
6392
6346
|
|
|
@@ -6395,19 +6349,19 @@ import { writeYamlSync } from "@visulima/fs";
|
|
|
6395
6349
|
import { join } from "node:path";
|
|
6396
6350
|
|
|
6397
6351
|
const writeMyYamlSync = () => {
|
|
6398
|
-
|
|
6399
|
-
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6352
|
+
try {
|
|
6353
|
+
writeYamlSync(join("/tmp", "my-data-sync.yaml"), { name: "Jane Doe", age: 28, city: "London" });
|
|
6354
|
+
console.log("YAML file written successfully (sync).");
|
|
6355
|
+
|
|
6356
|
+
writeYamlSync(join("/tmp", "another-data-sync.yaml"), { user: "john_sync", details: { id: 2, status: "inactive" } }, null, 4);
|
|
6357
|
+
console.log("Another YAML file written with 4 spaces indentation (sync).");
|
|
6358
|
+
|
|
6359
|
+
const customReplacer = (key, value) => (key === "city" ? "REDACTED" : value);
|
|
6360
|
+
writeYamlSync(join("/tmp", "filtered-data-sync.yaml"), { name: "Peter", age: 50, city: "Paris" }, customReplacer, { space: 2 });
|
|
6361
|
+
console.log("Filtered YAML file written with 2 spaces indentation (sync).");
|
|
6362
|
+
} catch (error) {
|
|
6363
|
+
console.error("Failed to write YAML file (sync):", error);
|
|
6364
|
+
}
|
|
6411
6365
|
};
|
|
6412
6366
|
|
|
6413
6367
|
writeMyYamlSync();
|
|
@@ -6416,13 +6370,10 @@ writeMyYamlSync();
|
|
|
6416
6370
|
#### Call Signature
|
|
6417
6371
|
|
|
6418
6372
|
```ts
|
|
6419
|
-
function writeYamlSync(
|
|
6420
|
-
path,
|
|
6421
|
-
data,
|
|
6422
|
-
options?): void;
|
|
6373
|
+
function writeYamlSync(path, data, options?): void;
|
|
6423
6374
|
```
|
|
6424
6375
|
|
|
6425
|
-
Defined in: [packages/fs/src/write/write-yaml-sync.ts:6](https://github.com/visulima/visulima/blob/
|
|
6376
|
+
Defined in: [packages/fs/src/write/write-yaml-sync.ts:6](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/write/write-yaml-sync.ts#L6)
|
|
6426
6377
|
|
|
6427
6378
|
##### Parameters
|
|
6428
6379
|
|
|
@@ -6445,14 +6396,10 @@ Defined in: [packages/fs/src/write/write-yaml-sync.ts:6](https://github.com/visu
|
|
|
6445
6396
|
#### Call Signature
|
|
6446
6397
|
|
|
6447
6398
|
```ts
|
|
6448
|
-
function writeYamlSync(
|
|
6449
|
-
path,
|
|
6450
|
-
data,
|
|
6451
|
-
replacer?,
|
|
6452
|
-
options?): void;
|
|
6399
|
+
function writeYamlSync(path, data, replacer?, options?): void;
|
|
6453
6400
|
```
|
|
6454
6401
|
|
|
6455
|
-
Defined in: [packages/fs/src/write/write-yaml-sync.ts:12](https://github.com/visulima/visulima/blob/
|
|
6402
|
+
Defined in: [packages/fs/src/write/write-yaml-sync.ts:12](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/write/write-yaml-sync.ts#L12)
|
|
6456
6403
|
|
|
6457
6404
|
##### Parameters
|
|
6458
6405
|
|
|
@@ -6484,7 +6431,7 @@ Defined in: [packages/fs/src/write/write-yaml-sync.ts:12](https://github.com/vis
|
|
|
6484
6431
|
type YamlReplacer = JsonReplacer;
|
|
6485
6432
|
```
|
|
6486
6433
|
|
|
6487
|
-
Defined in: [packages/fs/src/types.ts:202](https://github.com/visulima/visulima/blob/
|
|
6434
|
+
Defined in: [packages/fs/src/types.ts:202](https://github.com/visulima/visulima/blob/07f43a001a4f33a3ebcce9072d404a8975539608/packages/fs/src/types.ts#L202)
|
|
6488
6435
|
|
|
6489
6436
|
Type for the `replacer` parameter used in YAML serialization, similar to `JSON.stringify`'s replacer.
|
|
6490
6437
|
|