aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorpomali <[email protected]>2024-03-03 11:12:17 +0100
committerGitHub <[email protected]>2024-03-03 11:12:17 +0100
commit2b15f2ee7eeba7147c75a24d71042ee996966c92 (patch)
tree2812cdda5e77ae70cc5038ee659745fa130c22ac /src/modules
parent9348138893bb95faa5037c653443fbd525ce2939 (diff)
downloadfaker-2b15f2ee7eeba7147c75a24d71042ee996966c92.tar.xz
faker-2b15f2ee7eeba7147c75a24d71042ee996966c92.zip
feat(helpers)!: stricter checking for function signature passed to `multiple` (#2563)
Co-authored-by: ST-DDT <[email protected]> Co-authored-by: Matt Mayer <[email protected]>
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/helpers/index.ts8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts
index 593d1ede..b21f13e7 100644
--- a/src/modules/helpers/index.ts
+++ b/src/modules/helpers/index.ts
@@ -1129,17 +1129,19 @@ export class SimpleHelpersModule extends SimpleModuleBase {
* @template TResult The type of elements.
*
* @param method The method used to generate the values.
+ * The method will be called with `(_, index)`, to allow using the index in the generated value e.g. as id.
* @param options The optional options object.
* @param options.count The number or range of elements to generate. Defaults to `3`.
*
* @example
- * faker.helpers.multiple(faker.person.firstName) // [ 'Aniya', 'Norval', 'Dallin' ]
- * faker.helpers.multiple(faker.person.firstName, { count: 3 }) // [ 'Santos', 'Lavinia', 'Lavinia' ]
+ * faker.helpers.multiple(() => faker.person.firstName()) // [ 'Aniya', 'Norval', 'Dallin' ]
+ * faker.helpers.multiple(() => faker.person.firstName(), { count: 3 }) // [ 'Santos', 'Lavinia', 'Lavinia' ]
+ * faker.helpers.multiple((_, i) => `${faker.color.human()}-${i + 1}`) // [ 'orange-1', 'orchid-2', 'sky blue-3' ]
*
* @since 8.0.0
*/
multiple<const TResult>(
- method: () => TResult,
+ method: (v: unknown, index: number) => TResult,
options: {
/**
* The number or range of elements to generate.