0.0.3 • Published 11 years ago
mu-getargs v0.0.3
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:
npm install mu-getargsvar getargs = require('mu-getargs');
- AMD (install with bower):
bower install mu-getargsrequire(['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"