Catalog npm
PACKAGE EXPLORERView in registry

140-opts

npm

140 bytes fancy options parsing

Versions collected3
Direct dependencies1From release 1.3.0
Last observed20 Oct, 18:14 UTC

README

Current package documentation

140-opts Build Status

Command line arguments parser. This one doesn't do much. But it feets in a tweet.

Installation

$ npm install 140-opts

Alternately, to just copy the file into your repo and avoid an additional package.json dependency:

$ curl https://cdn.rawgit.com/mklabs/140-opts/master/opts.js > 140-opts.js

# or maybe
$ git clone https://github.com/mklabs/140-opts.git lib/140-opts

Code

module.exports = function(a){return a.map(function(c,d){return{n:c.match(/^--?(.+)/),v:a[d+1]||!0}}).reduce(function(a,b){b.n&&(a[b.n[1]]=b.v);return a},{})}

in a sligtly more readable way

// 242-opts
module.exports = function (a) {
  return a
    .map(function (c, d) {
      return {
        n: c.match(/^--?(.+)/),
        v: a[d+1]||!0
      };
    })
    .reduce(function (a, b) {
      b.n&&(a[b.n[1]]=b.v);
      return a;
    }, {})
};

Usage

var opts = require('140-opts')(process.argv.slice(2));
console.log(opts);

Takes a single argument, an array of String to parse, usually process.argv.slice(2).

var opts = require('140-opts');
var argv = opts(['--foo', 'foo', '--bar', 'bar', '-b', 'baz', '-o', 'woot', '--blah']);
assert.deepEqual(argv, {
  foo: 'foo',
  bar: 'bar',
  b: 'baz',
  o: 'woot',
  blah: true
});

Tests

    $ node test


    Success!

    $ --foo foo --bar bar -b baz -o woot --blah

    { foo: 'foo', bar: 'bar', b: 'baz', o: 'woot', blah: true }

    \o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/
    \o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/
    \o/\o/\o/\o/\o/                        \o/\o/\o/\o/\o/\o/\o/
    \o/\o/\o/\o/\o/                        \o/\o/\o/\o/\o/\o/\o/
    \o/\o/\o/\o/\o/       We did it!       \o/\o/\o/\o/\o/\o/\o/
    \o/\o/\o/\o/\o/                        \o/\o/\o/\o/\o/\o/\o/
    \o/\o/\o/\o/\o/                        \o/\o/\o/\o/\o/\o/\o/
    \o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/
    \o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/
    \o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/\o/

educational and experimental, doing 140bytes snippet of node code is kinda silly... But it's fun! And it's a good opportunity to learn some super-interesting byte saving techniques

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 3

Collected releases
VersionPublishedDirect dependenciesOpen version
1.3.0Registry latest5 Jun 20161
1.2.05 Jun 20160
1.1.031 May 20160

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
mklabs/140-opts

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 18:14 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:c8106578788754e300da8e8877f9087d529b4a155c5f27f7b659fc0f5de9baa4