files-provider
Provides apps with file(s) identified via a regex.
Last updated 3 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install files-provider 
SYNC missed versions from official npm registry.

files-provider

become a patron

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-provider

API

FilesProvider.fromDirectory

Returns or handles matched files from the given directory.

Parameters

  • root String? directory to open files from (defaults to working directory) (optional, default process.cwd())

Returns Array<Object> files if RETURN is the selected strategy

createFilesProvider

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 file HANDLE|RETURN (optional, default PROMPT)
    • $0.multi Number? strategy for handling multiple files HANDLE|PROMPT|RETURN|PROMPT_AND_HANDLE (optional, default PROMPT_AND_HANDLE)
    • $0.choiceAll Boolean? if true a choice to select all files is included when multiple files are found (optional, default true)
    • $0.handler function?= null function to call when HANDLE|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

License

MIT

Current Tags

  • 0.2.0                                ...           latest (3 years ago)

5 Versions

  • 0.2.0                                ...           3 years ago
  • 0.1.3                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 2
Dependencies (1)
Dev Dependencies (1)

Copyright 2014 - 2016 © taobao.org |