aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2024-02-20 12:15:52 +0100
committerGitHub <[email protected]>2024-02-20 12:15:52 +0100
commitd89b348aa6465e5b6b6521b1dc4b77a89d58cc73 (patch)
tree03c9953cb0a2608f697e097debd15409ac102070 /src/modules
parent25f2a0326b1103c8a47a06156d43d71d2d72b7fa (diff)
downloadfaker-d89b348aa6465e5b6b6521b1dc4b77a89d58cc73.tar.xz
faker-d89b348aa6465e5b6b6521b1dc4b77a89d58cc73.zip
infra(unicorn): no-useless-switch-case (#2508)
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/color/index.ts2
-rw-r--r--src/modules/internet/index.ts49
-rw-r--r--src/modules/location/index.ts1
-rw-r--r--src/modules/string/index.ts2
4 files changed, 17 insertions, 37 deletions
diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts
index 67344597..712f9799 100644
--- a/src/modules/color/index.ts
+++ b/src/modules/color/index.ts
@@ -136,7 +136,6 @@ function toCSS(
case 'lch':
return `lch(${percentage(values[0])}% ${values[1]} ${values[2]})`;
case 'rgb':
- default:
return `rgb(${values[0]}, ${values[1]}, ${values[2]})`;
}
}
@@ -161,7 +160,6 @@ function toColorFormat(
case 'binary':
return toBinary(values);
case 'decimal':
- default:
return values;
}
}
diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts
index df860169..608a909c 100644
--- a/src/modules/internet/index.ts
+++ b/src/modules/internet/index.ts
@@ -639,24 +639,18 @@ export class InternetModule extends ModuleBase {
lastName: hasLastName = legacyLastName,
} = options;
- let result: string;
- const strategy = this.faker.number.int(hasLastName ? 1 : 2);
const separator = this.faker.helpers.arrayElement(['.', '_']);
- switch (strategy) {
- case 0:
- result = `${firstName}${separator}${lastName}${this.faker.number.int(
- 99
- )}`;
- break;
- case 1:
- result = `${firstName}${separator}${lastName}`;
- break;
- case 2:
- default:
- result = `${firstName}${this.faker.number.int(99)}`;
- break;
+ const disambiguator = this.faker.number.int(99);
+ const strategies: Array<() => string> = [
+ () => `${firstName}${separator}${lastName}${disambiguator}`,
+ () => `${firstName}${separator}${lastName}`,
+ ];
+ if (!hasLastName) {
+ strategies.push(() => `${firstName}${disambiguator}`);
}
+ let result = this.faker.helpers.arrayElement(strategies)();
+
// There may still be non-ascii characters in the result.
// First remove simple accents etc
result = result
@@ -826,24 +820,15 @@ export class InternetModule extends ModuleBase {
lastName = legacyLastName ?? this.faker.person.lastName(),
} = options;
- let result: string;
- switch (this.faker.number.int(2)) {
- case 0:
- result = `${firstName}${this.faker.number.int(99)}`;
- break;
- case 1:
- result =
- firstName + this.faker.helpers.arrayElement(['.', '_']) + lastName;
- break;
- case 2:
- default:
- result = `${firstName}${this.faker.helpers.arrayElement([
- '.',
- '_',
- ])}${lastName}${this.faker.number.int(99)}`;
- break;
- }
+ const separator = this.faker.helpers.arrayElement(['.', '_']);
+ const disambiguator = this.faker.number.int(99);
+ const strategies: Array<() => string> = [
+ () => `${firstName}${disambiguator}`,
+ () => `${firstName}${separator}${lastName}`,
+ () => `${firstName}${separator}${lastName}${disambiguator}`,
+ ];
+ let result = this.faker.helpers.arrayElement(strategies)();
result = result.toString().replaceAll("'", '');
result = result.replaceAll(' ', '');
return result;
diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts
index fee40fd2..97120766 100644
--- a/src/modules/location/index.ts
+++ b/src/modules/location/index.ts
@@ -360,7 +360,6 @@ export class LocationModule extends ModuleBase {
case 'alpha-3':
return 'alpha3';
case 'alpha-2':
- default:
return 'alpha2';
}
})();
diff --git a/src/modules/string/index.ts b/src/modules/string/index.ts
index 8b3cbd26..cf469a2c 100644
--- a/src/modules/string/index.ts
+++ b/src/modules/string/index.ts
@@ -230,7 +230,6 @@ export class StringModule extends SimpleModuleBase {
charsArray = [...LOWER_CHARS];
break;
case 'mixed':
- default:
charsArray = [...LOWER_CHARS, ...UPPER_CHARS];
break;
}
@@ -321,7 +320,6 @@ export class StringModule extends SimpleModuleBase {
charsArray.push(...LOWER_CHARS);
break;
case 'mixed':
- default:
charsArray.push(...LOWER_CHARS, ...UPPER_CHARS);
break;
}