slurm
TypeScript icon, indicating that this package has built-in type declarations

0.5.10 • Public • Published

slurm v0.5.9

CLI argument parser

const slurm = require('slurm')
 
const argv = '-f -b=0 --list 1 2 3 -n=100 --func [1,2,3] -xyz'
process.argv.push(...argv.split(' '))
 
const args = slurm({
  '*': true,            // (no throw for unknown flags)
  f: 'foo',             // -f (alias of --foo)
  foo: true,            // --foo
  list: {               // --list 1 2 3
    list: true
  },
  b: {                  // -b=0
    type: 'boolean'
  },
  n: {                  // -n=100
    type: 'number',
    default: 0,
  },
  func(value) {         // --func [1,2,3]
    return JSON.parse(value)
  }
})
 
args.foo   // => true
args.list  // => ['1', '2', '3']
args.b     // => false
args.n     // => 100
args.func  // => [1, 2, 3]
args.x     // => true
args.y     // => true
args.z     // => true

Readme

Keywords

none

Package Sidebar

Install

npm i slurm

Weekly Downloads

10

Version

0.5.10

License

MIT

Unpacked Size

10.5 kB

Total Files

5

Last publish

Collaborators

  • aleclarson