Skip to content

Commit

Permalink
Added answers object available for excludePath and `excludeFilter…
Browse files Browse the repository at this point in the history
…` options
  • Loading branch information
dacodekid committed Apr 5, 2022
1 parent 41714f3 commit be42aab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![npm](https://img.shields.io/npm/v/inquirer-fuzzy-path)](https://www.npmjs.com/package/inquirer-fuzzy-path)
[![npm](https://img.shields.io/npm/dw/inquirer-fuzzy-path)](https://www.npmjs.com/package/inquirer-fuzzy-path)

Fuzzy file/directory search and select prompt for Inquirer.js
Fuzzy file/directory search and select prompt for Inquirer.js

![inquirer-fuzzy-path demo](https://raw.githubusercontent.com/adelsz/inquirer-fuzzy-path/master/recording.gif)

Expand All @@ -21,12 +21,14 @@ Call the prompt:
{
type: 'fuzzypath',
name: 'path',
excludePath: nodePath => nodePath.startsWith('node_modules'),
// excludePath :: (String) -> Bool
// excludePath to exclude some paths from the file-system scan
excludeFilter: nodePath => nodePath == '.',
// excludeFilter :: (String) -> Bool
// excludeFilter to exclude some paths from the final list, e.g. '.'
excludePath: (nodePath, answers) => nodePath.startsWith('node_modules'),
// excludePath :: (String, Object) -> Bool
// excludePath to exclude some paths from the file-system scan. Use `answers` object to get previous answers
// for further customization.
excludeFilter: (nodePath, answers) => nodePath == '.',
// excludeFilter :: (String, Object) -> Bool
// excludeFilter to exclude some paths from the final list, e.g. '.'. Use `answers` object to get previous
// answers for further customization.
itemType: 'any',
// itemType :: 'any' | 'directory' | 'file'
// specify the type of nodes to display
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function getPaths(
itemType,
defaultItem,
depthLimit,
answers,
) {
const fuzzOptions = {
pre: style.green.open,
Expand All @@ -26,7 +27,7 @@ function getPaths(

async function listNodes(nodePath, level) {
try {
if (excludePath(nodePath)) {
if (excludePath(nodePath, answers)) {
return [];
}
const nodes = await readdir(nodePath);
Expand Down Expand Up @@ -59,7 +60,7 @@ function getPaths(
const preFilteredNodes =
!excludeFilter
? nodeList
: nodeList.filter(node => !excludeFilter(node));
: nodeList.filter(node => !excludeFilter(node, answers));

const filteredNodes = fuzzy
.filter(pattern || '', preFilteredNodes, fuzzOptions)
Expand Down Expand Up @@ -94,6 +95,7 @@ class InquirerFuzzyPath extends InquirerAutocomplete {
itemType,
question.default,
depthLimit,
answers,
),
},
);
Expand Down

0 comments on commit be42aab

Please sign in to comment.