0.1.3 • Published 7 years ago

get-input v0.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

get-input

A lightweight library to get a value from argv and env

js-standard-style

Installation

npm install get-input --save

Example usage

var getInput = require('get-input')

// example.js
var foo = getInput({
  envKey: ['FOO', 'foo'],
  argvKey: ['-f', '--foo'],
  defaultValue: 'not found',
  endMark: '--',
  priority: 'argv'
})

console.log(foo)

// $ node example.js
// not found
//
// $ node example.js --foo
// true
//
// $ node example.js --foo bar
// bar
//
// $ node example.js -- --foo bar
// not found
//
// $ FOO=bar node example.js
// bar
//
// $ foo=bar node example.js -- --foo bax
// bar
//
// $ foo=bar node example.js --foo bax
// bax

Api

function getInput ({
  argv = process.argv.slice(2),
  argvKey,
  defaultValue,
  endMark = '--',
  env = process.env,
  envKey,
  priority = 'argv'
} = {}) {
  var argvValue = argvKey && getInputFromArgv(argv, argvKey, endMark)
  var envValue = envKey && getInputFromEnv(env, envKey)
  if (argvValue == null && envValue == null) {
    return defaultValue
  }
  return priority === 'env' ? envValue || argvValue : argvValue || envValue
}
0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago