Skip to content

Commit 855e6a2

Browse files
authored
docs: minor migration guide updates (#2811)
1 parent a1b9ffd commit 855e6a2

File tree

1 file changed

+36
-41
lines changed

1 file changed

+36
-41
lines changed

docs/guide/upgrading.md

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ v9 has not yet been released. This page contains a work-in-progress list of brea
1818

1919
## General Breaking Changes
2020

21-
### Node 14 and 16 No Longer Supported
21+
### Requires Node v18+
2222

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.
2424

2525
### Upgrade to TypeScript v5
2626

@@ -40,30 +40,27 @@ faker.helpers.arrayElement([1, 2, 3] as const); // 1 | 2 | 3
4040
faker.helpers.arrayElement([1, 2, 3]); // 1 | 2 | 3
4141
```
4242

43-
If you are unable to upgrade to TS5, you have to keep using Faker v8.
44-
4543
### Fix Tree Shaking
4644

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.
4846

4947
```ts
5048
import { faker } from '@faker-js/faker/locale/de';
5149
```
5250

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.
5552

5653
```ts
5754
import { fakerDE, fakerES, fakerFR } from '@faker-js/faker';
5855
```
5956

60-
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.
6158

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.
6360

64-
### Use High Precision RNG by default
61+
### Use High Precision RNG by Default
6562

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.
6764

6865
In v9 we switch from a 32 bit random value to a 53 bit random value.
6966
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);
110107

111108
#### Adoption
112109

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`.
118113

119-
#### Keeping the old behavior
114+
#### Keeping the Old Behavior
120115

121116
You can keep the old behavior, if you create your own `Faker` instance
122117
and pass a `Randomizer` instance from the `generateMersenne32Randomizer()` function to it.
@@ -134,19 +129,19 @@ const faker = new Faker({
134129
});
135130
```
136131

137-
### Using `tsup` for the build process
132+
### Using `tsup` for the Build Process
138133

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.
140135

141136
## Removals of Deprecated Code
142137

143138
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.
144139

145-
The following sections will contain more information about these changes.
140+
The following sections contain more information about these changes.
146141

147142
### Constructor and JS Backwards-Compatibility Methods
148143

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.
150145

151146
Also removed the accessors and method that were only for JS backwards compatibility.
152147

@@ -252,7 +247,7 @@ Note these are not exact replacements:
252247

253248
#### `faker.helpers.replaceSymbolWithNumber`
254249

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
256251

257252
```ts
258253
// old
@@ -274,14 +269,14 @@ faker.helpers.replaceSymbolWithNumber('!#####'); // '123152'
274269

275270
#### `faker.helpers.regexpStyleStringParse`
276271

277-
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`.
278273

279274
```ts
280275
faker.helpers.regexpStyleStringParse('a{3,6}'); // aaaaa
281276
faker.helpers.fromRegExp('a{3,6}'); // aaaaa
282277
```
283278

284-
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.
285280

286281
```ts
287282
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/
294289

295290
Please see the [unique values guide](/guide/unique) for alternatives.
296291

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):
298293

299294
Basic example:
300295

@@ -351,7 +346,7 @@ const city = enforcer.enforce(faker.location.city, {
351346
```
352347

353348
::: 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.
355350
:::
356351

357352
### Image Module
@@ -376,9 +371,9 @@ Removed deprecated image methods
376371
| `faker.image.technics()` | `faker.image.urlLoremFlickr({ category: 'technics' })` or `faker.image.url()` |
377372
| `faker.image.transport()` | `faker.image.urlLoremFlickr({ category: 'transport' })` or `faker.image.url()` |
378373

379-
#### image providers
374+
#### Image Providers
380375

381-
Removed deprecated image providers from `faker.image`. They already returned broken image URLs anyways.
376+
Removed deprecated image providers from `faker.image`. They already returned broken image URLs anyway.
382377

383378
| old | replacement |
384379
| ------------------------------------------- | -------------------------------------------------------- |
@@ -476,7 +471,7 @@ Removed deprecated random module
476471

477472
### Locale Aliases
478473

479-
Removed deprecated locale aliases
474+
Renamed deprecated locale aliases `cz`, `en_IND`, `ge` and removed `global`.
480475

481476
| old | replacement |
482477
| ------------------------------------------------------- | ------------------------------------------------------ |
@@ -519,9 +514,9 @@ Removed deprecated type aliases
519514

520515
## Breaking Changes to Specific Methods
521516

522-
### Changed Default Mode from Birthdate
517+
### Birthdate New Default Mode
523518

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.
525520
Now, the method requires either none or all of the `min`, `max` and `mode` options.
526521

527522
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.
536531

537532
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()`.
538533

539-
### Prices now return more price-like values
534+
### Prices Now Return More Price-Like Values
540535

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.
542537

543538
Old price: 828.00
544539
New price: 828.59
545540

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:
547542

548543
- 50% of the time: `9`
549544
- 30% of the time: `5`
@@ -552,7 +547,7 @@ The last digit of the price will adjusted to be more price-like:
552547

553548
We plan to rethink this method some more in the future: [#2579](https://github.com/faker-js/faker/issues/2579)
554549

555-
### Randomized Image Option Defaults
550+
### Images Have Random Options by Default
556551

557552
`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}`.
558553

@@ -562,11 +557,11 @@ We plan to rethink this method some more in the future: [#2579](https://github.c
562557

563558
`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'}`.
564559

565-
### Require `from` and `to` in `faker.date.between()` and `betweens()`
560+
### Require `from` and `to` in `faker.date.between` and `betweens`
566561

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`.
568563

569-
### Stricter Checking for Function Signature passed to `faker.helpers.multiple` Method
564+
### Stricter Checking for Function Signature Passed to `faker.helpers.multiple` Method
570565

571566
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.
572567

@@ -608,7 +603,7 @@ faker.helpers.multiple((_, index) => ({ id: index, ...}), ...); // [{id: 0, ...}
608603
### Stricter Enum Value Usage
609604

610605
Some methods would previously fallback to a default value for an option when an unknown value was passed for a enum parameter.
611-
Now, these methods will return undefined instead.
606+
Now, these methods return undefined instead.
612607
This only affects usage in Javascript, as in Typescript this usage would already throw a compile-time error.
613608

614609
For example:
@@ -626,9 +621,9 @@ This affects:
626621
- The `variant` property of `faker.location.countryCode()` must be one of `alpha-2`, `alpha-3`, `numeric` if provided
627622
- The `casing` property of `faker.string.alpha()` and `faker.string.alphanumeric()` must be one of `'upper' | 'lower' | 'mixed'` if provided
628623

629-
### faker.phone.number `style` replaces explicit `format`
624+
### Phone Number `style` Replaces Explicit `format`
630625

631-
`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.
632627

633628
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:
634629

0 commit comments

Comments
 (0)