aboutsummaryrefslogtreecommitdiff
path: root/src/modules/datatype
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2022-12-07 20:18:08 +0100
committerGitHub <[email protected]>2022-12-07 20:18:08 +0100
commitf06126a1ba8515d6e0b7733999d5cd2f8849be7a (patch)
tree56dadba70a0c2d78bd7ef6a6e255796cce38ea8b /src/modules/datatype
parent50fb72ce3d7a911564ad5ff9f929ca5567a83757 (diff)
downloadfaker-f06126a1ba8515d6e0b7733999d5cd2f8849be7a.tar.xz
faker-f06126a1ba8515d6e0b7733999d5cd2f8849be7a.zip
feat(helpers): introduce `multiple` method (#1545)
Diffstat (limited to 'src/modules/datatype')
-rw-r--r--src/modules/datatype/index.ts13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/modules/datatype/index.ts b/src/modules/datatype/index.ts
index 70a539d7..b7000dc6 100644
--- a/src/modules/datatype/index.ts
+++ b/src/modules/datatype/index.ts
@@ -278,16 +278,23 @@ export class DatatypeModule {
* Returns an array with random strings and numbers.
*
* @param length Size of the returned array. Defaults to `10`.
+ * @param length.min The minimum size of the array.
+ * @param length.max The maximum size of the array.
*
* @example
* faker.datatype.array() // [ 94099, 85352, 'Hz%T.C\\l;8', '|#gmtw3otS', '2>:rJ|3$&d', 56864, 'Ss2-p0RXSI', 51084, 2039, 'mNEU[.r0Vf' ]
* faker.datatype.array(3) // [ 61845, 'SK7H$W3:d*', 'm[%7N8*GVK' ]
+ * faker.datatype.array({ min: 3, max: 5 }) // [ 99403, 76924, 42281, "Q'|$&y\\G/9" ]
*
* @since 5.5.0
*/
- array(length = 10): Array<string | number> {
- return Array.from<string | number>({ length }).map(() =>
- this.boolean() ? this.faker.string.sample() : this.faker.number.int()
+ array(
+ length: number | { min: number; max: number } = 10
+ ): Array<string | number> {
+ return this.faker.helpers.multiple(
+ () =>
+ this.boolean() ? this.faker.string.sample() : this.faker.number.int(),
+ { count: length }
);
}