Provides apps with file(s) identified via a regex.
const opener = require('opener')
const { HANDLE, PROMPT_AND_HANDLE, createFilesProvider } = require('files-provider')
const provideFiles = createFilesProvider({
single : HANDLE
, multi : PROMPT_AND_HANDLE
, promptHeader : 'Example Tool - please select a file to open: '
, regex : /\.js$/
, handler : ({ entry, fullPath }) => {
console.error('Opening %s', entry)
opener(`file://${fullPath}`)
}
})
;(async () => {
try {
await provideFiles.fromDirectory(__dirname)
} catch (err) {
console.error(err)
}
})()
npm install files-provider
Returns or handles matched files from the given directory.
Parameters
root
String? directory to open files from (defaults to working directory) (optional, defaultprocess.cwd()
)
Returns Array<Object> files if RETURN
is the selected strategy
Creates a FilesProvider
Parameters
$0
Object?= {} options$0.regex
RegExp?= null the regex to match the files with$0.single
Number? strategy for handling a single fileHANDLE|RETURN
(optional, defaultPROMPT
)$0.multi
Number? strategy for handling multiple filesHANDLE|PROMPT|RETURN|PROMPT_AND_HANDLE
(optional, defaultPROMPT_AND_HANDLE
)$0.choiceAll
Boolean? iftrue
a choice to select all files is included when multiple files are found (optional, defaulttrue
)$0.handler
function?= null function to call whenHANDLE|PROMPT_AND_HANDLE
strategies are selected$0.promptHeader
String?= defaultPromptHeader header when prompting user to select a file$0.promptFooter
String?= defaultPromptFooter footer when prompting user to select a file
Returns FilesProvider the files provider
MIT