mu-getargs

0.0.3 • Public • Published

Version Version Build Status Coverage Status

mu-getargs

Parse a string as function arguments. Can also parse named arguments.

getargs(str)

  1. str {String} - The string to parse.

Note: If the this value of the function is defined, it will be used as the string (see examples). Thus it is possible to use this function to extend the String prototype: String.prototype.parseArgs = getargs.

Installation

  • Node: 0. npm install mu-getargs 0. var getargs = require('mu-getargs');
  • AMD (install with bower): 0. bower install mu-getargs 0. require(['mu-getargs/dist/getargs'], function(getargs){ /* ... */ });

Run tests with npm test.

Run coverage analysis with npm run coverage (coverage report is saved to ./coverage).

Examples

var str = "'hello',1,2,3,'world'",
    args = getargs(str);
console.log(args); // ["hello", 1, 2, 3, "world"]

By setting the this value:

var str = "'hello',1,2,3,'world'",
    args = getargs.call(str);
console.log(args); // ["hello", 1, 2, 3, "world"]

With named arguments:

var str = "foo='bar',1,2,3",
    args = getargs.call(str);
console.log(args); // ["bar", 1, 2, 3]
console.log(args.foo); // "bar"

Package Sidebar

Install

npm i mu-getargs

Weekly Downloads

1

Version

0.0.3

License

MIT

Last publish

Collaborators

  • eyalar