change return data in argument-parser.
This commit is contained in:
@ -4,6 +4,9 @@ const FORMAT_REST = /\.{3}(\w+)/g;
|
||||
|
||||
const ESCAPABLE = '.^$*+?()[{\\|}]'.split('');
|
||||
|
||||
const REQUIRED = 0;
|
||||
const OPTIONAL = 1;
|
||||
|
||||
/**
|
||||
* Parses a message for arguments, based on format
|
||||
*
|
||||
@ -36,21 +39,26 @@ export default function argumentParser(format, string) {
|
||||
string = string.replace(/[^\s]+/, '').trim();
|
||||
format = format.replace(/[^\s]+/, '').trim();
|
||||
|
||||
if (!string || !format) {
|
||||
if (!format) {
|
||||
return {};
|
||||
}
|
||||
|
||||
let indexes = [];
|
||||
if (!string) return {args: {}, params};
|
||||
|
||||
let indexes = [],
|
||||
params = {};
|
||||
|
||||
format = format.replace(/\s/g, '\\s*');
|
||||
format = format.replace(FORMAT_REQUIRED,
|
||||
(f, symbols, arg, type = 'word', offset) => {
|
||||
indexes.push({arg, offset});
|
||||
params[arg] = REQUIRED;
|
||||
return (escape(symbols) + getFormat(type, 'required')).trim();
|
||||
});
|
||||
format = format.replace(FORMAT_OPTIONAL,
|
||||
(f, symbols, arg, type = 'word', offset) => {
|
||||
indexes.push({arg, offset});
|
||||
params[arg] = OPTIONAL;
|
||||
return (escape(symbols, '?') + getFormat(type, 'optional')).trim();
|
||||
});
|
||||
format = format.replace(FORMAT_REST, (full, arg, offset) => {
|
||||
@ -73,7 +81,7 @@ export default function argumentParser(format, string) {
|
||||
object[argument.arg] = match;
|
||||
}
|
||||
|
||||
return object;
|
||||
return {args: object, params};
|
||||
}
|
||||
|
||||
function escape(symbols, append = '') {
|
||||
|
Reference in New Issue
Block a user