find-files-extra
v1.2.2
Published
Simple file finder with both file name and content search options
Downloads
32
Readme
Simple (with advanced feature) file search
Examples
// Find all json files (Loading content + parse to json)
let jsonFiles = await findFileExtra({
root: MY_PROJECT_ROOT,
filePattern: "**/*.json",
loadFileContent: true,
parseJson: true,
});
// Find all ts files with 'search-me' in content (Not loading content)
let files = await findFileExtra({
root: MY_PROJECT_ROOT,
filePattern: "**/*.ts",
fileContentPattern: "search-me",
});
// Find all ts files with content that match regexp (Loading content)
let files = await findFileExtra({
root: MY_PROJECT_ROOT,
filePattern: "**/*.ts",
fileContentPattern: /search\-me|searchMe/,
loadFileContent: true,
});
Result
The result is list of findFileExtraFileInfo
(interface)
export interface findFileExtraFileInfo {
fullPath: string;
pathFromRoot: string;
fileName: string;
dirFullPath: string;
dirPathFromRoot: string;
ext: string;
json?: unknown;
content?: string;
}
Options
| Option | Required | Type | Default | Description |
| ------------------ | -------- | --------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| root | true | string | - | Root directory to search in. |
| filePattern | false | string | "**/*.*"
| File pattern to search for. glob pattern |
| ignoreFilePattern | false | string[] | ["**/bin/**", "**/node_modules/**", "**/obj/**"]
| File pattern to ignore. glob pattern |
| fileContentPattern | false | regexp / string | undefined | File content pattern to search for. |
| loadFileContent | false | boolean | false | Load file content. |
| parseJson | false | boolean | false | Parse file content to json. |
| dot | false | boolean | true | Use dot notation for json keys. |
| nocase | false | boolean | true | Case insensitive search. |
parseJson
requiresloadFileContent
to be true.
if
filePattern
andfileContentPattern
is bothundefined
(not set) all files will be found in the root.
Installation
- npm install find-files-extra
- yarn add find-files-extra