diff options
| author | c0per <[email protected]> | 2022-05-04 17:30:58 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-04 11:30:58 +0200 |
| commit | 100a1ea230cba422174a6b5103c56bc4cf9c0dc4 (patch) | |
| tree | 914de99f5f9a68eb0f9b081283c9c57ec6259154 /src/modules | |
| parent | 788af82d574b5f929f805ef6305e5953981c79f2 (diff) | |
| download | faker-100a1ea230cba422174a6b5103c56bc4cf9c0dc4.tar.xz faker-100a1ea230cba422174a6b5103c56bc4cf9c0dc4.zip | |
fix: empty array passed into helpers.arrayElements (#921)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/helpers/index.ts | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 1b28ddfa..7f056b9f 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -783,7 +783,10 @@ export class Helpers { count?: number ): T[] { if (typeof count !== 'number') { - count = this.faker.datatype.number({ min: 1, max: array.length }); + count = + array.length === 0 + ? 0 + : this.faker.datatype.number({ min: 1, max: array.length }); } else if (count > array.length) { count = array.length; } else if (count < 0) { |
