Skip to content

Commit

Permalink
fix(woof): make command safe
Browse files Browse the repository at this point in the history
  • Loading branch information
JackuB committed Oct 5, 2020
1 parent 7c7d579 commit 8016ae2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/cli/commands/woof.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { MethodArgs, ArgsOptions } from '../args';

interface WoofOptions {
language?: string; // ISO 639-1 code
}

const woofs = {
en: 'Woof!',
he: ' !הב ',
Expand All @@ -12,13 +8,16 @@ const woofs = {
cs: ' Haf!',
};

export = function woof(...args0: MethodArgs) {
const args = [...args0];
let options: WoofOptions = {};
if (typeof args[args.length - 1] === 'object') {
options = (args.pop() as ArgsOptions) as WoofOptions;
export = function woof(...args: MethodArgs) {
const options = args.pop() as ArgsOptions;
let lang = 'en';

if (
typeof options.language === 'string' &&
Object.keys(woofs).includes(options.language)
) {
lang = options.language;
}
const lang = options.language || 'en';
console.log(`
| |
/| |\\
Expand Down

0 comments on commit 8016ae2

Please sign in to comment.