# optjs

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

Latest version **3.2.2** (published 2016-01-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install optjs
pnpm add optjs
yarn add optjs
bun add optjs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.2 |
| Published | 2016-01-11 |
| First published | 2013-05-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Daniel Wirtz |
| Maintainers | dcode |

## Links

- npm: https://www.npmjs.com/package/optjs
- Repository: https://github.com/dcodeIO/opt.js
- Homepage: https://github.com/dcodeIO/opt.js#readme
- Issues: https://github.com/dcodeIO/opt.js/issues
- npm.io page: https://npm.io/package/optjs

## Recent versions

- 3.2.2 (latest) — 2016-01-11
- 3.2.1-boom — 2013-05-03

## README

![opt.js](https://raw.github.com/dcodeIO/opt.js/master/opt.png)
======
Probably the sole command line option parser you'll ever need to <del>`npm install optjs`</del> Ctrl+C, Ctrl+V. Proof:

```js
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
-----
```js
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`

```js
// 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"]
```

Full-featured test suite
------------------------
```js
#!/usr/bin/env node
console.log(require("./opt.js")());
```

License
-------
MIT

---
_Source: https://npm.io/package/optjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
