aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/helpers/index.ts11
-rw-r--r--src/modules/word/filterWordListByLength.ts10
2 files changed, 10 insertions, 11 deletions
diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts
index 3b94586d..048614cf 100644
--- a/src/modules/helpers/index.ts
+++ b/src/modules/helpers/index.ts
@@ -1086,7 +1086,7 @@ export class HelpersModule {
*
* @since 8.0.0
*/
- fake(patterns: string[]): string;
+ fake(patterns: ReadonlyArray<string>): string;
/**
* Generator for combining faker methods based on a static string input or an array of static string inputs.
*
@@ -1135,11 +1135,10 @@ export class HelpersModule {
*
* @since 7.4.0
*/
- fake(pattern: string | string[]): string;
- fake(pattern: string | string[]): string {
- if (Array.isArray(pattern)) {
- pattern = this.arrayElement(pattern);
- }
+ fake(pattern: string | ReadonlyArray<string>): string;
+ fake(pattern: string | ReadonlyArray<string>): string {
+ pattern =
+ typeof pattern === 'string' ? pattern : this.arrayElement(pattern);
// find first matching {{ and }}
const start = pattern.search(/{{[a-z]/);
diff --git a/src/modules/word/filterWordListByLength.ts b/src/modules/word/filterWordListByLength.ts
index 4651d497..e866bb9e 100644
--- a/src/modules/word/filterWordListByLength.ts
+++ b/src/modules/word/filterWordListByLength.ts
@@ -10,7 +10,7 @@ const STRATEGIES = {
throw new FakerError('No words found that match the given length.');
},
closest: (
- wordList: string[],
+ wordList: ReadonlyArray<string>,
length: { min: number; max: number }
): string[] => {
const wordsByLength = wordList.reduce((data, word) => {
@@ -30,15 +30,15 @@ const STRATEGIES = {
word.length === length.max + closestOffset
);
},
- shortest: (wordList: string[]): string[] => {
+ shortest: (wordList: ReadonlyArray<string>): string[] => {
const minLength = Math.min(...wordList.map((word) => word.length));
return wordList.filter((word) => word.length === minLength);
},
- longest: (wordList: string[]): string[] => {
+ longest: (wordList: ReadonlyArray<string>): string[] => {
const maxLength = Math.max(...wordList.map((word) => word.length));
return wordList.filter((word) => word.length === maxLength);
},
- 'any-length': (wordList: string[]): string[] => {
+ 'any-length': (wordList: ReadonlyArray<string>): string[] => {
return [...wordList];
},
} as const; /*
@@ -67,7 +67,7 @@ string, // Parameters<filterWordListByLength>[0]['strategy']
* - `any-length`: Returns a copy of the original word list.
*/
export function filterWordListByLength(options: {
- wordList: string[];
+ wordList: ReadonlyArray<string>;
length?: number | { min: number; max: number };
strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length';
}): string[] {