1.0.2 • Published 8 years ago

string-args v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

string-args Build Status

Simple parser for space delimited arguments, like the arguments of an IRC command.

Installing

npm install string-args

Example usage

var parse = require('string-args');

// 1st parameter is a list of names
// 2nd parameter is the actual string of arguments
// string-args will attempt to map the names to their corresponding arguments
parse('one two three', 'uno dos tres')
parse('one two three', 'uno dos tres quatro') // extra args ignored
/* These both output:
{
    one: 'uno',
    two: 'dos',
    three: 'tres'
}
*/


// Missing arguments will be undefined
parse('one two three', 'uno dos')
/* Output:
{
    one: 'uno',
    two: 'dos'
}
*/


// Use '...' at the end of the last name to get the rest of the arguments
parse('one two three...', 'uno dos tres quatro cinco')
/* Output:
{
    one: 'uno',
    two: 'dos',
    three: 'tres quatro cinco'
}
*/