diff --git a/src/cli/commands/woof.ts b/src/cli/commands/woof.ts index 4c294d4906..42a19df694 100644 --- a/src/cli/commands/woof.ts +++ b/src/cli/commands/woof.ts @@ -1,29 +1,8 @@ -import { MethodArgs, ArgsOptions } from '../args'; +import { MethodArgs } from '../args'; +import getWoof from './woof/getWoof'; -const woofs = { - en: 'Woof!', - he: ' !הב ', - ru: ' Гав!', - es: 'Guau!', - cs: ' Haf!', -}; - -export function getWoofLanguage(args: MethodArgs): string { - const options = args.pop() as ArgsOptions; - let lang = 'en'; - - if ( - typeof options.language === 'string' && - Object.keys(woofs).includes(options.language) - ) { - lang = options.language; - } - - return lang; -} - -export default function woof(...args: MethodArgs) { - const lang = getWoofLanguage(args); +export = function woof(...args: MethodArgs) { + const woof = getWoof(args); console.log(` | | /| |\\ @@ -37,7 +16,7 @@ export default function woof(...args: MethodArgs) { | | | | \\ ( ) / \\_/ \\_/ /-----\\ - \\U/ --( ${woofs[lang]} ) + \\U/ --( ${woof} ) \\-----/ `); -} +}; diff --git a/src/cli/commands/woof/getWoof.ts b/src/cli/commands/woof/getWoof.ts new file mode 100644 index 0000000000..0be68195a6 --- /dev/null +++ b/src/cli/commands/woof/getWoof.ts @@ -0,0 +1,23 @@ +import { MethodArgs, ArgsOptions } from '../../args'; + +const woofs = { + en: 'Woof!', + he: ' !הב ', + ru: ' Гав!', + es: 'Guau!', + cs: ' Haf!', +}; + +export default function getWoof(args: MethodArgs): string { + const options = args.pop() as ArgsOptions; + let lang = 'en'; + + if ( + typeof options.language === 'string' && + Object.keys(woofs).includes(options.language) + ) { + lang = options.language; + } + + return woofs[lang]; +} diff --git a/test/woof.spec.ts b/test/woof.spec.ts index dec887a8c8..c7c45221b7 100644 --- a/test/woof.spec.ts +++ b/test/woof.spec.ts @@ -1,28 +1,28 @@ -import { getWoofLanguage } from '../src/cli/commands/woof'; +import getWoof from '../src/cli/commands/woof/getWoof'; describe('Woof command - Language option', () => { it('Default language is "en"', () => { // $ snyk woof - expect(getWoofLanguage([{} as any])).toEqual('en'); + expect(getWoof([{} as any])).toEqual('Woof!'); }); it('Returns selected language', () => { expect( - getWoofLanguage([ + getWoof([ { language: 'he', } as any, ]), - ).toEqual('he'); + ).toEqual(' !הב '); }); it('Returns default when selected language is invalid', () => { expect( - getWoofLanguage([ + getWoof([ { language: 'toString', } as any, ]), - ).toEqual('en'); + ).toEqual('Woof!'); }); });