You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/upgrading.md
+36-41Lines changed: 36 additions & 41 deletions
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,9 @@ v9 has not yet been released. This page contains a work-in-progress list of brea
18
18
19
19
## General Breaking Changes
20
20
21
-
### Node 14 and 16 No Longer Supported
21
+
### Requires Node v18+
22
22
23
-
Support for Node.js versions 14 and 16 has been discontinued as these versions have reached their [end-of-life](https://github.com/nodejs/Release). Faker.js 9.0 requires a minimum of Node.js version 18.
23
+
Support for Node.js v14 and v16 has been discontinued as these versions have reached their [end-of-life](https://github.com/nodejs/Release). Faker.js v9 requires a minimum of Node.js v18.
If you are unable to upgrade to TS5, you have to keep using Faker v8.
44
-
45
43
### Fix Tree Shaking
46
44
47
-
Prior to this version, users had to resort to workarounds by importing specific faker instances from dedicated paths to overcome tree shaking issues.
45
+
Prior to this version, there was an issue where all locales would be bundled even if only one was used. Users had to resort to a workaround by importing specific faker instances from dedicated paths.
48
46
49
47
```ts
50
48
import { faker } from'@faker-js/faker/locale/de';
51
49
```
52
50
53
-
With the implementation of this fix, such workarounds should no longer be necessary.
54
-
That means that you should be able to import different localized faker instances from the root of your package.
51
+
With this fix, the workaround should no longer be necessary. You will be able to import different localized faker instances from the root of your package with the bundle only including those specific locales.
The dedicated import paths will still stay for now, to allow a gradual migration for our users.
57
+
The dedicated import paths are kept in v9, to allow a gradual migration for our users.
61
58
62
-
While the implementation of this change does not constitute as breaking according to semantic versioning guidelines, it does impact the behavior of users bundlers.
59
+
While this is not a breaking change according to semantic versioning guidelines, it does impact the behavior of users' bundlers.
63
60
64
-
### Use High Precision RNG by default
61
+
### Use High Precision RNG by Default
65
62
66
-
TLDR: Many Faker methods will return a different result in v9 compared to v8 for the same seed.
63
+
TLDR: Many Faker methods return a different result in v9 compared to v8 for the same seed.
67
64
68
65
In v9 we switch from a 32 bit random value to a 53 bit random value.
69
66
We don't change the underlying algorithm much, but we now consume two seed values each step instead of one.
@@ -110,13 +107,11 @@ diff(r32, r53);
110
107
111
108
#### Adoption
112
109
113
-
If you don't have any seeded tests and just want some random values, then you don't have to change anything.
114
-
115
-
If you have seeded tests, you have to update most test snapshots or similar comparisons to new values.
116
-
117
-
If you are using vitest, you can do that using `pnpm vitest run -u`.
110
+
- If you don't have any seeded tests and just want some random values, then you don't have to change anything.
111
+
- If you have seeded tests, you have to update most test snapshots or similar comparisons to new values.
112
+
- If you are using [vitest](https://vitest.dev), you can do that using `pnpm vitest run -u`.
118
113
119
-
#### Keeping the old behavior
114
+
#### Keeping the Old Behavior
120
115
121
116
You can keep the old behavior, if you create your own `Faker` instance
122
117
and pass a `Randomizer` instance from the `generateMersenne32Randomizer()` function to it.
@@ -134,19 +129,19 @@ const faker = new Faker({
134
129
});
135
130
```
136
131
137
-
### Using `tsup` for the build process
132
+
### Using `tsup` for the Build Process
138
133
139
-
We only support exports defined via `package.json` but after the switch to `tsup`, there are now complete restructures in the dist folder resulting it minified and chunked files for cjs.
134
+
After the switch to [tsup](https://tsup.egoist.dev), the `dist` folder now contains minified and chunked files for CJS. However, as we officially support only `exports` defined via `package.json`, this should not affect your code.
140
135
141
136
## Removals of Deprecated Code
142
137
143
138
A large number of methods which were deprecated in v8 are completely removed in v9. To prepare for the upgrade, it is recommended to first upgrade to the latest version of v8 (e.g. `npm install --save-dev faker@8`) and fix any deprecation warnings issued by your code.
144
139
145
-
The following sections will contain more information about these changes.
140
+
The following sections contain more information about these changes.
146
141
147
142
### Constructor and JS Backwards-Compatibility Methods
148
143
149
-
Removed deprecated faker constructor, so it is not possible anymore to just pass a locale string identifier.
144
+
Removed deprecated faker constructor, so you can no longer just pass a locale string identifier.
150
145
151
146
Also removed the accessors and method that were only for JS backwards compatibility.
152
147
@@ -252,7 +247,7 @@ Note these are not exact replacements:
252
247
253
248
#### `faker.helpers.replaceSymbolWithNumber`
254
249
255
-
The `replaceSymbolWithNumber` method was deprecated in Faker 8.4 and removed in 9.0. The method parsed the given string symbol by symbol and replaces the `#` symbol with digits (`0` - `9`) and the `!` symbol with digits >=2 (`2` - `9`). This was primarily used internally by Faker for generating phone numbers. If needed, you can use a simple string replace combined with `faker.string.numeric` to replace this
250
+
The `replaceSymbolWithNumber` method was deprecated in Faker v8.4 and removed in v9.0. The method parsed the given string symbol by symbol and replaces the `#` symbol with digits (`0` - `9`) and the `!` symbol with digits >=2 (`2` - `9`). This was primarily used internally by Faker for generating phone numbers. If needed, you can use a simple string replace combined with `faker.string.numeric` to replace this
The `regexpStyleStringParse` method in `faker.helpers` was deprecated in Faker 8.1 and removed in 9.0. A likely replacement is the more powerful `faker.helpers.fromRegExp`.
272
+
The `regexpStyleStringParse` method in `faker.helpers` was deprecated in Faker v8.1 and removed in v9.0. A likely replacement is the more powerful `faker.helpers.fromRegExp`.
However, please note that `faker.helpers.fromRegExp` is not an exact replacement for `faker.helpers.regexpStyleStringParse` as `fromRegExp` cannot handle numeric ranges. This will now need to be handled separately.
279
+
However, please note that `faker.helpers.fromRegExp` is not an exact replacement for `faker.helpers.regexpStyleStringParse` as `fromRegExp` cannot handle numeric ranges. This now needs to be handled separately.
285
280
286
281
```ts
287
282
faker.helpers.regexpStyleStringParse('a{3,6}[1-100]'); // "aaaa53", etc.
@@ -294,7 +289,7 @@ Prior to v9, Faker provided a [`faker.helpers.unique()`](https://v8.fakerjs.dev/
294
289
295
290
Please see the [unique values guide](/guide/unique) for alternatives.
296
291
297
-
For example, many simple use cases can use [`faker.helpers.uniqueArray`](https://v8.fakerjs.dev/api/helpers.html#uniqueArray). Or you can migrate to a third party package such as `enforce-unique`:
292
+
For example, many simple use cases can use [`faker.helpers.uniqueArray`](https://v8.fakerjs.dev/api/helpers.html#uniqueArray). Or you can migrate to a recommended third party package such as [`enforce-unique`](https://www.npmjs.com/package/enforce-unique):
298
293
299
294
Basic example:
300
295
@@ -351,7 +346,7 @@ const city = enforcer.enforce(faker.location.city, {
351
346
```
352
347
353
348
::: tip Note
354
-
`enforce-unique` does not support the `exclude` or `store` options. If you were previously using these, you may wish to build your own unique logic instead.
349
+
`enforce-unique` does not directly support the `store` option previously available in `faker.helpers.unique`. If you were previously using this parameter, check the [documentation](https://www.npmjs.com/package/enforce-unique). If you need to reset the store, you can call the `reset()` method on the `UniqueEnforcer` instance.
@@ -519,9 +514,9 @@ Removed deprecated type aliases
519
514
520
515
## Breaking Changes to Specific Methods
521
516
522
-
### Changed Default Mode from Birthdate
517
+
### Birthdate New Default Mode
523
518
524
-
Previously, the method had defaults that were unclear in their specific impact.
519
+
Previously, the `faker.date.birthdate()`method had defaults that were unclear in their specific impact.
525
520
Now, the method requires either none or all of the `min`, `max` and `mode` options.
526
521
527
522
We also improved the error messages in case of invalid min/max age/year ranges.
@@ -536,14 +531,14 @@ Now, this throws an error raising awareness of that bad value.
536
531
537
532
This affects the `refDate` parameter of the `anytime()`, `birthdate()`, `past()`, `future()`, `recent()` and `soon()`, methods as well as the `from` and `to` parameters of `between()` and `betweens()`.
538
533
539
-
### Prices now return more price-like values
534
+
### Prices Now Return More Price-Like Values
540
535
541
-
The `faker.commerce.price` method now produces values, that also return fractional values.
536
+
The `faker.commerce.price()` method now produces values that also return fractional values.
542
537
543
538
Old price: 828.00
544
539
New price: 828.59
545
540
546
-
The last digit of the price will adjusted to be more price-like:
541
+
The last digit of the price is adjusted to be more price-like:
547
542
548
543
- 50% of the time: `9`
549
544
- 30% of the time: `5`
@@ -552,7 +547,7 @@ The last digit of the price will adjusted to be more price-like:
552
547
553
548
We plan to rethink this method some more in the future: [#2579](https://github.com/faker-js/faker/issues/2579)
554
549
555
-
### Randomized Image Option Defaults
550
+
### Images Have Random Options by Default
556
551
557
552
`faker.image.url()` now returns an image url with a random width and height by default. To obtain the previous behavior, pass `{width: 640, height: 480}`.
558
553
@@ -562,11 +557,11 @@ We plan to rethink this method some more in the future: [#2579](https://github.c
562
557
563
558
`faker.image.dataUri()` now returns an image url with a random width and height by default, additionally the type of the image is now random. To obtain the previous behavior, pass `{width: 640, height: 480, type: 'svg-uri'}`.
564
559
565
-
### Require `from` and `to` in `faker.date.between()` and `betweens()`
560
+
### Require `from` and `to` in `faker.date.between` and `betweens`
566
561
567
-
Previously, in `faker.date.between()` and `faker.date.betweens()` if the `from` or `to` parameter was omitted (in Javascript) or an invalid date (in Javascript or Typescript), they would default to the current date or reference date. Now, both boundaries must now be given explictly. If you still need the old behavior, you can pass `Date.now()` or the reference date for `from` or `to`.
562
+
Previously, in `faker.date.between()` and `faker.date.betweens()` if the `from` or `to` parameter was omitted (in Javascript) or an invalid date (in Javascript or Typescript), they would default to the current date or reference date. Now, both boundaries must be given explicitly. If you still need the old behavior, you can pass `Date.now()` or the reference date for `from` or `to`.
568
563
569
-
### Stricter Checking for Function Signature passed to `faker.helpers.multiple` Method
564
+
### Stricter Checking for Function Signature Passed to `faker.helpers.multiple` Method
570
565
571
566
The `faker.helpers.multiple` method takes a function reference as its first parameter. Previously you may have written code like this to generate multiple values.
`faker.phone.number()` generates a phone number for the current locale. However, previously there was little control over the generated number, which might or might not include country codes, extensions, white space and punctuation.
626
+
`faker.phone.number()` generates a phone number for the current locale. Previously, there was little control over the generated number, which may or may not have included country codes, extensions, white space, and punctuation.
632
627
633
628
If you wanted more control over the number, it was previously necessary to pass an explicit `format` parameter. This has now been removed. Instead, you can consider one of two options:
0 commit comments