Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(datatype): deprecate array #1853

Merged
merged 7 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/guide/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ faker.number.float({ max: 100, precision: 0.01 }); // 35.21
| `faker.datatype.float` | `faker.number.float` |
| `faker.datatype.bigInt` | `faker.number.bigInt` |

### Deprecation of `datatype.array`

The method `faker.datatype.array` has been deprecated and will be removed in v9.
If you need an array of element you are better off creating your own one using `helpers.multiple`.

### `allowLeadingZeros` behavior change in `faker.string.numeric`

The `allowLeadingZeros` boolean parameter in `faker.string.numeric` (in the new `string` module) now defaults to `true`. `faker.string.numeric` will now generate numeric strings that could have leading zeros by default.
Expand Down
9 changes: 9 additions & 0 deletions src/modules/datatype/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ export class DatatypeModule {
* faker.datatype.array({ min: 3, max: 5 }) // [ 99403, 76924, 42281, "Q'|$&y\\G/9" ]
*
* @since 5.5.0
*
* @deprecated Use your own function to build complex arrays.
*/
array(
length:
Expand All @@ -425,6 +427,13 @@ export class DatatypeModule {
max: number;
} = 10
): Array<string | number> {
deprecated({
deprecated: 'faker.datatype.array()',
proposed: 'your own function to build complex arrays',
since: '8.0',
until: '9.0',
});

return this.faker.helpers.multiple(
() =>
this.boolean() ? this.faker.string.sample() : this.faker.number.int(),
Expand Down