{"_id":"optjs","_rev":"63316","name":"optjs","description":"Probably the sole command line option parser you'll ever need to...","dist-tags":{"latest":"3.2.2"},"maintainers":[{"name":"dcode","email":""}],"time":{"modified":"2021-06-03T10:21:26.000Z","created":"2013-05-03T00:41:30.896Z","3.2.2":"2016-01-11T15:16:17.788Z","3.2.1-boom":"2013-05-03T00:41:30.896Z"},"users":{"nickeltobias":true},"author":{"name":"Daniel Wirtz","email":"dcode@dcode.io"},"repository":{"type":"git","url":"git+https://github.com/dcodeIO/opt.js.git"},"versions":{"3.2.2":{"name":"optjs","description":"Probably the sole command line option parser you'll ever need to...","version":"3.2.2","author":{"name":"Daniel Wirtz","email":"dcode@dcode.io"},"repository":{"type":"git","url":"git+https://github.com/dcodeIO/opt.js.git"},"main":"./opt.js","license":"MIT","gitHead":"3316e52955256e0fde52c2fa8f00dd5eba665208","bugs":{"url":"https://github.com/dcodeIO/opt.js/issues"},"homepage":"https://github.com/dcodeIO/opt.js#readme","_id":"optjs@3.2.2","scripts":{},"_shasum":"69a6ce89c442a44403141ad2f9b370bd5bb6f4ee","_from":".","_npmVersion":"2.11.3","_nodeVersion":"0.12.7","_npmUser":{"name":"dcode","email":"dcode@dcode.io"},"maintainers":[{"name":"dcode","email":""}],"dist":{"shasum":"69a6ce89c442a44403141ad2f9b370bd5bb6f4ee","size":1139,"noattachment":false,"key":"/optjs/-/optjs-3.2.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/optjs/download/optjs-3.2.2.tgz"},"directories":{},"publish_time":1452525377788,"_cnpm_publish_time":1452525377788,"_hasShrinkwrap":false},"3.2.1-boom":{"name":"optjs","description":"Probably the sole command line option parser you'll ever need to...","version":"3.2.1-boom","author":{"name":"Daniel Wirtz","email":"dcode@dcode.io"},"repository":{"type":"git","url":"https://github.com/dcodeIO/opt.js.git"},"main":"./opt.js","license":"NASA-1.3","readmeFilename":"README.md","_id":"optjs@3.2.1-boom","dist":{"shasum":"bc0af6c8647db5eec511c4ca2d264f9646add758","size":4246,"noattachment":false,"key":"/optjs/-/optjs-3.2.1-boom.tgz","tarball":"http://registry.cnpm.dingdandao.com/optjs/download/optjs-3.2.1-boom.tgz"},"_from":".","_npmVersion":"1.2.18","_npmUser":{"name":"dcode","email":"dcode@dcode.io"},"maintainers":[{"name":"dcode","email":""}],"directories":{},"publish_time":1367541690896,"_hasShrinkwrap":false,"_cnpm_publish_time":1367541690896}},"readme":"![opt.js](https://raw.github.com/dcodeIO/opt.js/master/opt.png)\r\n======\r\nProbably the sole command line option parser you'll ever need to <del>`npm install optjs`</del> Ctrl+C, Ctrl+V. Proof:\r\n\r\n```js\r\nfunction opt(argv) {\r\n    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)=='-')\r\n    ((p=(arg=(\"\"+argv.splice(i--,1)).replace(/^[\\-]+/,'')).indexOf(\"=\"))>0?opt[arg.substring(0,p)]=arg.substring(p+1):opt[arg]=true);\r\n    return {'node':argv[0],'script':argv[1],'argv':argv.slice(2),'opt':opt};\r\n}\r\n```\r\n\r\nUsage\r\n-----\r\n```js\r\nvar opt = require(\"optjs\")();\r\nconsole.log(opt.node);   // Path to node executable\r\nconsole.log(opt.script); // Path to the current script\r\nconsole.log(opt.opt);    // Command line options as a hash\r\nconsole.log(opt.argv);   // Remaining non-option arguments\r\n```\r\n\r\nExample\r\n-------\r\n`node somescript.js foo -a=1 -b --c=\"hello world\" bar ----d`\r\n\r\n```js\r\n// Result\r\nopt.node   == \"/path/to/node[.exe]\"\r\nopt.script == \"/path/to/somescript.js\"\r\nopt.opt    == { a: 1, b: true, c: \"hello world\", d: true }\r\nopt.argv   == [\"foo\", \"bar\"]\r\n```\r\n\r\nFull-featured test suite\r\n------------------------\r\n```js\r\n#!/usr/bin/env node\r\nconsole.log(require(\"./opt.js\")());\r\n```\r\n\r\nLicense\r\n-------\r\nMIT\r\n","_attachments":{},"homepage":"https://github.com/dcodeIO/opt.js#readme","bugs":{"url":"https://github.com/dcodeIO/opt.js/issues"},"license":"MIT"}