Skip to content

Commit

Permalink
clean up search_fs docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanatkn committed Sep 24, 2024
1 parent 7a4902a commit a4884bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-ladybugs-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ryanatkn/gro': patch
---

clean up `search_fs` docs
23 changes: 11 additions & 12 deletions src/lib/search_fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export interface Search_Fs_Options {
*/
filter?: Path_Filter | Path_Filter[];
/**
* An array of file suffixes to include.
* One or more file filter functions. Every filter must pass for a file to be included.
*/
file_filter?: File_Filter | File_Filter[];
/**
* Pass `null` or `false` to speed things up at the cost of volatile ordering.
*/
sort?: boolean | null | ((a: Resolved_Path, b: Resolved_Path) => number);
/**
* Set to `false` to include directories.
* Set to `true` to include directories. Defaults to `false`.
*/
include_directories?: boolean;
/**
Expand Down Expand Up @@ -76,17 +76,16 @@ const crawl = (
const is_directory = dirent.isDirectory();
const id = parentPath + name;
const include = !filters || filters.every((f) => f(id, is_directory));
if (include) {
const path = base_dir === null ? name : base_dir + '/' + name;
if (is_directory) {
const dir_id = id + '/';
if (include_directories) {
paths.push({path, id: dir_id, is_directory: true});
}
crawl(dir_id, paths, filters, file_filter, include_directories, path);
} else if (!file_filter || file_filter.every((f) => f(id))) {
paths.push({path, id, is_directory: false});
if (!include) continue;
const path = base_dir === null ? name : base_dir + '/' + name;
if (is_directory) {
const dir_id = id + '/';
if (include_directories) {
paths.push({path, id: dir_id, is_directory: true});
}
crawl(dir_id, paths, filters, file_filter, include_directories, path);
} else if (!file_filter || file_filter.every((f) => f(id))) {
paths.push({path, id, is_directory: false});
}
}
return paths;
Expand Down

0 comments on commit a4884bf

Please sign in to comment.