Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/files-provider
Provides apps with file(s) identified via a regex.
https://github.com/thlorenz/files-provider
Last synced: 26 days ago
JSON representation
Provides apps with file(s) identified via a regex.
- Host: GitHub
- URL: https://github.com/thlorenz/files-provider
- Owner: thlorenz
- License: mit
- Created: 2018-04-16T20:57:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-08T04:01:44.000Z (over 6 years ago)
- Last Synced: 2024-11-22T22:08:55.010Z (about 1 month ago)
- Language: JavaScript
- Homepage: https://thlorenz.github.io/files-provider
- Size: 1.13 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# files-provider
Provides apps with file(s) identified via a regex.
```js
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-provider
## [API](https://thlorenz.github.io/files-provider)
### FilesProvider.fromDirectory
Returns or handles matched files from the given directory.
**Parameters**
- `root` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** directory to open files from (defaults to working directory) (optional, default `process.cwd()`)
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** files if `RETURN` is the selected strategy
### createFilesProvider
Creates a FilesProvider
**Parameters**
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?= {}** options
- `$0.regex` **[RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)?= null** the regex to match the files with
- `$0.single` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** strategy for handling a single file `HANDLE|RETURN` (optional, default `PROMPT`)
- `$0.multi` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** strategy for handling multiple files `HANDLE|PROMPT|RETURN|PROMPT_AND_HANDLE` (optional, default `PROMPT_AND_HANDLE`)
- `$0.choiceAll` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** if `true` a choice to select all files is included when multiple files are found (optional, default `true`)
- `$0.handler` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?= null** function to call when `HANDLE|PROMPT_AND_HANDLE` strategies are selected
- `$0.promptHeader` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?= defaultPromptHeader** header when prompting user to select a file
- `$0.promptFooter` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?= defaultPromptFooter** footer when prompting user to select a fileReturns **FilesProvider** the files provider
## License
MIT