diff options
| author | Shinigami <[email protected]> | 2024-03-13 13:28:28 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-03-13 12:28:28 +0000 |
| commit | 1169a0576ba1469d7c05be0b8fd844bde8a1af13 (patch) | |
| tree | b04103c0476f48d9c8978907728f5e4a1f2a2b39 /docs | |
| parent | 1b1163e7bdeaf71f0352e8d642f29eabe4296c8f (diff) | |
| download | faker-1169a0576ba1469d7c05be0b8fd844bde8a1af13.tar.xz faker-1169a0576ba1469d7c05be0b8fd844bde8a1af13.zip | |
refactor(helpers)!: remove v8 deprecated helpers methods (#2729)
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/guide/upgrading_v9/2729.md | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/docs/guide/upgrading_v9/2729.md b/docs/guide/upgrading_v9/2729.md new file mode 100644 index 00000000..0e43183c --- /dev/null +++ b/docs/guide/upgrading_v9/2729.md @@ -0,0 +1,48 @@ +### Remove deprecated helpers methods + +Removed deprecated helpers methods + +| old | replacement | +| --------------------------------------- | -------------------------------------------------------------- | +| `faker.helpers.replaceSymbolWithNumber` | `string.replace(/#+/g, (m) => faker.string.numeric(m.length))` | +| `faker.helpers.regexpStyleStringParse` | `faker.helpers.fromRegExp` | + +Note these are not exact replacements: + +#### `faker.helpers.replaceSymbolWithNumber` + +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 + +```js +// old +faker.helpers.replaceSymbolWithNumber('#####-##'); // '04812-67' + +// new +'#####-##'.replace(/#+/g, (m) => faker.string.numeric(m.length)); + +// old +faker.helpers.replaceSymbolWithNumber('!#####'); // '123152' + +// new +'!#####' + .replace(/#+/g, (m) => faker.string.numeric(m.length)) + .replace(/!+/g, (m) => + faker.string.numeric({ length: m.length, exclude: ['0', '1'] }) + ); +``` + +#### `faker.helpers.regexpStyleStringParse` + +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`. + +```js +faker.helpers.regexpStyleStringParse('a{3,6}'); // aaaaa +faker.helpers.fromRegExp('a{3,6}'); // aaaaa +``` + +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. + +```js +faker.helpers.regexpStyleStringParse('a{3,6}[1-100]'); // "aaaa53", etc. +faker.helpers.fromRegExp('a{3,6}') + faker.number.int({ min: 1, max: 100 }); +``` |
