diff --git a/src/utils/number.ts b/src/utils/number.ts index 596d1f1..fcd1623 100644 --- a/src/utils/number.ts +++ b/src/utils/number.ts @@ -1,3 +1,7 @@ export const isNumber = (value: string) => { return !isNaN(Number(value)); }; + +export const isPairingCode = (pairingCode: string) => { + return pairingCode.length === 8 && pairingCode.split('').every((char) => isNumber(char)); +}; diff --git a/src/yargs.ts b/src/yargs.ts index c460c84..c3bbd07 100644 --- a/src/yargs.ts +++ b/src/yargs.ts @@ -2,7 +2,7 @@ import yargs from 'yargs/yargs'; import { CATEGORIES } from './config/categories'; import { OUTPUT_FORMATS } from './config/output'; import { Category, OutputFormat } from './types'; -import { isNumber } from './utils/number'; +import { isPairingCode } from './utils/number'; export const argv = yargs(process.argv.slice(2)) // Attempt to detect the os locale @@ -92,11 +92,10 @@ export const argv = yargs(process.argv.slice(2)) ); }) .check(({ pairingCode }) => { - if (pairingCode.length === 8 && pairingCode.split('').every((char) => isNumber(char))) { + if (isPairingCode(pairingCode)) { return true; - } else { - throw new Error('Pairing Code must be specified with 8 digits'); } + throw new Error('Pairing Code must be specified with 8 digits'); }) .help() .usage('Usage: homekit-code [commands] [options]')