faker
faker copied to clipboard
refactor!: remove v8 deprecations
Remove all v8 deprecations
we might need to split this PR into several smaller PRs, until this PR itself is small enough
Uncommitted changes were detected after runnning generate:*
commands.
Please run pnpm run preflight
to generate/update the related files, and commit them.
For reference for the migration guide, these are the completely removed methods:
(WIP, once this is finished we can add to the migration guide)
Deprecated methods removed
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.
old | replacement |
---|---|
faker.company.bs() |
faker.company.buzzPhrase() |
faker.company.bsAdjective() |
faker.company.buzzAdjective() |
faker.company.bsBuzz() |
faker.company.buzzVerb() |
faker.company.bsNoun() |
faker.company.buzzNoun() |
faker.company.companySuffix() |
faker.company.name - not an exact replacement |
faker.company.suffixes() |
faker.company.name - not an exact replacement |
faker.datatype.array() |
No direct replacement |
faker.datatype.bigInt() |
faker.number.bigInt() |
faker.datatype.datetime() |
faker.date.between({ from: min, to: max }) or faker.date.anytime() |
faker.datatype.float() |
faker.number.float() |
faker.datatype.hexadecimal() |
faker.string.hexadecimal() or faker.number.hex() |
faker.datatype.json() |
No direct replacement |
faker.datatype.number() |
faker.number.int() or faker.number.float() |
faker.datatype.string() |
faker.string.sample() |
faker.datatype.uuid() |
faker.string.uuid() |
faker.finance.account() |
faker.finance.accountNumber() |
faker.finance.mask() |
faker.finance.maskedNumber() |
faker.git.shortSha() |
faker.git.commitSha({ length: 7 }) |
faker.helpers.regexpStyleStringParse() |
faker.helpers.fromRegExp() - not an exact replacement |
faker.helpers.replaceSymbolWithNumber() |
No direct replacement |
faker.helpers.unique() |
No direct replacement |
faker.image.abstract() |
faker.image.urlLoremFlickr({category:'abstract'}) |
faker.image.animals() |
faker.image.urlLoremFlickr({category:'animals'}) |
faker.image.business() |
faker.image.urlLoremFlickr({category:'business'}) |
faker.image.cats() |
faker.image.urlLoremFlickr({category:'cats'}) |
faker.image.city() |
faker.image.urlLoremFlickr({category:'city'}) |
faker.image.fashion() |
faker.image.urlLoremFlickr({category:'fashion'}) |
faker.image.food() |
faker.image.urlLoremFlickr({category:'food'}) |
faker.image.image() |
faker.image.url() |
faker.image.imageUrl() |
faker.image.url() |
faker.image.lorempicsum() |
Provider no longer available, use faker.image.url() |
faker.image.nature() |
faker.image.urlLoremFlickr({category:'nature'}) |
faker.image.nightlife() |
faker.image.urlLoremFlickr({category:'nightlife'}) |
faker.image.people() |
faker.image.urlLoremFlickr({category:'people'}) |
faker.image.placeholder() |
faker.image.urlPlaceholder |
faker.image.sports() |
faker.image.urlLoremFlickr({category:'sports'}) |
faker.image.technics() |
faker.image.urlLoremFlickr({category:'technics'}) |
faker.image.transport() |
faker.image.urlLoremFlickr({category:'transport'}) |
faker.image.unsplash() |
Provider no longer available, use faker.image.url() |
faker.internet.avatar() |
faker.image.avatarLegacy() or faker.image.avatar() |
faker.location.cityName() |
faker.location.city() |
faker.location.stateAbbr() |
faker.location.state({ abbreviated: true }) |
faker.location.streetName() |
faker.location.street() |
faker.location.zipCodeByState() |
faker.location.zipCode({ state }) |
faker.random.alpha() |
faker.string.alpha() |
faker.random.alphaNumeric() |
faker.string.alphanumeric() |
faker.random.locale() |
faker.helpers.objectKey(allLocales/allFakers) |
faker.random.numeric() |
faker.string.numeric() |
faker.random.word() |
faker.lorem.word() or faker.word.sample() |
faker.random.words() |
faker.lorem.words() or faker.word.words() |
Changes to method signatures
Many methods that previously took multiple parameters now use a single parameter with an options object. For example
//old
faker.commerce.price(100, 200, 0, '$')
//new
faker.commerce.price({min: 100, max: 200, dec: 0, symbol: '$'}
old | replacement |
---|---|
faker.commerce.price(min, max, dec, symbol) |
faker.commerce.price({ min, max, dec, symbol}) |
faker.date.between(from, to) |
faker.date.between({ from: min, to: max }) |
faker.date.past(years, refDate) |
faker.date.past({ years, refDate }) |
faker.date.future(years, refDate) |
faker.date.future({ years, refDate }) |
faker.date.between(from, to) |
faker.date.between({ from, to }) |
faker.date.betweens(from, to, count) |
faker.date.betweens({ from, to, count }) |
faker.date.recent(days, refDate) |
faker.date.recent({ days, refDate }) |
faker.date.soon(days, refDate) |
faker.date.soon({ days, refDate }) |
faker.finance.amount(min, max, dec, symbol, autoFormat) |
faker.finance.amount({ min, max, dec, symbol, autoFormat }) |
faker.finance.iban(formatted, countryCode) |
faker.finance.iban({ formatted, countryCode }) |
faker.git.commitSha(length) |
faker.git.commitSha({ length }) |
faker.internet.email(firstName, lastName, provider) |
faker.internet.email({ firstName, lastName, provider }) |
faker.internet.exampleEmail(firstName, lastName) |
faker.internet.exampleEmail({ firstName: lastName }) |
faker.internet.userName(firstName, lastName) |
faker.internet.userName({ firstName, lastName }) |
faker.internet.displayName(firstName, lastName) |
faker.internet.displayName({ firstName, lastName }) |
faker.internet.color(redBase, greenBase, blueBase) |
faker.internet.color({ redBase, greenBase, blueBase }) |
faker.internet.password(length, memorable, pattern, prefix) |
faker.internet.password({ length, memorable, pattern, prefix }) |
faker.location.zipCode(state) |
faker.location.zipCode({ state }) |
faker.location.direction(abbreviated) |
faker.location.direction({ abbreviated }) |
faker.location.cardinalDirection(abbreviated) |
faker.location.cardinalDirection({ abbreviated }) |
faker.location.latitude({ max, min, precision }) |
faker.location.latitude({ max, min, precision }) |
faker.location.longitude(max, min, precision) |
faker.location.longitude({ max, min, precision }) |
faker.location.ordinalDirection(abbreviated) |
faker.location.ordinalDirection({ abbreviated }) |
faker.location.nearbyGPSCoordinate(origin, radius, isMetric) |
faker.location.nearbyGPSCoordinate({ origin, radius, isMetric }) |
Other parameters renamed or removed
old | replacement |
---|---|
faker.date.month({ abbr }) |
faker.date.month({ abbreviated }) |
faker.date.weekday({ abbr }) |
faker.date.weekday({ abbreviated }) |
faker.number.float({ precision }) |
faker.number.float({ multipleOf }) |
faker.phone.number({ format }) |
No direct replacement |
Old constructions for Faker removed
Some old constructors for the Faker were removed. In most cases you should use one of the prebuilt Faker instances instead of the constructor, for example fakerDE
, fakerFR
. For more details see https://fakerjs.dev/api/faker.html#constructor
i think there might be logic in not removing the faker.phone.number({ format }) method in this initial commit until a good replacement (e.g. #2578 ) is merged?
i think there might be logic in not removing the faker.phone.number({ format }) method in this initial commit until a good replacement (e.g. #2578 ) is merged?
🤔 Mhh. I think having the alternative suggestions like the @see faker.helpers.fromRegexp
is enough.
Please note that the format parameter has to be removed before release v9.0 if we plan to add the new parameters in v9.x.
My initial draft for the migration guide is done, https://github.com/faker-js/faker/pull/2608#issuecomment-1901742274 when you have a chance you can add that initial text to docs/guide/upgrading_v9/2608.md
My initial draft for the migration guide is done, #2608 (comment) when you have a chance you can add that initial text to
docs/guide/upgrading_v9/2608.md
We might plan to split this PR into several smaller PRs. Like e.g. remove the image provider in one PR.
Sure no hurry then
Do you need/want help?
Do you need/want help?
Mh, mostly with the new upgrading/*.md
files, but I thing that will be solved in todays evening meeting.
I would like to potential go through the deprecation removals by module or/and by specific things (like image-providers and unique)
Maybe we could e.g. also bundle all whole-file-removals into one PR (I see test/modules/random.spec.ts
in the conflicts right now 👀)
At the end, try to do steps that are not get in conflict with each other 🙂 And then maybe we could structure it if wanted with a task-list, to enable parallel working
While I think there are a few special cases that need their own PRs like unique and the image providers, I think it's fine if most of the standard removals of deprecated methods is done in a single big PR. It's not too hard to review removals.
This PR is too big and to confusing to review Also finding the test-errors in all the mess is cumbersome
I will close this PR and we will do PRs for every module on its own