@visulima/fs
Version:
Human friendly file system utilities for Node.js
35 lines (34 loc) • 2.13 kB
TypeScript
import type { WalkEntry, WalkOptions } from "../types.d.ts";
/**
* Synchronously walks the file tree rooted at `directory`, yielding each file or directory that matches the criteria specified in `options`.
* This is the synchronous version of the {@linkcode walk} function.
* @param directory The root directory to start walking from.
* @param options Optional configuration to control the walking process. See {@link WalkOptions}.
* @param options.extensions List of file extensions used to filter entries.
* @param options.followSymlinks Indicates whether symlinks should be resolved or not.
* @param options.includeDirs Indicates whether directory entries should be included or not.
* @param options.includeFiles Indicates whether file entries should be included or not.
* @param options.includeSymlinks Indicates whether symlink entries should be included or not.
* @param options.match List of regular expression or glob patterns used to filter entries.
* @param options.maxDepth Maximum depth to walk. Defaults to infinity.
* @param options.skip List of regular expression or glob patterns used to skip entries.
* @returns An iterable iterator yielding {@link WalkEntry} objects for each matching file or directory.
* @example
* ```javascript
* import { walkSync } from "@visulima/fs";
* import { join } from "node:path";
*
* // Walk through /tmp/my-project, looking for .ts files, max depth 2
* for (const entry of walkSync(join("/tmp", "my-project"), { extensions: ["ts"], maxDepth: 2 })) {
* console.log(`Found: ${entry.path} (Type: ${entry.isFile() ? 'file' : 'directory'})`);
* }
*
* // Walk, including only directories, and skip any node_modules folders
* for (const entry of walkSync(join("/tmp", "another-project"), { includeFiles: false, skip: [/node_modules/] })) {
* if (entry.isDirectory()) {
* console.log(`Directory: ${entry.path}`);
* }
* }
* ```
*/
export default function walkSync(directory: URL | string, { extensions, followSymlinks, includeDirs: includeDirectories, includeFiles, includeSymlinks, match, maxDepth, skip, }?: WalkOptions): IterableIterator<WalkEntry>;