@opt/require

0.2.0 • Public • Published

@opt/require

Build Status Dependency Status npm version Coverage Status

Plugin for @opt/parse adding type def which calls require() on the value.

It adds to nopt's typeDef a new type marked by the string require. When an option has that type it is tested as a path first, then, require() is called on it to get the result, which is placed into the parsed options.

Basically, you can do an option like: name: require and name: [require, Array] and you'll get back the result of the require operation in the name property.

See @opt/parse

See @opt/nopt

See @use/core

Install

npm install @opt/require --save

Usage

var parse = require('@opt/parse')

// make nopt the parser and apply our require plugin
parse.use('@opt/nopt', '@opt/require')

var options = {
  // the type def is marked with string 'require()'
  // this allows multiple of them, set into an array.
  plugin: [require, Array]
}

// an example args array with a plugin option to require()
// the module path must be absolute, or relative to CWD. or use ~/
var argv = [ 'node', 'some.js', '--plugin', 'some/module' ]

// then use parse as you would use `nopt`,
// plus any changes made possible by the plugins added
options = parse(options, {}, argv, 2)

// the above would produce:
options = {
  // can't write a function... so, 'theModuleFunction' means a real function
  // returned by require('some/module')
  plugin: [ theModuleFunction ]
  argv: {
    original: [ 'node', 'some.js', '--plugin', 'some/module' ]
    original: [ 'node', 'some.js', '--plugin', 'some/module' ]
    remain  : []
  }
}

MIT License

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.00latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.00
0.1.00

Package Sidebar

Install

npm i @opt/require

Weekly Downloads

0

Version

0.2.0

License

MIT

Last publish

Collaborators

  • elidoran
  • opt