Installations
npm install find-files-by-patterns
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=10.0.0 || ^10.15.1
Node Version
12.22.12
NPM Version
6.14.16
Score
74.9
Supply Chain
99.4
Quality
75.7
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
Download Statistics
Total Downloads
16,493
Last Day
1
Last Week
8
Last Month
21
Last Year
664
GitHub Statistics
5 Stars
65 Commits
1 Forks
1 Watching
4 Branches
3 Contributors
Bundle Size
7.45 kB
Minified
2.16 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.0.3
Package Id
find-files-by-patterns@2.0.3
Unpacked Size
163.91 kB
Size
22.93 kB
File Count
36
NPM Version
6.14.16
Node Version
12.22.12
Publised On
11 Mar 2023
Total Downloads
Cumulative downloads
Total Downloads
16,493
Last day
0%
1
Compared to previous day
Last week
-20%
8
Compared to previous week
Last month
-57.1%
21
Compared to previous month
Last year
-43.3%
664
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
find-files-by-patterns
Use the iterator pattern to find files upwards and downwards in the file system.
Installation
Using npm:
1npm install find-files-by-patterns
Assuming this file system, where the current working directory is
/Documents/project
:
1/ 2└── Documents 3 ├── data.csv 4 └── project 5 ├── node_modules 6 └── package.json
In Node.js:
1const { findFile, upwardDirectories, 2 ofBasename, downwardFiles } = require("find-files-by-patterns"); 3 4(async () => { 5 const dataFile = await findFile(upwardDirectories(), ofBasename("data.csv")); 6 console.log(dataFile); //=> `/Documents/data.csv` 7 8 for await (const file of downwardFiles("/Documents")) { 9 console.log(file); 10 } 11 //=> `/Documents/data.csv` 12 //=> `/Documents/project` 13 //=> `/Documents/project/node_modules` ... 14 //=> `/Documents/project/package.json` 15})(); 16
Table of Contents
- API
findFile
andfindFileSync
findAllFiles
andfindAllFilesSync
findOnlyFile
andfindOnlyFileSync
downwardDirectories
anddownwardDirectoriesSync
upwardDirectories
andupwardDirectoriesSync
downwardFiles
anddownwardFilesSync
upwardFiles
andupwardFilesSync
ofBasename
,ofName
,ofDirname
andofExtname
hasPathSegments
isFile
andisFileSync
isDirectory
andisDirectorySync
hasFile
andhasFileSync
readdir
andreaddirSync
readdirs
andreaddirsSync
filter
andfilterSync
conjunction
andconjunctionSync
disjunction
anddisjunctionSync
allElements
andallElementsSync
firstElement
andfirstElementSync
onlyElement
andonlyElementSync
- About
API
Complete list of exported functions
Finders:
Files:
Directories:
Filters:
ofBasename
,ofName
,ofDirname
andofExtname
hasPathSegments
isFile
andisFileSync
isDirectory
andisDirectorySync
hasFile
andhasFileSync
conjunction
andconjunctionSync
disjunction
anddisjunctionSync
Iterable readdir
:
Iterable utilities:
findFile
and findFileSync
Finds the first file that matches all of the given filters in the given directories. If no directory is supplied, then the current working directory is read.
Specifications
1type Filter<T> = (element: T) => Promise<boolean>; 2type FilterSync<T> = (element: T) => boolean; 3 4findFile( 5 ...tests: Array<Filter<string> | FilterSync<string>> 6): Promise<string | null>; 7 8findFile( 9 directories: string | AsyncIterable<string> | Iterable<string>, 10 ...tests: Array<Filter<string> | FilterSync<string>> 11): Promise<string | null>; 12 13findFileSync(...tests: Array<FilterSync<string>>): string | null; 14 15findFileSync( 16 directories: string | Iterable<string>, 17 ...tests: Array<FilterSync<string>> 18): string | null;
findAllFiles
and findAllFilesSync
Finds all the files that match all of the given filters in the given directories. If no directory is supplied, then the current working directory is read.
Specifications
1type Filter<T> = (element: T) => Promise<boolean>; 2type FilterSync<T> = (element: T) => boolean; 3 4findAllFiles( 5 ...tests: Array<Filter<string> | FilterSync<string>> 6): Promise<string[]>; 7 8findAllFiles( 9 directories: string | AsyncIterable<string> | Iterable<string>, 10 ...tests: Array<Filter<string> | FilterSync<string>> 11): Promise<string[]>; 12 13findAllFilesSync(...tests: Array<FilterSync<string>>): string[]; 14 15findAllFilesSync( 16 directories: string | Iterable<string>, 17 ...tests: Array<FilterSync<string>> 18): string[];
findOnlyFile
and findOnlyFileSync
Finds the first and only file in its directory that matches all of the given filters. If no directory is supplied, then the current working directory is read.
Specifications
1type Filter<T> = (element: T) => Promise<boolean>; 2type FilterSync<T> = (element: T) => boolean; 3 4findOnlyFile( 5 ...tests: Array<Filter<string> | FilterSync<string>> 6): Promise<string | null>; 7 8findOnlyFile( 9 directories: string | AsyncIterable<string> | Iterable<string>, 10 ...tests: Array<Filter<string> | FilterSync<string>> 11): Promise<string | null>; 12 13findOnlyFileSync(...tests: Array<FilterSync<string>>): string | null; 14 15findOnlyFileSync( 16 directories: string | Iterable<string>, 17 ...tests: Array<FilterSync<string>> 18): string | null;
downwardDirectories
and downwardDirectoriesSync
Returns an iterable over the existing downward files from a start path. Symbolic links are followed and handled such that no directory is traversed twice.
Specifications
1downwardDirectories(): AsyncIterable<string>;
2
3downwardDirectories(maximumDepth: number): AsyncIterable<string>;
4
5downwardDirectories(startDirectory: string): AsyncIterable<string>;
6
7downwardDirectories(startDirectory: string,
8 maximumDepth: number): AsyncIterable<string>;
9
10downwardDirectoriesSync(): Iterable<string>;
11
12downwardDirectoriesSync(maximumDepth: number): Iterable<string>;
13
14downwardDirectoriesSync(startDirectory: string): Iterable<string>;
15
16downwardDirectoriesSync(startDirectory: string,
17 maximumDepth: number): Iterable<string>;
Example
Assuming this file system, where the current working directory is /Documents
:
1/ 2└── Documents 3 ├── Images 4 | └── image.jpeg 5 └── project 6 ├── node_modules 7 └── package.json
1const { downwardDirectoriesSync } = require("find-files-by-patterns"); 2 3[ 4 ...downwardDirectoriesSync() 5]; /*=> `[ '/Documents/Images', 6 '/Documents/project', 7 '/Documents/project/node_modules' ]`*/ 8[...downwardDirectoriesSync(1)]; /*=> `[ '/Documents/Images', 9 '/Documents/project' ]`*/ 10[...downwardDirectoriesSync( 11 "/Documents/project" 12)]; //=> `[ '/Documents/project/node_modules' ]` 13[...downwardDirectoriesSync( 14 "/Documents", 1 15)]; //=> `[ '/Documents/Images', '/Documents/project' ]`
upwardDirectories
and upwardDirectoriesSync
Returns an iterable over the existing directories upwards from a start path.
Specifications
1upwardDirectories(): AsyncIterable<string>;
2
3upwardDirectories(startPath: string): AsyncIterable<string>;
4
5upwardDirectories(startPath: string,
6 maximumHeight: number): AsyncIterable<string>;
7
8upwardDirectories(startPath: string, endPath: string): AsyncIterable<string>;
9
10upwardDirectoriesSync(): Iterable<string>;
11
12upwardDirectoriesSync(startPath: string): Iterable<string>;
13
14upwardDirectoriesSync(startPath: string,
15 maximumHeight: number): Iterable<string>;
16
17upwardDirectoriesSync(startPath: string, endPath: string): Iterable<string>;
Example
Assuming this file system, where the current working directory is
/Documents/project
:
1/ 2└── Documents 3 ├── Images 4 | └── image.jpeg 5 └── project 6 ├── node_modules 7 └── package.json
1const { upwardDirectoriesSync } = require("find-files-by-patterns"); 2 3[...upwardDirectoriesSync()]; //=> `[ '/Documents', '/' ]` 4[...upwardDirectoriesSync(1)]; //=> `[ '/Documents' ]` 5[...upwardDirectoriesSync( 6 "/Documents/Images/image.jpeg" 7)]; //=> `[ '/Documents/Images', '/Documents', '/' ]` 8[...upwardDirectoriesSync( 9 "/Documents/Images/image.jpeg", 2 10)]; //=> `[ '/Documents/Images', '/Documents' ]` 11[...upwardDirectoriesSync( 12 "/Documents/Images/image.jpeg", "/Documents" 13)]; //=> `[ '/Documents/Images', '/Documents' ]`
downwardFiles
and downwardFilesSync
Returns and iterable over the files in each downward directory yielded by
downwardDirectories
or downwardDirectoriesSync
.
Specifications
1downwardFiles(): AsyncIterable<string>;
2
3downwardFiles(maximumDepth: number): AsyncIterable<string>;
4
5downwardFiles(startDirectory: string): AsyncIterable<string>;
6
7downwardFiles(startDirectory: string,
8 maximumDepth: number): AsyncIterable<string>;
9
10downwardFilesSync(): Iterable<string>;
11
12downwardFilesSync(maximumDepth: number): Iterable<string>;
13
14downwardFilesSync(startDirectory: string): Iterable<string>;
15
16downwardFilesSync(startDirectory: string,
17 maximumDepth: number): Iterable<string>;
upwardFiles
and upwardFilesSync
Returns and iterable over the files in each upward directory yielded by
upwardDirectories
or upwardDirectoriesSync
.
Specifications
1upwardFiles(): AsyncIterable<string>;
2
3upwardFiles(startPath: string): AsyncIterable<string>;
4
5upwardFiles(startPath: string, maximumHeight: number): AsyncIterable<string>;
6
7upwardFiles(startPath: string, endPath: string): AsyncIterable<string>;
8
9upwardFilesSync(): Iterable<string>;
10
11upwardFilesSync(startPath: string): Iterable<string>;
12
13upwardFilesSync(startPath: string, maximumHeight: number): Iterable<string>;
14
15upwardFilesSync(startPath: string, endPath: string): Iterable<string>;
ofBasename
, ofName
, ofDirname
and ofExtname
Determines whether or not a path's basename
, name
, dirname
or extname
matches any of a sequence of segment testers.
A segment tester can be a string, a regular expression or a function.
- If it is a string, then the segment must correspond to it for the path to match.
- If it is a regular expression, then the segment must test against it for the path to match.
- If it is a function, then the segment must make it return
true
for the path to match.
Specifications
1type SegmentTester = string | RegExp | ((segment: string) => boolean);
2
3ofBasename(...tests: SegmentTester[]): FilterSync<string>;
4
5ofName(...tests: SegmentTester[]): FilterSync<string>;
6
7ofDirname(...tests: SegmentTester[]): FilterSync<string>;
8
9ofExtname(...tests: SegmentTester[]): FilterSync<string>;
Example
1const { ofBasename, ofName, 2 ofDirname, ofExtname } = require("find-files-by-patterns"); 3 4const isMarkdownFile = ofExtname(".md", ".markdown"); 5const isIndexFile = ofName("index"); 6const isDataFilename = ofBasename(/^data/); 7const isInDocuments = ofDirname("/Documents"); 8 9isMarkdownFile("/Documents/article.md"); //=> `true` 10isMarkdownFile("/Documents/data.json"); //=> `false` 11isIndexFile("/Documents/index.html"); //=> `true` 12isIndexFile("/Documents/index.md"); //=> `true` 13isDataFilename("/Documents/data.json"); //=> `true` 14isInDocuments("/Documents/data.json"); //=> `true` 15isInDocuments("/Documents/src/index.js"); //=> `false`
hasPathSegments
Determines whether or not all the paths segments of a path match a sequence of segment testers. A segment tester can be a string, a regular expression or a function.
- If it is a string, then the segment must correspond to it for the path to match.
- If it is a regular expression, then the segment must test against it for the path to match.
- If it is a function, then the segment must make it return
true
for the path to match.
Specifications
1type SegmentTester = string | RegExp | ((segment: string) => boolean); 2 3hasPathSegments(...tests: SegmentTester[]): FilterSync<string>;
Example
1const { hasPathSegments } = require("find-files-by-patterns"); 2 3const isIgnored = hasPathSegments(segment => segment.startsWith("_")); 4 5isIgnored("project/src/_ignored.json"); //=> `true` 6 7isIgnored("project/_ignored/data.json"); //=> `true` 8 9isIgnored("project/src/data.yaml"); //=> `false`
isFile
and isFileSync
Determines whether or not a path exists on the file system and is a file.
Specifications
1isFile(path: string): Promise<boolean>;
2
3isFileSync(path: string): boolean;
isDirectory
and isDirectorySync
Determines whether or not a path exists on the file system and is a directory.
Specifications
1isDirectory(path: string): Promise<boolean>;
2
3isDirectorySync(path: string): boolean;
hasFile
and hasFileSync
Returns a filter which determines whether or not a path is a directory that has a file which matches a filter.
Specifications
1hasFile(test: Filter<string> | FilterSync<string>): Filter<string>;
2
3hasFileSync(test: FilterSync<string>): FilterSync<string>;
Example
Assuming this file system, where the current working directory is
/Documents/project
:
1/ 2└── Documents 3 ├── Images 4 | └── image.jpeg 5 └── project 6 ├── node_modules 7 └── package.json
1const { findFileSync, upwardDirectoriesSync, 2 hasFileSync, ofBasename } = require("find-files-by-patterns"); 3 4const imagesDirectory = findFileSync( 5 upwardDirectoriesSync(), 6 hasFileSync(ofBasename("image.jpeg")) 7); //=> `/Documents/Images`
readdir
and readdirSync
Returns an iterable over the fully qualified file names in the given directory.
Specifications
1readdir(directory: string): AsyncIterable<string>; 2 3readdirSync(directory: string): Iterable<string>;
readdirs
and readdirsSync
Returns an iterable over the fully qualified file names in the given sequence of directories.
Specifications
1readdirs(directory: string): AsyncIterable<string>; 2 3readdirsSync(directory: string): Iterable<string>;
filter
and filterSync
Filters out the iterated elements of an iterable for which the filter function
returns false
.
This is analogous to the array filter method.
Specifications
1type Filter<T> = (element: T) => Promise<boolean>; 2type FilterSync<T> = (element: T) => boolean; 3 4filter<T>(iterable: Iterable<T> | AsyncIterable<T>, 5 filter: Filter<T> | FilterSync<T>): AsyncIterable<T>; 6 7filterSync<T>(iterable: Iterable<T>, 8 filter: FilterSync<T>): Iterable<T>;
Example
1const { filterSync, hasPathSegments } = require("find-files-by-patterns"); 2 3const paths = [ 4 "/Documents/project", 5 "/Documents/project/data.json", 6 "/Documents/project/_directory", 7 "/Documents/project/_directory/data.json" 8]; 9[...filterSync(paths, hasPathSegments(segment => !segment.startsWith("_")))]; 10//=> `[ '/Documents/project', '/Documents/project/data.json' ]`
conjunction
and conjunctionSync
Compounds a sequence of filters using logical conjunction.
Specifications
1type Filter<T> = (element: T) => Promise<boolean>; 2type FilterSync<T> = (element: T) => boolean; 3 4conjunction<T>(filters: Array<Filter<T> | FilterSync<T>>): Filter<T>; 5 6conjunctionSync<T>(filters: Array<FilterSync<T>>): FilterSync<T>;
Example
1const { ofBasename, ofExtname, 2 conjunctionSync } = require("find-files-by-patterns"); 3 4const validDataExtensions = [".json", ".yaml", ".csv"]; 5const isDataFile = conjunctionSync([ ofBasename(basename => basename.startsWith("data")), ofExtname(...validDataExtensions)]); 6 7isDataFile("/Documents/project/data.json"); //=> `true` 8isDataFile("/Documents/project/data.yaml"); //=> `true` 9isDataFile("/Documents/project/_data.json"); //=> `false`
disjunction
and disjunctionSync
Compounds a sequence of filters using logical disjunction.
Specifications
1type Filter<T> = (element: T) => Promise<boolean>; 2type FilterSync<T> = (element: T) => boolean; 3 4disjunction<T>(filters: Array<Filter<T> | FilterSync<T>>): Filter<T>; 5 6disjunctionSync<T>(filters: Array<FilterSync<T>>): FilterSync<T>;
Example
1const { ofBasename, disjunctionSync } = require("find-files-by-patterns"); 2 3const isDataFilename = disjunctionSync([ ofBasename("data.json"), ofBasename("_data.json")]); 4 5isDataFilename("/Documents/project/data.json"); //=> `true` 6isDataFilename("/Documents/project/_data.json"); //=> `true` 7isDataFilename("/Documents/project/data.yaml"); //=> `false`
allElements
and allElementsSync
Converts an iterable to an array.
Specifications
1allElements<T>(iterable: AsyncIterable<T>): Promise<T[]>; 2 3allElementsSync<T>(iterable: Iterable<T>): T[];
firstElement
and firstElementSync
Returns the first element of an iterable.
Specifications
1firstElement<T>(iterable: AsyncIterable<T>): Promise<T | null>; 2 3firstElementSync<T>(iterable: Iterable<T>): T | null;
onlyElement
and onlyElementSync
Returns the only yielded element of an iterable. If there is more than one element yielded by the iterable, then an error is thrown.
Specifications
1onlyElement<T>(iterable: AsyncIterable<T>): Promise<T | null>; 2 3onlyElementSync<T>(iterable: Iterable<T>): T | null;
About
Building the documentation
1npm run doc
Running the tests
1npm run test
Building the library
1npm run build
Authors
- Marc-Antoine Ouimet - MartyO256
License
This project is licensed under the MIT License. See the LICENSE.md file for details.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/25 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/MartyO256/find-files-by-patterns/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/MartyO256/find-files-by-patterns/main.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/MartyO256/find-files-by-patterns/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/MartyO256/find-files-by-patterns/release.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/MartyO256/find-files-by-patterns/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/MartyO256/find-files-by-patterns/release.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:49: update your workflow using https://app.stepsecurity.io/secureworkflow/MartyO256/find-files-by-patterns/release.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:30
- Warn: npmCommand not pinned by hash: .github/workflows/release.yml:30
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 3 third-party GitHubAction dependencies pinned
- Info: 0 out of 2 npmCommand dependencies pinned
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
Project has not signed or included provenance with any releases.
Details
- Warn: release artifact v1.1.3 not signed: https://api.github.com/repos/MartyO256/find-files-by-patterns/releases/25246343
- Warn: release artifact v1.1.2 not signed: https://api.github.com/repos/MartyO256/find-files-by-patterns/releases/25156204
- Warn: release artifact v1.1.1 not signed: https://api.github.com/repos/MartyO256/find-files-by-patterns/releases/15357922
- Warn: release artifact v1.1.0 not signed: https://api.github.com/repos/MartyO256/find-files-by-patterns/releases/14863407
- Warn: release artifact v1.0.1 not signed: https://api.github.com/repos/MartyO256/find-files-by-patterns/releases/14704612
- Warn: release artifact v1.1.3 does not have provenance: https://api.github.com/repos/MartyO256/find-files-by-patterns/releases/25246343
- Warn: release artifact v1.1.2 does not have provenance: https://api.github.com/repos/MartyO256/find-files-by-patterns/releases/25156204
- Warn: release artifact v1.1.1 does not have provenance: https://api.github.com/repos/MartyO256/find-files-by-patterns/releases/15357922
- Warn: release artifact v1.1.0 does not have provenance: https://api.github.com/repos/MartyO256/find-files-by-patterns/releases/14863407
- Warn: release artifact v1.0.1 does not have provenance: https://api.github.com/repos/MartyO256/find-files-by-patterns/releases/14704612
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Reason
11 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
Score
2.5
/10
Last Scanned on 2025-01-13
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More