From 93416f71cf0ddf32dd12c181c862a1b59ef4fd86 Mon Sep 17 00:00:00 2001 From: DivisionByZero Date: Sun, 6 Jul 2025 17:43:03 +0200 Subject: refactor(word)!: change default error strategy to 'fail' (#3560) --- src/modules/word/filter-word-list-by-length.ts | 4 +-- src/modules/word/index.ts | 39 +++++++++++--------------- 2 files changed, 18 insertions(+), 25 deletions(-) (limited to 'src/modules') diff --git a/src/modules/word/filter-word-list-by-length.ts b/src/modules/word/filter-word-list-by-length.ts index 6c1b25bf..c4e5999e 100644 --- a/src/modules/word/filter-word-list-by-length.ts +++ b/src/modules/word/filter-word-list-by-length.ts @@ -51,7 +51,7 @@ const STRATEGIES = { * @param options The options to provide. * @param options.wordList A list of words to filter. * @param options.length The exact or the range of lengths the words should have. - * @param options.strategy The strategy to apply when no words with a matching length are found. Defaults to `'any-length'`. + * @param options.strategy The strategy to apply when no words with a matching length are found. Defaults to `'fail'`. * * Available error handling strategies: * @@ -66,7 +66,7 @@ export function filterWordListByLength(options: { length?: number | { min: number; max: number }; strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; }): string[] { - const { wordList, length, strategy = 'any-length' } = options; + const { wordList, length, strategy = 'fail' } = options; if (length != null) { const filter: (word: string) => boolean = diff --git a/src/modules/word/index.ts b/src/modules/word/index.ts index 6713eec0..cf5719b2 100644 --- a/src/modules/word/index.ts +++ b/src/modules/word/index.ts @@ -21,12 +21,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.adjective() // 'pungent' * faker.word.adjective(5) // 'slimy' - * faker.word.adjective(100) // 'complete' * faker.word.adjective({ strategy: 'shortest' }) // 'icy' * faker.word.adjective({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'distant' * @@ -62,7 +61,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -94,12 +93,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.adverb() // 'quarrelsomely' * faker.word.adverb(5) // 'madly' - * faker.word.adverb(100) // 'sadly' * faker.word.adverb({ strategy: 'shortest' }) // 'too' * faker.word.adverb({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'sweetly' * @@ -135,7 +133,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -167,12 +165,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.conjunction() // 'in order that' * faker.word.conjunction(5) // 'since' - * faker.word.conjunction(100) // 'as long as' * faker.word.conjunction({ strategy: 'shortest' }) // 'or' * faker.word.conjunction({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'hence' * @@ -208,7 +205,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -240,12 +237,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.interjection() // 'gah' * faker.word.interjection(5) // 'fooey' - * faker.word.interjection(100) // 'yowza' * faker.word.interjection({ strategy: 'shortest' }) // 'hm' * faker.word.interjection({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'boohoo' * @@ -281,7 +277,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -313,12 +309,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.noun() // 'external' * faker.word.noun(5) // 'front' - * faker.word.noun(100) // 'care' * faker.word.noun({ strategy: 'shortest' }) // 'ad' * faker.word.noun({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'average' * @@ -354,7 +349,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -386,12 +381,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.preposition() // 'without' * faker.word.preposition(5) // 'abaft' - * faker.word.preposition(100) // 'an' * faker.word.preposition({ strategy: 'shortest' }) // 'a' * faker.word.preposition({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'given' * @@ -427,7 +421,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -459,12 +453,11 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.verb() // 'act' * faker.word.verb(5) // 'tinge' - * faker.word.verb(100) // 'mess' * faker.word.verb({ strategy: 'shortest' }) // 'do' * faker.word.verb({ length: { min: 5, max: 7 }, strategy: "fail" }) // 'vault' * @@ -500,7 +493,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} @@ -532,7 +525,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * Defaults to `'any-length'`. + * Defaults to `'fail'`. * * @example * faker.word.sample() // 'incidentally' @@ -570,7 +563,7 @@ export class WordModule extends ModuleBase { * - `longest`: Returns any of the longest words. * - `any-length`: Returns a word with any length. * - * @default 'any-length' + * @default 'fail' */ strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; } = {} -- cgit v1.2.3