0.2.0 • Published 8 years ago
files-provider v0.2.0
files-provider
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)
}
})()Installation
npm install files-providerAPI
FilesProvider.fromDirectory
Returns or handles matched files from the given directory.
Parameters
rootString? directory to open files from (defaults to working directory) (optional, defaultprocess.cwd())
Returns Array<Object> files if RETURN is the selected strategy
createFilesProvider
Creates a FilesProvider
Parameters
$0Object?= {} options$0.regexRegExp?= null the regex to match the files with$0.singleNumber? strategy for handling a single fileHANDLE|RETURN(optional, defaultPROMPT)$0.multiNumber? strategy for handling multiple filesHANDLE|PROMPT|RETURN|PROMPT_AND_HANDLE(optional, defaultPROMPT_AND_HANDLE)$0.choiceAllBoolean? iftruea choice to select all files is included when multiple files are found (optional, defaulttrue)$0.handlerfunction?= null function to call whenHANDLE|PROMPT_AND_HANDLEstrategies are selected$0.promptHeaderString?= defaultPromptHeader header when prompting user to select a file$0.promptFooterString?= defaultPromptFooter footer when prompting user to select a file
Returns FilesProvider the files provider
License
MIT