aboutsummaryrefslogtreecommitdiff
path: root/src/date.ts
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-03-15 19:16:56 +0100
committerGitHub <[email protected]>2022-03-15 19:16:56 +0100
commit5cb74b1bf31f44311b4ee54ea320b81f68879f07 (patch)
treebfe4e31ed4384be8b7b47826cf1ceb98227e9100 /src/date.ts
parent09487b6b3a6e6cc3de0303851b9913ecdf1390dc (diff)
downloadfaker-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.ts59
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]);
}
}