Socket
Socket
Sign inDemoInstall

optjs

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    optjs

Probably the sole command line option parser you'll ever need to...


Version published
Weekly downloads
206K
increased by2.63%
Maintainers
1
Install size
2.88 kB
Created
Weekly downloads
 

Readme

Source

opt.js

Probably the sole command line option parser you'll ever need to npm install optjs Ctrl+C, Ctrl+V. Proof:

function opt(argv) {
    var opt={},arg,p;argv=Array.prototype.slice.call(argv||process.argv);for(var i=2;i<argv.length;i++)if(argv[i].charAt(0)=='-')
    ((p=(arg=(""+argv.splice(i--,1)).replace(/^[\-]+/,'')).indexOf("="))>0?opt[arg.substring(0,p)]=arg.substring(p+1):opt[arg]=true);
    return {'node':argv[0],'script':argv[1],'argv':argv.slice(2),'opt':opt};
}

Usage

var opt = require("optjs")();
console.log(opt.node);   // Path to node executable
console.log(opt.script); // Path to the current script
console.log(opt.opt);    // Command line options as a hash
console.log(opt.argv);   // Remaining non-option arguments

Example

node somescript.js foo -a=1 -b --c="hello world" bar ----d

// Result
opt.node   == "/path/to/node[.exe]"
opt.script == "/path/to/somescript.js"
opt.opt    == { a: 1, b: true, c: "hello world", d: true }
opt.argv   == ["foo", "bar"]
#!/usr/bin/env node
console.log(require("./opt.js")());

License

MIT

FAQs

Last updated on 11 Jan 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc