-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (26 loc) · 844 Bytes
/
index.js
File metadata and controls
31 lines (26 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module.exports = function ( args ) {
var result = {
'_':[]
};
var value = args.join( ' ' );
var reStr = /(-[^\s-](?:-\S+)?|--\S+)\s*([^\s-]*)?/g;
var match;
while( ( match = reStr.exec( value ) ) ) {
var key = match[1].replace( /-/g,'' );
match[2] = typeof match[2] === 'undefined' ? 'true' : match[2];
if( key in result ) {
if( Array.isArray( result[key] ) ) {
result[key].push( match[2] );
}else{
result[key] = [result[key] , match[2]];
}
}else{
result[key] = match[2];
}
}
var _value = value.replace( /-[^-\s]{2,}|--?\S+\s*[^-\s]*/g,'' )
.replace( /\s*^\s*|\s+$/g,'' )
.split( /\s+/ );
result._ = result._.concat( _value );
return result;
};