@visulima/fs 4.0.3 → 4.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/LICENSE.md +4 -1
- package/dist/constants.d.ts +42 -0
- package/dist/ensure/ensure-dir-sync.d.ts +14 -0
- package/dist/ensure/ensure-dir.d.ts +14 -0
- package/dist/ensure/ensure-file-sync.d.ts +15 -0
- package/dist/ensure/ensure-file.d.ts +27 -0
- package/dist/ensure/ensure-link-sync.d.ts +16 -0
- package/dist/ensure/ensure-link.d.ts +16 -0
- package/dist/ensure/ensure-symlink-sync.d.ts +23 -0
- package/dist/ensure/ensure-symlink.d.ts +23 -0
- package/dist/ensure/utils/get-file-info-type.d.ts +7 -0
- package/dist/ensure/utils/is-stats-identical.d.ts +3 -0
- package/dist/ensure/utils/resolve-symlink-target.d.ts +2 -0
- package/dist/eol.d.ts +35 -7
- package/dist/eol.js +26 -3
- package/dist/error/already-exists-error.d.ts +39 -0
- package/dist/error/directory-error.d.ts +47 -0
- package/dist/error/json-error.d.ts +52 -0
- package/dist/error/not-empty-error.d.ts +51 -0
- package/dist/error/not-found-error.d.ts +44 -0
- package/dist/error/permission-error.d.ts +45 -0
- package/dist/error/walk-error.d.ts +51 -0
- package/dist/error.d.ts +7 -50
- package/dist/error.js +7 -1
- package/dist/find/collect-sync.d.ts +31 -0
- package/dist/find/collect.d.ts +35 -0
- package/dist/find/find-up-sync.d.ts +42 -0
- package/dist/find/find-up.d.ts +46 -0
- package/dist/find/utils/glob-to-regex.d.ts +2 -0
- package/dist/find/utils/walk-include.d.ts +2 -0
- package/dist/find/walk-sync.d.ts +26 -0
- package/dist/find/walk.d.ts +29 -0
- package/dist/index.d.ts +34 -136
- package/dist/index.js +32 -1
- package/dist/is-accessible-sync.d.ts +3 -0
- package/dist/is-accessible.d.ts +29 -0
- package/dist/move/index.d.ts +70 -0
- package/dist/move/types.d.ts +38 -0
- package/dist/move/utils/internal-move-file-sync.d.ts +3 -0
- package/dist/move/utils/internal-move-file.d.ts +3 -0
- package/dist/move/utils/validate-same-directory.d.ts +2 -0
- package/dist/packem_shared/AlreadyExistsError-D5BGeeNR.js +27 -0
- package/dist/packem_shared/DirectoryError-CaUV2Pbk.js +27 -0
- package/dist/packem_shared/F_OK-BalxCn9n.js +8 -0
- package/dist/packem_shared/JSONError-BkHRnInH.js +26 -0
- package/dist/packem_shared/NotEmptyError-mOHWXE0m.js +27 -0
- package/dist/packem_shared/NotFoundError-D4llRgRs.js +27 -0
- package/dist/packem_shared/PermissionError-1qs0skfo.js +27 -0
- package/dist/packem_shared/WalkError-DUdQd6FT.js +24 -0
- package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +7 -0
- package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +7 -0
- package/dist/packem_shared/collect-DcBwsYYd.js +14 -0
- package/dist/packem_shared/collectSync-Bkjf9Dbm.js +14 -0
- package/dist/packem_shared/emptyDir-CYB5Tict.js +43 -0
- package/dist/packem_shared/emptyDirSync-BD8-1Ytl.js +41 -0
- package/dist/packem_shared/ensureDir-C_kuQ5Ik.js +53 -0
- package/dist/packem_shared/ensureDirSync-CI5g-uBI.js +53 -0
- package/dist/packem_shared/ensureFile-BUtXGlGT.js +47 -0
- package/dist/packem_shared/ensureFileSync-C8hASR-1.js +47 -0
- package/dist/packem_shared/ensureLink-BPnAG5-P.js +54 -0
- package/dist/packem_shared/ensureLinkSync-B-Z7X0ub.js +54 -0
- package/dist/packem_shared/ensureSymlink-BGz6W-Wa.js +73 -0
- package/dist/packem_shared/ensureSymlinkSync-C5Gk8QYi.js +74 -0
- package/dist/packem_shared/findUp-Lv9mZCIQ.js +85 -0
- package/dist/packem_shared/findUpSync-BsK4Nrrq.js +85 -0
- package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +14 -0
- package/dist/packem_shared/index-CHM-in-V.js +100 -0
- package/dist/packem_shared/is-stats-identical-D8FxpvQU.js +3 -0
- package/dist/packem_shared/isAccessible-iOp0Bou6.js +38 -0
- package/dist/packem_shared/isAccessibleSync-38BmiIcx.js +38 -0
- package/dist/packem_shared/isFsCaseSensitive-D-ayleCy.js +62 -0
- package/dist/packem_shared/move-BD6JbYSu.js +134 -0
- package/dist/packem_shared/parseJson-CqUuRguZ.js +231 -0
- package/dist/packem_shared/readFile-XVOjAw8r.js +65 -0
- package/dist/packem_shared/readFileSync-B9Zg5PSF.js +53 -0
- package/dist/packem_shared/readJson-Dra2m6s-.js +22 -0
- package/dist/packem_shared/readJsonSync-B6Dl1I_6.js +22 -0
- package/dist/packem_shared/readYaml-Bu1nsexB.js +10 -0
- package/dist/packem_shared/readYamlSync-Di88aMME.js +10 -0
- package/dist/packem_shared/remove-_oDY3uKo.js +38 -0
- package/dist/packem_shared/removeSync-DETRj7Qn.js +38 -0
- package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +16 -0
- package/dist/packem_shared/stripJsonComments-21XWVDwP.js +19 -0
- package/dist/packem_shared/to-uint-8-array-Dz2nF1y1.js +19 -0
- package/dist/packem_shared/walk-BhTbpr3y.js +115 -0
- package/dist/packem_shared/walk-include-CZco7BvN.js +16 -0
- package/dist/packem_shared/walkSync-DDBq95s8.js +114 -0
- package/dist/packem_shared/writeFile-NT1fLEEe.js +83 -0
- package/dist/packem_shared/writeFileSync-Bj5UDSf0.js +83 -0
- package/dist/packem_shared/writeJson-DQLdAi0d.js +50 -0
- package/dist/packem_shared/writeJsonSync-DvTCjVUi.js +50 -0
- package/dist/packem_shared/writeYaml-BMY0kOPf.js +24 -0
- package/dist/packem_shared/writeYamlSync-DqPu8cCd.js +24 -0
- package/dist/read/read-file-sync.d.ts +37 -0
- package/dist/read/read-file.d.ts +41 -0
- package/dist/read/read-json-sync.d.ts +5 -0
- package/dist/read/read-json.d.ts +5 -0
- package/dist/read/read-yaml-sync.d.ts +4 -0
- package/dist/read/read-yaml.d.ts +4 -0
- package/dist/remove/empty-dir-sync.d.ts +24 -0
- package/dist/remove/empty-dir.d.ts +28 -0
- package/dist/remove/remove-sync.d.ts +28 -0
- package/dist/remove/remove.d.ts +32 -0
- package/dist/size.d.ts +245 -12
- package/dist/size.js +144 -1
- package/dist/types.d.ts +299 -0
- package/dist/utils/assert-valid-file-contents.d.ts +27 -0
- package/dist/utils/assert-valid-file-or-directory-path.d.ts +26 -0
- package/dist/utils/parse-json.d.ts +5 -0
- package/dist/utils/strip-json-comments.d.ts +44 -0
- package/dist/utils.d.ts +6 -19
- package/dist/utils.js +6 -1
- package/dist/write/utils/to-uint-8-array.d.ts +2 -0
- package/dist/write/write-file-sync.d.ts +30 -0
- package/dist/write/write-file.d.ts +30 -0
- package/dist/write/write-json-sync.d.ts +30 -0
- package/dist/write/write-json.d.ts +30 -0
- package/dist/write/write-yaml-sync.d.ts +4 -0
- package/dist/write/write-yaml.d.ts +4 -0
- package/dist/yaml.d.ts +5 -17
- package/dist/yaml.js +4 -1
- package/package.json +2 -3
- package/dist/packem_shared/AlreadyExistsError-CEu6_Tjb.js +0 -1
- package/dist/packem_shared/DirectoryError-ddlbUV8C.js +0 -1
- package/dist/packem_shared/F_OK-CAwY1qU7.js +0 -1
- package/dist/packem_shared/JSONError-D7h6PNWc.js +0 -4
- package/dist/packem_shared/NotEmptyError-DMh1o7UL.js +0 -1
- package/dist/packem_shared/NotFoundError-BPiW0icm.js +0 -1
- package/dist/packem_shared/PermissionError-B1Emi5a9.js +0 -1
- package/dist/packem_shared/WalkError-BsngoIKJ.js +0 -1
- package/dist/packem_shared/assertValidFileContents-BZFnXa7K.js +0 -1
- package/dist/packem_shared/assertValidFileOrDirectoryPath-DgPIPmZT.js +0 -1
- package/dist/packem_shared/collect-DO31RsLs.js +0 -1
- package/dist/packem_shared/collectSync-Cy7ULmjZ.js +0 -1
- package/dist/packem_shared/emptyDir-zBLHyPsJ.js +0 -1
- package/dist/packem_shared/emptyDirSync-DZ8nTo6g.js +0 -1
- package/dist/packem_shared/ensureDir-CwcwvbZ0.js +0 -1
- package/dist/packem_shared/ensureDirSync-DsFhH5oQ.js +0 -1
- package/dist/packem_shared/ensureFile-DwcEQVDX.js +0 -1
- package/dist/packem_shared/ensureFileSync-KnrH51Ox.js +0 -1
- package/dist/packem_shared/ensureLink-5rjQGEBb.js +0 -1
- package/dist/packem_shared/ensureLinkSync-CYXpscf2.js +0 -1
- package/dist/packem_shared/ensureSymlink-GATTbE5c.js +0 -1
- package/dist/packem_shared/ensureSymlinkSync-CvXgTFrl.js +0 -1
- package/dist/packem_shared/findUp-Di7Az07S.js +0 -1
- package/dist/packem_shared/findUpSync-iV97v14Q.js +0 -1
- package/dist/packem_shared/get-file-info-type-CaWGXRjY.js +0 -1
- package/dist/packem_shared/index-CYIVJA0W.js +0 -1
- package/dist/packem_shared/is-stats-identical-CohsLtWy.js +0 -1
- package/dist/packem_shared/isAccessible-CDFxsAAo.js +0 -1
- package/dist/packem_shared/isAccessibleSync-5nzZWgin.js +0 -1
- package/dist/packem_shared/isFsCaseSensitive-Drl8fHLV.js +0 -1
- package/dist/packem_shared/json-error-ZPgZIXcg.d.ts +0 -11
- package/dist/packem_shared/move-Bz4gSIjp.js +0 -1
- package/dist/packem_shared/parseJson-Cj4v3qzl.js +0 -6
- package/dist/packem_shared/readFile-CbxFM_zp.js +0 -1
- package/dist/packem_shared/readFileSync-B9iv2Sb8.js +0 -1
- package/dist/packem_shared/readJson-BgC3msx-.js +0 -1
- package/dist/packem_shared/readJsonSync-DHO1vjAG.js +0 -1
- package/dist/packem_shared/readYaml-D5mtfANg.js +0 -1
- package/dist/packem_shared/readYamlSync-D0igCVDE.js +0 -1
- package/dist/packem_shared/remove-BUqZUj1W.js +0 -1
- package/dist/packem_shared/removeSync-BbT4vmDi.js +0 -1
- package/dist/packem_shared/resolve-symlink-target-BofZSDIc.js +0 -1
- package/dist/packem_shared/stripJsonComments-DbMjL4qv.js +0 -1
- package/dist/packem_shared/to-uint-8-array-DwgaTasY.js +0 -1
- package/dist/packem_shared/types-T308NKwz.d.ts +0 -90
- package/dist/packem_shared/walk-ZrZngpc4.js +0 -1
- package/dist/packem_shared/walk-include-DCiVAwMP.js +0 -1
- package/dist/packem_shared/walkSync-BQa4NKSG.js +0 -1
- package/dist/packem_shared/writeFile-D5OYEMHu.js +0 -1
- package/dist/packem_shared/writeFileSync-CO4ySqUn.js +0 -1
- package/dist/packem_shared/writeJson-DfmgiY_s.js +0 -4
- package/dist/packem_shared/writeJsonSync-Ck1pmmj_.js +0 -4
- package/dist/packem_shared/writeYaml-BJeyUpyY.js +0 -1
- package/dist/packem_shared/writeYamlSync-D87XCS7Y.js +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown in {@linkcode walk} or {@linkcode walkSync} during iteration.
|
|
3
|
+
* @example
|
|
4
|
+
* ```javascript
|
|
5
|
+
* import { WalkError } from "@visulima/fs/error";
|
|
6
|
+
* import { walk } from "@visulima/fs";
|
|
7
|
+
* import { join } from "node:path";
|
|
8
|
+
*
|
|
9
|
+
* const processDirectory = async () => {
|
|
10
|
+
* const dirToWalk = join("/tmp", "non-existent-or-permission-denied-dir");
|
|
11
|
+
* try {
|
|
12
|
+
* // Forcing the scenario: walk might throw a WalkError if it encounters an issue
|
|
13
|
+
* // like a directory it cannot read during the walk process.
|
|
14
|
+
* const simulateWalkError = async (rootDir) => {
|
|
15
|
+
* // Let's say readdir inside walk fails for a subdirectory.
|
|
16
|
+
* const underlyingError = new Error("Permission denied reading subdirectory");
|
|
17
|
+
* throw new WalkError(underlyingError, rootDir);
|
|
18
|
+
* }
|
|
19
|
+
* // This is conceptual. In a real scenario, 'walk' itself would throw.
|
|
20
|
+
* // for await (const entry of walk(dirToWalk)) {
|
|
21
|
+
* // console.log(entry.path);
|
|
22
|
+
* // }
|
|
23
|
+
* await simulateWalkError(dirToWalk);
|
|
24
|
+
* } catch (error) {
|
|
25
|
+
* if (error instanceof WalkError) {
|
|
26
|
+
* console.error(`Error during directory walk of "${error.root}": ${error.message}`);
|
|
27
|
+
* if (error.cause) {
|
|
28
|
+
* console.error(`Underlying cause: ${error.cause}`);
|
|
29
|
+
* }
|
|
30
|
+
* } else {
|
|
31
|
+
* console.error("An unexpected error occurred:", error);
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* };
|
|
35
|
+
*
|
|
36
|
+
* processDirectory();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare class WalkError extends Error {
|
|
40
|
+
/** File path of the root that's being walked. */
|
|
41
|
+
root: string;
|
|
42
|
+
/**
|
|
43
|
+
* Constructs a new instance.
|
|
44
|
+
* @param cause The underlying error or reason for the walk failure.
|
|
45
|
+
* @param root The root directory path where the walk operation started or encountered the error.
|
|
46
|
+
*/
|
|
47
|
+
constructor(cause: unknown, root: string);
|
|
48
|
+
get name(): string;
|
|
49
|
+
set name(_name: string);
|
|
50
|
+
}
|
|
51
|
+
export default WalkError;
|
package/dist/error.d.ts
CHANGED
|
@@ -1,50 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
set name(_name: string);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare class DirectoryError extends Error {
|
|
12
|
-
constructor(message: string);
|
|
13
|
-
get code(): string;
|
|
14
|
-
set code(_name: string);
|
|
15
|
-
get name(): string;
|
|
16
|
-
set name(_name: string);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare class NotEmptyError extends Error {
|
|
20
|
-
constructor(message: string);
|
|
21
|
-
get code(): string;
|
|
22
|
-
set code(_name: string);
|
|
23
|
-
get name(): string;
|
|
24
|
-
set name(_name: string);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare class NotFoundError extends Error {
|
|
28
|
-
constructor(message: string);
|
|
29
|
-
get code(): string;
|
|
30
|
-
set code(_name: string);
|
|
31
|
-
get name(): string;
|
|
32
|
-
set name(_name: string);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
declare class PermissionError extends Error {
|
|
36
|
-
constructor(message: string);
|
|
37
|
-
get code(): string;
|
|
38
|
-
set code(_name: string);
|
|
39
|
-
get name(): string;
|
|
40
|
-
set name(_name: string);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
declare class WalkError extends Error {
|
|
44
|
-
root: string;
|
|
45
|
-
constructor(cause: unknown, root: string);
|
|
46
|
-
get name(): string;
|
|
47
|
-
set name(_name: string);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export { AlreadyExistsError, DirectoryError, NotEmptyError, NotFoundError, PermissionError, WalkError };
|
|
1
|
+
export { default as AlreadyExistsError } from "./error/already-exists-error.d.ts";
|
|
2
|
+
export { default as DirectoryError } from "./error/directory-error.d.ts";
|
|
3
|
+
export { default as JSONError } from "./error/json-error.d.ts";
|
|
4
|
+
export { default as NotEmptyError } from "./error/not-empty-error.d.ts";
|
|
5
|
+
export { default as NotFoundError } from "./error/not-found-error.d.ts";
|
|
6
|
+
export { default as PermissionError } from "./error/permission-error.d.ts";
|
|
7
|
+
export { default as WalkError } from "./error/walk-error.d.ts";
|
package/dist/error.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
export { default as AlreadyExistsError } from './packem_shared/AlreadyExistsError-D5BGeeNR.js';
|
|
2
|
+
export { default as DirectoryError } from './packem_shared/DirectoryError-CaUV2Pbk.js';
|
|
3
|
+
export { default as JSONError } from './packem_shared/JSONError-BkHRnInH.js';
|
|
4
|
+
export { default as NotEmptyError } from './packem_shared/NotEmptyError-mOHWXE0m.js';
|
|
5
|
+
export { default as NotFoundError } from './packem_shared/NotFoundError-D4llRgRs.js';
|
|
6
|
+
export { default as PermissionError } from './packem_shared/PermissionError-1qs0skfo.js';
|
|
7
|
+
export { default as WalkError } from './packem_shared/WalkError-DUdQd6FT.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { WalkOptions } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Synchronously collects all file paths within a directory that match the specified criteria.
|
|
4
|
+
* By default, it searches for JavaScript and TypeScript file extensions.
|
|
5
|
+
* @param directory The root directory to start collecting files from.
|
|
6
|
+
* @param options Optional configuration to control the collection process. See {@link WalkOptions}.
|
|
7
|
+
* @returns An array of absolute file paths.
|
|
8
|
+
* @example
|
|
9
|
+
* ```javascript
|
|
10
|
+
* import { collectSync } from "@visulima/fs";
|
|
11
|
+
* import { join } from "node:path";
|
|
12
|
+
*
|
|
13
|
+
* // Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
|
|
14
|
+
* const files = collectSync(join("/tmp", "docs"), {
|
|
15
|
+
* extensions: ["txt", "md"],
|
|
16
|
+
* maxDepth: 2,
|
|
17
|
+
* includeDirs: false, // Only collect files
|
|
18
|
+
* });
|
|
19
|
+
* console.log(files);
|
|
20
|
+
* // Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
|
|
21
|
+
*
|
|
22
|
+
* // Collect all .js files, excluding anything in node_modules
|
|
23
|
+
* const jsFiles = collectSync(join("/tmp", "project"), {
|
|
24
|
+
* extensions: ["js"],
|
|
25
|
+
* skip: [/node_modules/],
|
|
26
|
+
* });
|
|
27
|
+
* console.log(jsFiles);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare const collectSync: (directory: string, options?: WalkOptions) => string[];
|
|
31
|
+
export default collectSync;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { WalkOptions } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Asynchronously collects all file paths within a directory that match the specified criteria.
|
|
4
|
+
* By default, it searches for JavaScript and TypeScript file extensions.
|
|
5
|
+
* @param directory The root directory to start collecting files from.
|
|
6
|
+
* @param options Optional configuration to control the collection process. See {@link WalkOptions}.
|
|
7
|
+
* @returns A promise that resolves to an array of absolute file paths.
|
|
8
|
+
* @example
|
|
9
|
+
* ```javascript
|
|
10
|
+
* import { collect } from "@visulima/fs";
|
|
11
|
+
* import { join } from "node:path";
|
|
12
|
+
*
|
|
13
|
+
* const collectFiles = async () => {
|
|
14
|
+
* // Collect all .txt and .md files in /tmp/docs, up to 2 levels deep
|
|
15
|
+
* const files = await collect(join("/tmp", "docs"), {
|
|
16
|
+
* extensions: ["txt", "md"],
|
|
17
|
+
* maxDepth: 2,
|
|
18
|
+
* includeDirs: false, // Only collect files
|
|
19
|
+
* });
|
|
20
|
+
* console.log(files);
|
|
21
|
+
* // Example output: ['/tmp/docs/file1.txt', '/tmp/docs/subdir/report.md']
|
|
22
|
+
*
|
|
23
|
+
* // Collect all .js files, excluding anything in node_modules
|
|
24
|
+
* const jsFiles = await collect(join("/tmp", "project"), {
|
|
25
|
+
* extensions: ["js"],
|
|
26
|
+
* skip: [/node_modules/],
|
|
27
|
+
* });
|
|
28
|
+
* console.log(jsFiles);
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* collectFiles();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare const collect: (directory: string, options?: WalkOptions) => Promise<string[]>;
|
|
35
|
+
export default collect;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { FindUpNameSync, FindUpOptions } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Synchronously finds a file or directory by walking up parent directories.
|
|
4
|
+
* @param name The name(s) of the file or directory to find. Can be a string, an array of strings, or a function that returns a name or `FIND_UP_STOP`.
|
|
5
|
+
* @param options Optional configuration for the search. See {@link FindUpOptions}.
|
|
6
|
+
* @returns The absolute path of the first found file/directory, or `undefined` if not found.
|
|
7
|
+
* @example
|
|
8
|
+
* ```javascript
|
|
9
|
+
* import { findUpSync } from "@visulima/fs";
|
|
10
|
+
* import { join } from "node:path";
|
|
11
|
+
*
|
|
12
|
+
* // Find the closest package.json, starting from /tmp/foo/bar/baz
|
|
13
|
+
* const projectRoot = findUpSync("package.json", {
|
|
14
|
+
* cwd: join("/tmp", "foo", "bar", "baz"),
|
|
15
|
+
* type: "file",
|
|
16
|
+
* });
|
|
17
|
+
* console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
|
|
18
|
+
*
|
|
19
|
+
* // Find the closest .git directory or a README.md file
|
|
20
|
+
* const gitDirOrReadme = findUpSync([".git", "README.md"], {
|
|
21
|
+
* cwd: join("/tmp", "foo", "bar"),
|
|
22
|
+
* });
|
|
23
|
+
* console.log(gitDirOrReadme);
|
|
24
|
+
*
|
|
25
|
+
* // Find using a custom function, stopping at /tmp
|
|
26
|
+
* const customFound = findUpSync(
|
|
27
|
+
* (directory) => {
|
|
28
|
+
* if (directory === join("/tmp", "foo")) {
|
|
29
|
+
* return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
|
|
30
|
+
* }
|
|
31
|
+
* return undefined;
|
|
32
|
+
* },
|
|
33
|
+
* {
|
|
34
|
+
* cwd: join("/tmp", "foo", "bar", "baz"),
|
|
35
|
+
* stopAt: join("/tmp"),
|
|
36
|
+
* }
|
|
37
|
+
* );
|
|
38
|
+
* console.log(customFound);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare const findUpSync: (name: FindUpNameSync, options?: FindUpOptions) => string | undefined;
|
|
42
|
+
export default findUpSync;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { FindUpName, FindUpOptions } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Asynchronously finds a file or directory by walking up parent directories.
|
|
4
|
+
* @param name The name(s) of the file or directory to find. Can be a string, an array of strings, or a function that returns a name or `FIND_UP_STOP`.
|
|
5
|
+
* @param options Optional configuration for the search. See {@link FindUpOptions}.
|
|
6
|
+
* @returns A promise that resolves to the absolute path of the first found file/directory, or `undefined` if not found.
|
|
7
|
+
* @example
|
|
8
|
+
* ```javascript
|
|
9
|
+
* import { findUp } from "@visulima/fs";
|
|
10
|
+
* import { join } from "node:path";
|
|
11
|
+
*
|
|
12
|
+
* const findProjectRoot = async () => {
|
|
13
|
+
* // Find the closest package.json, starting from /tmp/foo/bar/baz
|
|
14
|
+
* const projectRoot = await findUp("package.json", {
|
|
15
|
+
* cwd: join("/tmp", "foo", "bar", "baz"),
|
|
16
|
+
* type: "file",
|
|
17
|
+
* });
|
|
18
|
+
* console.log(projectRoot); // e.g., /tmp/foo/package.json or undefined
|
|
19
|
+
*
|
|
20
|
+
* // Find the closest .git directory or a README.md file
|
|
21
|
+
* const gitDirOrReadme = await findUp([".git", "README.md"], {
|
|
22
|
+
* cwd: join("/tmp", "foo", "bar"),
|
|
23
|
+
* });
|
|
24
|
+
* console.log(gitDirOrReadme);
|
|
25
|
+
*
|
|
26
|
+
* // Find using a custom function, stopping at /tmp
|
|
27
|
+
* const customFound = await findUp(
|
|
28
|
+
* (directory) => {
|
|
29
|
+
* if (directory === join("/tmp", "foo")) {
|
|
30
|
+
* return "found-it-here.txt"; // Pretend this file exists in /tmp/foo
|
|
31
|
+
* }
|
|
32
|
+
* return undefined;
|
|
33
|
+
* },
|
|
34
|
+
* {
|
|
35
|
+
* cwd: join("/tmp", "foo", "bar", "baz"),
|
|
36
|
+
* stopAt: join("/tmp"),
|
|
37
|
+
* }
|
|
38
|
+
* );
|
|
39
|
+
* console.log(customFound);
|
|
40
|
+
* };
|
|
41
|
+
*
|
|
42
|
+
* findProjectRoot();
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare const findUp: (name: FindUpName, options?: FindUpOptions) => Promise<string | undefined>;
|
|
46
|
+
export default findUp;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { WalkEntry, WalkOptions } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Synchronously walks the file tree rooted at `directory`, yielding each file or directory that matches the criteria specified in `options`.
|
|
4
|
+
* This is the synchronous version of the {@link walk} function.
|
|
5
|
+
* @param directory The root directory to start walking from.
|
|
6
|
+
* @param options Optional configuration to control the walking process. See {@link WalkOptions}.
|
|
7
|
+
* @returns An iterable iterator yielding {@link WalkEntry} objects for each matching file or directory.
|
|
8
|
+
* @example
|
|
9
|
+
* ```javascript
|
|
10
|
+
* import { walkSync } from "@visulima/fs";
|
|
11
|
+
* import { join } from "node:path";
|
|
12
|
+
*
|
|
13
|
+
* // Walk through /tmp/my-project, looking for .ts files, max depth 2
|
|
14
|
+
* for (const entry of walkSync(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
|
|
15
|
+
* console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? 'file' : 'directory'})`);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* // Walk, including only directories, and skip any node_modules folders
|
|
19
|
+
* for (const entry of walkSync(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
|
|
20
|
+
* if (entry.isDirectory()) {
|
|
21
|
+
* console.log(`Directory: ${entry.path}`);
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export default function walkSync(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): IterableIterator<WalkEntry>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { WalkEntry, WalkOptions } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Asynchronously walks the file tree rooted at `directory`, yielding each file or directory that matches the criteria specified in `options`.
|
|
4
|
+
* @param directory The root directory to start walking from.
|
|
5
|
+
* @param options Optional configuration to control the walking process. See {@link WalkOptions}.
|
|
6
|
+
* @returns An async iterable iterator yielding {@link WalkEntry} objects for each matching file or directory.
|
|
7
|
+
* @example
|
|
8
|
+
* ```javascript
|
|
9
|
+
* import { walk } from "@visulima/fs";
|
|
10
|
+
* import { join } from "node:path";
|
|
11
|
+
*
|
|
12
|
+
* const printEntries = async () => {
|
|
13
|
+
* // Walk through /tmp/my-project, looking for .ts files, max depth 2
|
|
14
|
+
* for await (const entry of walk(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
|
|
15
|
+
* console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? 'file' : 'directory'})`);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* // Walk, including only directories, and skip any node_modules folders
|
|
19
|
+
* for await (const entry of walk(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
|
|
20
|
+
* if (entry.isDirectory()) {
|
|
21
|
+
* console.log(`Directory: ${entry.path}`);
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* };
|
|
25
|
+
*
|
|
26
|
+
* printEntries();
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export default function walk(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): AsyncIterableIterator<WalkEntry>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,136 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
declare function walkSync(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): IterableIterator<WalkEntry>;
|
|
37
|
-
|
|
38
|
-
declare function isAccessible(path: URL | string, mode?: number): Promise<boolean>;
|
|
39
|
-
|
|
40
|
-
declare function isAccessibleSync(path: URL | string, mode?: number): boolean;
|
|
41
|
-
|
|
42
|
-
type FilePermissions = number;
|
|
43
|
-
type Options = {
|
|
44
|
-
cwd?: URL | string;
|
|
45
|
-
readonly directoryMode?: FilePermissions;
|
|
46
|
-
readonly overwrite?: boolean;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
declare const move: (sourcePath: string, destinationPath: string, options?: Options) => Promise<void>;
|
|
50
|
-
declare const moveSync: (sourcePath: string, destinationPath: string, options?: Options) => void;
|
|
51
|
-
declare const rename: (source: string, destination: string, options?: Options) => Promise<void>;
|
|
52
|
-
declare const renameSync: (source: string, destination: string, options?: Options) => void;
|
|
53
|
-
|
|
54
|
-
declare const decompressionMethods$1: {
|
|
55
|
-
readonly brotli: typeof brotliDecompress;
|
|
56
|
-
readonly gzip: typeof unzip;
|
|
57
|
-
readonly none: (buffer: Buffer, callback: (error: Error | null, result: Buffer) => void) => void;
|
|
58
|
-
};
|
|
59
|
-
declare const readFile: <O extends ReadFileOptions<keyof typeof decompressionMethods$1> | undefined = undefined>(path: URL | string, options?: O) => Promise<ContentType<O>>;
|
|
60
|
-
|
|
61
|
-
declare const decompressionMethods: {
|
|
62
|
-
readonly brotli: typeof brotliDecompressSync;
|
|
63
|
-
readonly gzip: typeof unzipSync;
|
|
64
|
-
readonly none: (buffer: Buffer) => Buffer<ArrayBufferLike>;
|
|
65
|
-
};
|
|
66
|
-
declare const readFileSync: <O extends ReadFileOptions<keyof typeof decompressionMethods> | undefined = undefined>(path: URL | string, options?: O) => ContentType<O>;
|
|
67
|
-
|
|
68
|
-
declare function readJson<T extends JsonValue>(path: URL | string, options?: ReadJsonOptions): Promise<T>;
|
|
69
|
-
declare function readJson<T extends JsonValue>(path: URL | string, reviver: JsonReviver, options?: ReadJsonOptions): Promise<T>;
|
|
70
|
-
|
|
71
|
-
declare function readJsonSync<T extends JsonValue>(path: URL | string, options?: ReadJsonOptions): T;
|
|
72
|
-
declare function readJsonSync<T extends JsonValue>(path: URL | string, reviver: JsonReviver, options?: ReadJsonOptions): T;
|
|
73
|
-
|
|
74
|
-
declare const emptyDir: (dir: URL | string, options?: RetryOptions) => Promise<void>;
|
|
75
|
-
|
|
76
|
-
declare const emptyDirSync: (dir: URL | string, options?: RetryOptions) => void;
|
|
77
|
-
|
|
78
|
-
declare const remove: (path: URL | string, options?: RetryOptions) => Promise<void>;
|
|
79
|
-
|
|
80
|
-
declare const removeSync: (path: URL | string, options?: RetryOptions) => void;
|
|
81
|
-
|
|
82
|
-
declare const writeFile: (path: URL | string, content: ArrayBuffer | ArrayBufferView | string, options?: WriteFileOptions) => Promise<void>;
|
|
83
|
-
|
|
84
|
-
declare const writeFileSync: (path: URL | string, content: ArrayBuffer | ArrayBufferView | string, options?: WriteFileOptions) => void;
|
|
85
|
-
|
|
86
|
-
declare const writeJson: (path: URL | string, data: unknown, options?: WriteJsonOptions) => Promise<void>;
|
|
87
|
-
|
|
88
|
-
declare const writeJsonSync: (path: URL | string, data: unknown, options?: WriteJsonOptions) => void;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Subset of Node.js fs module methods required for case-sensitivity detection.
|
|
92
|
-
* This allows custom fs implementations to be passed for testing purposes.
|
|
93
|
-
*/
|
|
94
|
-
type FsSubset = {
|
|
95
|
-
existsSync: typeof fs.existsSync;
|
|
96
|
-
writeFileSync: typeof fs.writeFileSync;
|
|
97
|
-
unlinkSync: typeof fs.unlinkSync;
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Detects whether the filesystem is case-sensitive.
|
|
101
|
-
*
|
|
102
|
-
* Uses a fast, I/O-free primary method that checks if the specified directory
|
|
103
|
-
* path can be accessed with inverted case. Falls back to writing a temporary
|
|
104
|
-
* file if the primary method is inconclusive.
|
|
105
|
-
*
|
|
106
|
-
* Different mount points can have different case-sensitivity settings, so this
|
|
107
|
-
* function checks the filesystem where the specified directory resides.
|
|
108
|
-
*
|
|
109
|
-
* @param directoryPath - The directory path to check. Defaults to
|
|
110
|
-
* `process.cwd()`. Different mount points can have different case-sensitivity.
|
|
111
|
-
* @param fsInstance - Custom filesystem implementation (primarily for
|
|
112
|
-
* testing). Defaults to Node.js `fs` module.
|
|
113
|
-
* @param useCache - Whether to cache the result per directory. Defaults to
|
|
114
|
-
* `true`. When enabled, subsequent calls for the same directory return
|
|
115
|
-
* instantly without re-checking.
|
|
116
|
-
* @returns `true` if the filesystem is case-sensitive, `false` otherwise
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```ts
|
|
120
|
-
* import { isFsCaseSensitive } from 'is-fs-case-sensitive'
|
|
121
|
-
*
|
|
122
|
-
* // Check current working directory's filesystem
|
|
123
|
-
* if (isFsCaseSensitive()) {
|
|
124
|
-
* console.log('Case-sensitive filesystem (likely Linux)')
|
|
125
|
-
* } else {
|
|
126
|
-
* console.log('Case-insensitive filesystem (likely macOS/Windows)')
|
|
127
|
-
* }
|
|
128
|
-
*
|
|
129
|
-
* // Check specific directory
|
|
130
|
-
* const isHomeCaseSensitive = isFsCaseSensitive('/home/user')
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
declare const isFsCaseSensitive: (directoryPath?: string, fsInstance?: FsSubset, useCache?: boolean) => boolean;
|
|
134
|
-
|
|
135
|
-
export { ContentType, FindUpName, FindUpNameSync, FindUpOptions, JsonReviver, ReadFileOptions, ReadJsonOptions, WalkEntry, WalkOptions, WriteFileOptions, WriteJsonOptions, collect, collectSync, emptyDir, emptyDirSync, ensureDir, ensureDirSync, ensureFile, ensureFileSync, ensureLink, ensureLinkSync, ensureSymlink, ensureSymlinkSync, findUp, findUpSync, isAccessible, isAccessibleSync, isFsCaseSensitive, move, moveSync, readFile, readFileSync, readJson, readJsonSync, remove, removeSync, rename, renameSync, walk, walkSync, writeFile, writeFileSync, writeJson, writeJsonSync };
|
|
136
|
-
export type { Options as MoveOptions };
|
|
1
|
+
export { F_OK, FIND_UP_STOP, R_OK, W_OK, X_OK } from "./constants.d.ts";
|
|
2
|
+
export { default as ensureDir } from "./ensure/ensure-dir.d.ts";
|
|
3
|
+
export { default as ensureDirSync } from "./ensure/ensure-dir-sync.d.ts";
|
|
4
|
+
export { default as ensureFile } from "./ensure/ensure-file.d.ts";
|
|
5
|
+
export { default as ensureFileSync } from "./ensure/ensure-file-sync.d.ts";
|
|
6
|
+
export { default as ensureLink } from "./ensure/ensure-link.d.ts";
|
|
7
|
+
export { default as ensureLinkSync } from "./ensure/ensure-link-sync.d.ts";
|
|
8
|
+
export { default as ensureSymlink } from "./ensure/ensure-symlink.d.ts";
|
|
9
|
+
export { default as ensureSymlinkSync } from "./ensure/ensure-symlink-sync.d.ts";
|
|
10
|
+
export { CRLF, detect, EOL, format, LF } from "./eol.d.ts";
|
|
11
|
+
export { default as collect } from "./find/collect.d.ts";
|
|
12
|
+
export { default as collectSync } from "./find/collect-sync.d.ts";
|
|
13
|
+
export { default as findUp } from "./find/find-up.d.ts";
|
|
14
|
+
export { default as findUpSync } from "./find/find-up-sync.d.ts";
|
|
15
|
+
export { default as walk } from "./find/walk.d.ts";
|
|
16
|
+
export { default as walkSync } from "./find/walk-sync.d.ts";
|
|
17
|
+
export { default as isAccessible } from "./is-accessible.d.ts";
|
|
18
|
+
export { default as isAccessibleSync } from "./is-accessible-sync.d.ts";
|
|
19
|
+
export { move, moveSync, rename, renameSync } from "./move/index.d.ts";
|
|
20
|
+
export type { Options as MoveOptions } from "./move/types.d.ts";
|
|
21
|
+
export { default as readFile } from "./read/read-file.d.ts";
|
|
22
|
+
export { default as readFileSync } from "./read/read-file-sync.d.ts";
|
|
23
|
+
export { default as readJson } from "./read/read-json.d.ts";
|
|
24
|
+
export { default as readJsonSync } from "./read/read-json-sync.d.ts";
|
|
25
|
+
export { default as emptyDir } from "./remove/empty-dir.d.ts";
|
|
26
|
+
export { default as emptyDirSync } from "./remove/empty-dir-sync.d.ts";
|
|
27
|
+
export { default as remove } from "./remove/remove.d.ts";
|
|
28
|
+
export { default as removeSync } from "./remove/remove-sync.d.ts";
|
|
29
|
+
export type { CodeFrameLocation, CodeFrameOptions, ContentType, FindUpName, FindUpNameFnResult, FindUpNameSync, FindUpNameSyncFnResult, FindUpOptions, JsonReplacer, JsonReviver, ReadFileEncoding, ReadFileOptions, ReadJsonOptions, WalkEntry, WalkOptions, WriteFileOptions, WriteJsonOptions, } from "./types.d.ts";
|
|
30
|
+
export { default as writeFile } from "./write/write-file.d.ts";
|
|
31
|
+
export { default as writeFileSync } from "./write/write-file-sync.d.ts";
|
|
32
|
+
export { default as writeJson } from "./write/write-json.d.ts";
|
|
33
|
+
export { default as writeJsonSync } from "./write/write-json-sync.d.ts";
|
|
34
|
+
export { isFsCaseSensitive } from "is-fs-case-sensitive";
|
package/dist/index.js
CHANGED
|
@@ -1 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
export { FIND_UP_STOP, F_OK, R_OK, W_OK, X_OK } from './packem_shared/F_OK-BalxCn9n.js';
|
|
2
|
+
export { default as ensureDir } from './packem_shared/ensureDir-C_kuQ5Ik.js';
|
|
3
|
+
export { default as ensureDirSync } from './packem_shared/ensureDirSync-CI5g-uBI.js';
|
|
4
|
+
export { default as ensureFile } from './packem_shared/ensureFile-BUtXGlGT.js';
|
|
5
|
+
export { default as ensureFileSync } from './packem_shared/ensureFileSync-C8hASR-1.js';
|
|
6
|
+
export { default as ensureLink } from './packem_shared/ensureLink-BPnAG5-P.js';
|
|
7
|
+
export { default as ensureLinkSync } from './packem_shared/ensureLinkSync-B-Z7X0ub.js';
|
|
8
|
+
export { default as ensureSymlink } from './packem_shared/ensureSymlink-BGz6W-Wa.js';
|
|
9
|
+
export { default as ensureSymlinkSync } from './packem_shared/ensureSymlinkSync-C5Gk8QYi.js';
|
|
10
|
+
export { CRLF, EOL, LF, detect, format } from './eol.js';
|
|
11
|
+
export { default as collect } from './packem_shared/collect-DcBwsYYd.js';
|
|
12
|
+
export { default as collectSync } from './packem_shared/collectSync-Bkjf9Dbm.js';
|
|
13
|
+
export { default as findUp } from './packem_shared/findUp-Lv9mZCIQ.js';
|
|
14
|
+
export { default as findUpSync } from './packem_shared/findUpSync-BsK4Nrrq.js';
|
|
15
|
+
export { default as walk } from './packem_shared/walk-BhTbpr3y.js';
|
|
16
|
+
export { default as walkSync } from './packem_shared/walkSync-DDBq95s8.js';
|
|
17
|
+
export { default as isAccessible } from './packem_shared/isAccessible-iOp0Bou6.js';
|
|
18
|
+
export { default as isAccessibleSync } from './packem_shared/isAccessibleSync-38BmiIcx.js';
|
|
19
|
+
export { move, moveSync, rename, renameSync } from './packem_shared/move-BD6JbYSu.js';
|
|
20
|
+
export { default as readFile } from './packem_shared/readFile-XVOjAw8r.js';
|
|
21
|
+
export { default as readFileSync } from './packem_shared/readFileSync-B9Zg5PSF.js';
|
|
22
|
+
export { default as readJson } from './packem_shared/readJson-Dra2m6s-.js';
|
|
23
|
+
export { default as readJsonSync } from './packem_shared/readJsonSync-B6Dl1I_6.js';
|
|
24
|
+
export { default as emptyDir } from './packem_shared/emptyDir-CYB5Tict.js';
|
|
25
|
+
export { default as emptyDirSync } from './packem_shared/emptyDirSync-BD8-1Ytl.js';
|
|
26
|
+
export { default as remove } from './packem_shared/remove-_oDY3uKo.js';
|
|
27
|
+
export { default as removeSync } from './packem_shared/removeSync-DETRj7Qn.js';
|
|
28
|
+
export { default as writeFile } from './packem_shared/writeFile-NT1fLEEe.js';
|
|
29
|
+
export { default as writeFileSync } from './packem_shared/writeFileSync-Bj5UDSf0.js';
|
|
30
|
+
export { default as writeJson } from './packem_shared/writeJson-DQLdAi0d.js';
|
|
31
|
+
export { default as writeJsonSync } from './packem_shared/writeJsonSync-DvTCjVUi.js';
|
|
32
|
+
export { isFsCaseSensitive } from './packem_shared/isFsCaseSensitive-D-ayleCy.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronously tests a user's permissions for the file or directory specified by path.
|
|
3
|
+
* Returns a Promise that resolves to `true` if the accessibility check is successful, `false` otherwise.
|
|
4
|
+
* @param path The path to the file or directory. Can be a string or a URL object.
|
|
5
|
+
* @param mode The accessibility checks to perform. Defaults to `F_OK` (check for existence).
|
|
6
|
+
* Other possible values include `R_OK` (check for read access), `W_OK` (check for write access),
|
|
7
|
+
* and `X_OK` (check for execute/search access). Multiple modes can be combined using bitwise OR.
|
|
8
|
+
* @returns A Promise that resolves to a boolean indicating if the path is accessible with the specified mode.
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { isAccessible, F_OK, R_OK } from "@visulima/fs";
|
|
12
|
+
*
|
|
13
|
+
* (async () => {
|
|
14
|
+
* if (await isAccessible("myFile.txt")) {
|
|
15
|
+
* console.log("myFile.txt exists");
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* if (await isAccessible("myFile.txt", R_OK)) {
|
|
19
|
+
* console.log("myFile.txt is readable");
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* if (await isAccessible("myDirectory", F_OK | R_OK | W_OK)) {
|
|
23
|
+
* console.log("myDirectory exists, is readable and writable");
|
|
24
|
+
* }
|
|
25
|
+
* })();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function isAccessible(path: URL | string, mode?: number): Promise<boolean>;
|
|
29
|
+
export default isAccessible;
|