forked from linuswillner/react-console-emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandExists.js
More file actions
42 lines (38 loc) · 1.17 KB
/
commandExists.js
File metadata and controls
42 lines (38 loc) · 1.17 KB
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
32
33
34
35
36
37
38
39
40
41
42
export default (commands, commandName, matchCaseInsensitive) => {
/* istanbul ignore next: Covered by interactivity tests */
if (matchCaseInsensitive) {
for (const command of Object.keys(commands)) {
if (new RegExp(`^${commandName}$`, 'gi').test(command)) {
return {
exists: true,
command: command
// Have to return the defined and existing command name that matched here, otherwise the executor won't know which one it is
}
}
}
if (commands.default) {
return {
exists: true,
command: commands.default
// Have to return the defined and existing command name that matched here, otherwise the executor won't know which one it is
}
}
// Command not found
return {
exists: false,
command: null
}
} else {
if (!commands[commandName] && commands.default) {
return {
exists: true,
command: 'default'
// Have to return the defined and existing command name that matched here, otherwise the executor won't know which one it is
}
}
return {
exists: commandName in commands,
command: commandName
}
}
}