-
-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(helpers)!: remove v8 deprecated helpers methods (#2729)
- Loading branch information
1 parent
1b1163e
commit 1169a05
Showing
4 changed files
with
49 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters