@@ -3,17 +3,23 @@ import {
33 TYPE_FIGURE ,
44 TYPE_REGEXP ,
55 TYPE_ARRAY ,
6+ TYPE_MATCHER ,
67} from './constants'
78import Ctx from './ctx'
8- import { CommandInterface , CallbackType , CommandType } from './types/command'
9+ import {
10+ CommandInterface ,
11+ CallbackType ,
12+ CommandType ,
13+ CommandNameType ,
14+ } from './types/command'
915import { CtxInterface } from './types/ctx'
1016
1117export default class Command implements CommandInterface {
12- public name : any [ ] | string | RegExp
13- public type : | CommandType
18+ public name : CommandNameType
19+ public type : CommandType
1420 public callback : CallbackType
1521
16- constructor ( name : string , callback : CallbackType ) {
22+ constructor ( name : CommandNameType , callback : CallbackType ) {
1723 if ( name === undefined ) { throw new Error ( 'Command name is not specified' ) }
1824 this . name = name
1925 this . callback = callback
@@ -25,15 +31,18 @@ export default class Command implements CommandInterface {
2531 public _defineCommandType ( name ) {
2632 let type
2733
28- if ( typeof name === 'string' ) {
29- type = TYPE_STRING
30- if ( name . includes ( '${' ) ) {
31- type = TYPE_FIGURE
34+ if ( typeof name === 'function' ) {
35+ type = TYPE_MATCHER
3236 }
37+ if ( typeof name === 'string' ) {
38+ type = TYPE_STRING
39+ if ( name . includes ( '${' ) ) {
40+ type = TYPE_FIGURE
41+ }
3342 } else if ( name instanceof RegExp ) {
34- type = TYPE_REGEXP
43+ type = TYPE_REGEXP
3544 } else if ( Array . isArray ( name ) ) {
36- type = TYPE_ARRAY
45+ type = TYPE_ARRAY
3746 } else {
3847 throw new Error ( `Command name is not of proper type.
3948 Could be only string, array of strings or regular expression` )
0 commit comments