mu-getargs
v0.0.3
Published
Parse a string as function arguments
Downloads
1
Readme
mu-getargs
Parse a string as function arguments. Can also parse named arguments.
getargs(str)
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"