From e453c93b6d73173d448a9ac8d38124a8235dd12e Mon Sep 17 00:00:00 2001 From: Piotr Kuczynski Date: Sun, 30 Jan 2022 00:02:02 +0100 Subject: chore: rename phone_number to phone (#340) --- src/index.ts | 2 +- src/phone.ts | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/phone_number.ts | 50 -------------------------------------------------- 3 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 src/phone.ts delete mode 100644 src/phone_number.ts (limited to 'src') diff --git a/src/index.ts b/src/index.ts index 21365202..d740faea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,7 +19,7 @@ import { Lorem } from './lorem'; import { Mersenne } from './mersenne'; import { Music } from './music'; import { Name } from './name'; -import { Phone } from './phone_number'; +import { Phone } from './phone'; import { Random } from './random'; import { System } from './system'; import { Time } from './time'; diff --git a/src/phone.ts b/src/phone.ts new file mode 100644 index 00000000..1db85eae --- /dev/null +++ b/src/phone.ts @@ -0,0 +1,50 @@ +import type { Faker } from '.'; + +export class Phone { + constructor(private readonly faker: Faker) { + // Bind `this` so namespaced is working correctly + for (const name of Object.getOwnPropertyNames(Phone.prototype)) { + if (name === 'constructor' || typeof this[name] !== 'function') { + continue; + } + this[name] = this[name].bind(this); + } + } + + /** + * phoneNumber + * + * @method faker.phone.phoneNumber + * @param format + * @memberOf faker.phone + */ + phoneNumber(format?: string) { + format ||= this.faker.phone.phoneFormats(); + return this.faker.helpers.replaceSymbolWithNumber(format); + } + + // FIXME: this is strange passing in an array index. + /** + * phoneNumberFormat + * + * @method faker.phone.phoneFormatsArrayIndex + * @param phoneFormatsArrayIndex + * @memberOf faker.phone + */ + phoneNumberFormat(phoneFormatsArrayIndex: number = 0) { + return this.faker.helpers.replaceSymbolWithNumber( + this.faker.definitions.phone_number.formats[phoneFormatsArrayIndex] + ); + } + + /** + * phoneFormats + * + * @method faker.phone.phoneFormats + */ + phoneFormats(): string { + return this.faker.random.arrayElement( + this.faker.definitions.phone_number.formats + ); + } +} diff --git a/src/phone_number.ts b/src/phone_number.ts deleted file mode 100644 index 1db85eae..00000000 --- a/src/phone_number.ts +++ /dev/null @@ -1,50 +0,0 @@ -import type { Faker } from '.'; - -export class Phone { - constructor(private readonly faker: Faker) { - // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(Phone.prototype)) { - if (name === 'constructor' || typeof this[name] !== 'function') { - continue; - } - this[name] = this[name].bind(this); - } - } - - /** - * phoneNumber - * - * @method faker.phone.phoneNumber - * @param format - * @memberOf faker.phone - */ - phoneNumber(format?: string) { - format ||= this.faker.phone.phoneFormats(); - return this.faker.helpers.replaceSymbolWithNumber(format); - } - - // FIXME: this is strange passing in an array index. - /** - * phoneNumberFormat - * - * @method faker.phone.phoneFormatsArrayIndex - * @param phoneFormatsArrayIndex - * @memberOf faker.phone - */ - phoneNumberFormat(phoneFormatsArrayIndex: number = 0) { - return this.faker.helpers.replaceSymbolWithNumber( - this.faker.definitions.phone_number.formats[phoneFormatsArrayIndex] - ); - } - - /** - * phoneFormats - * - * @method faker.phone.phoneFormats - */ - phoneFormats(): string { - return this.faker.random.arrayElement( - this.faker.definitions.phone_number.formats - ); - } -} -- cgit v1.2.3