diff options
| author | ST-DDT <[email protected]> | 2022-03-15 19:16:56 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-03-15 19:16:56 +0100 |
| commit | 5cb74b1bf31f44311b4ee54ea320b81f68879f07 (patch) | |
| tree | bfe4e31ed4384be8b7b47826cf1ceb98227e9100 /src/date.ts | |
| parent | 09487b6b3a6e6cc3de0303851b9913ecdf1390dc (diff) | |
| download | faker-5cb74b1bf31f44311b4ee54ea320b81f68879f07.tar.xz faker-5cb74b1bf31f44311b4ee54ea320b81f68879f07.zip | |
chore: fix some lint warnings (#613)
Co-authored-by: Shinigami <[email protected]>
Diffstat (limited to 'src/date.ts')
| -rw-r--r-- | src/date.ts | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/src/date.ts b/src/date.ts index 818a946a..dcc23600 100644 --- a/src/date.ts +++ b/src/date.ts @@ -1,4 +1,5 @@ import type { Faker } from '.'; +import type { DateEntryDefinition } from './definitions'; /** * Module to generate dates. @@ -205,23 +206,24 @@ export class _Date { * faker.date.month({ abbr: true, context: true }) // 'Sep' */ month(options?: { abbr?: boolean; context?: boolean }): string { - options = options || {}; + const abbr = options?.abbr ?? false; + const context = options?.context ?? false; - let type = 'wide'; - if (options.abbr) { - type = 'abbr'; - } - if ( - options.context && - typeof this.faker.definitions.date.month[type + '_context'] !== - 'undefined' - ) { - type += '_context'; + const source = this.faker.definitions.date.month; + let type: keyof DateEntryDefinition; + if (abbr) { + if (context && typeof source['abbr_context'] !== 'undefined') { + type = 'abbr_context'; + } else { + type = 'abbr'; + } + } else if (context && typeof source['wide_context'] !== 'undefined') { + type = 'wide_context'; + } else { + type = 'wide'; } - const source = this.faker.definitions.date.month[type]; - - return this.faker.random.arrayElement(source); + return this.faker.random.arrayElement(source[type]); } /** @@ -238,22 +240,23 @@ export class _Date { * faker.date.weekday({ abbr: true, context: true }) // 'Fri' */ weekday(options?: { abbr?: boolean; context?: boolean }): string { - options = options || {}; + const abbr = options?.abbr ?? false; + const context = options?.context ?? false; - let type = 'wide'; - if (options.abbr) { - type = 'abbr'; - } - if ( - options.context && - typeof this.faker.definitions.date.weekday[type + '_context'] !== - 'undefined' - ) { - type += '_context'; + const source = this.faker.definitions.date.weekday; + let type: keyof DateEntryDefinition; + if (abbr) { + if (context && typeof source['abbr_context'] !== 'undefined') { + type = 'abbr_context'; + } else { + type = 'abbr'; + } + } else if (context && typeof source['wide_context'] !== 'undefined') { + type = 'wide_context'; + } else { + type = 'wide'; } - const source = this.faker.definitions.date.weekday[type]; - - return this.faker.random.arrayElement(source); + return this.faker.random.arrayElement(source[type]); } } |
