diff options
| author | Shinigami <[email protected]> | 2025-07-04 20:23:30 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-07-04 18:23:30 +0000 |
| commit | 623d2741a4ca165596fad7fede2f850b6c08aa3a (patch) | |
| tree | c05531e1f25bea9201925c0342d22e9a50f8946f /src | |
| parent | 160960b79719e1298668a7ebba390b30b8de1080 (diff) | |
| download | faker-623d2741a4ca165596fad7fede2f850b6c08aa3a.tar.xz faker-623d2741a4ca165596fad7fede2f850b6c08aa3a.zip | |
refactor!: remove deprecations (#3553)
Diffstat (limited to 'src')
| -rw-r--r-- | src/faker.ts | 26 | ||||
| -rw-r--r-- | src/modules/date/index.ts | 27 | ||||
| -rw-r--r-- | src/modules/finance/index.ts | 166 | ||||
| -rw-r--r-- | src/modules/helpers/eval.ts | 24 | ||||
| -rw-r--r-- | src/modules/image/index.ts | 133 | ||||
| -rw-r--r-- | src/modules/internet/index.ts | 124 |
6 files changed, 4 insertions, 496 deletions
diff --git a/src/faker.ts b/src/faker.ts index d9e9905b..cac89a32 100644 --- a/src/faker.ts +++ b/src/faker.ts @@ -1,6 +1,5 @@ import type { LocaleDefinition, MetadataDefinition } from './definitions'; import { FakerError } from './errors/faker-error'; -import { deprecated } from './internal/deprecated'; import type { LocaleProxy } from './internal/locale-proxy'; import { createLocaleProxy } from './internal/locale-proxy'; import { AirlineModule } from './modules/airline'; @@ -18,11 +17,9 @@ import { HackerModule } from './modules/hacker'; import { HelpersModule } from './modules/helpers'; import { ImageModule } from './modules/image'; import { InternetModule } from './modules/internet'; -import type { LocationModule as AddressModule } from './modules/location'; import { LocationModule } from './modules/location'; import { LoremModule } from './modules/lorem'; import { MusicModule } from './modules/music'; -import type { PersonModule as NameModule } from './modules/person'; import { PersonModule } from './modules/person'; import { PhoneModule } from './modules/phone'; import { ScienceModule } from './modules/science'; @@ -87,29 +84,6 @@ export class Faker extends SimpleFaker { readonly vehicle: VehicleModule = new VehicleModule(this); readonly word: WordModule = new WordModule(this); - // Aliases - /** @deprecated Use {@link Faker#location} instead */ - get address(): AddressModule { - deprecated({ - deprecated: 'faker.address', - proposed: 'faker.location', - since: '8.0', - until: '10.0', - }); - return this.location; - } - - /** @deprecated Use {@link Faker#person} instead */ - get name(): NameModule { - deprecated({ - deprecated: 'faker.name', - proposed: 'faker.person', - since: '8.0', - until: '10.0', - }); - return this.person; - } - /** * Creates a new instance of Faker. * diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts index 65d4a7d9..f1225cdb 100644 --- a/src/modules/date/index.ts +++ b/src/modules/date/index.ts @@ -160,13 +160,6 @@ export class SimpleDateModule extends SimpleModuleBase { */ to: string | Date | number; }): Date { - // TODO @matthewmayer 2023-03-27: Consider removing in v10 as this check is only needed in JS - if (options == null || options.from == null || options.to == null) { - throw new FakerError( - 'Must pass an options object with `from` and `to` values.' - ); - } - const { from, to } = options; const fromMs = toDate(from, 'from').getTime(); @@ -234,13 +227,6 @@ export class SimpleDateModule extends SimpleModuleBase { max: number; }; }): Date[] { - // TODO @matthewmayer 2023-03-27: Consider removing in v10 as this check is only needed in JS - if (options == null || options.from == null || options.to == null) { - throw new FakerError( - 'Must pass an options object with `from` and `to` values.' - ); - } - const { from, to, count = 3 } = options; return this.faker.helpers .multiple(() => this.between({ from, to }), { count }) @@ -486,21 +472,8 @@ export class SimpleDateModule extends SimpleModuleBase { min = 18, max = 80, refDate: rawRefDate = this.faker.defaultRefDate(), - mode: originalMode, - min: originalMin, - max: originalMax, } = options; - // TODO @ST-DDT 2024-03-17: Remove check in v10 - const optionsSet = [originalMin, originalMax, originalMode].filter( - (x) => x != null - ).length; - if (optionsSet % 3 !== 0) { - throw new FakerError( - "The 'min', 'max', and 'mode' options must be set together." - ); - } - const refDate = toDate(rawRefDate); const refYear = refDate.getUTCFullYear(); diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index 414d07ee..9744ee6f 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -1,5 +1,4 @@ import { FakerError } from '../../errors/faker-error'; -import { deprecated } from '../../internal/deprecated'; import { ModuleBase } from '../../internal/module-base'; import type { BitcoinAddressFamilyType, BitcoinNetworkType } from './bitcoin'; import { @@ -207,171 +206,6 @@ export class FinanceModule extends ModuleBase { } /** - * Generates a random masked number. - * - * @param length The length of the unmasked number. Defaults to `4`. - * - * @example - * faker.finance.maskedNumber() // '(...9711)' - * faker.finance.maskedNumber(3) // '(...342)' - * - * @since 8.0.0 - * - * @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead. - */ - maskedNumber(length?: number): string; - /** - * Generates a random masked number. - * - * @param options An options object. - * @param options.length The length of the unmasked number. Defaults to `4`. - * @param options.parens Whether to use surrounding parenthesis. Defaults to `true`. - * @param options.ellipsis Whether to prefix the numbers with an ellipsis. Defaults to `true`. - * - * @example - * faker.finance.maskedNumber() // '(...9711)' - * faker.finance.maskedNumber({ length: 3 }) // '(...342)' - * faker.finance.maskedNumber({ length: 3, parens: false }) // '...236' - * faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298' - * - * @since 8.0.0 - * - * @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead. - */ - maskedNumber(options?: { - /** - * The length of the unmasked number. - * - * @default 4 - */ - length?: number; - /** - * Whether to use surrounding parenthesis. - * - * @default true - */ - parens?: boolean; - /** - * Whether to prefix the numbers with an ellipsis. - * - * @default true - */ - ellipsis?: boolean; - }): string; - /** - * Generates a random masked number. - * - * @param optionsOrLength An options object or the length of the unmask number. - * @param optionsOrLength.length The length of the unmasked number. Defaults to `4`. - * @param optionsOrLength.parens Whether to use surrounding parenthesis. Defaults to `true`. - * @param optionsOrLength.ellipsis Whether to prefix the numbers with an ellipsis. Defaults to `true`. - * - * @example - * faker.finance.maskedNumber() // '(...9711)' - * faker.finance.maskedNumber(3) // '(...342)' - * faker.finance.maskedNumber({ length: 3 }) // '(...342)' - * faker.finance.maskedNumber({ length: 3, parens: false }) // '...236' - * faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298' - * - * @since 8.0.0 - * - * @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead. - */ - maskedNumber( - optionsOrLength?: - | number - | { - /** - * The length of the unmasked number. - * - * @default 4 - */ - length?: number; - /** - * Whether to use surrounding parenthesis. - * - * @default true - */ - parens?: boolean; - /** - * Whether to prefix the numbers with an ellipsis. - * - * @default true - */ - ellipsis?: boolean; - } - ): string; - /** - * Generates a random masked number. - * - * @param options An options object. - * @param options.length The length of the unmasked number. Defaults to `4`. - * @param options.parens Whether to use surrounding parenthesis. Defaults to `true`. - * @param options.ellipsis Whether to prefix the numbers with an ellipsis. Defaults to `true`. - * - * @example - * faker.finance.maskedNumber() // '(...9711)' - * faker.finance.maskedNumber(3) // '(...342)' - * faker.finance.maskedNumber({ length: 3 }) // '(...342)' - * faker.finance.maskedNumber({ length: 3, parens: false }) // '...236' - * faker.finance.maskedNumber({ length: 3, parens: false, ellipsis: false }) // '298' - * - * @since 8.0.0 - * - * @deprecated Use `faker.finance.iban().replace(/(?<=.{4})\w(?=.{2})/g, '*')` or a similar approach instead. - */ - maskedNumber( - options: - | number - | { - /** - * The length of the unmasked number. - * - * @default 4 - */ - length?: number; - /** - * Whether to use surrounding parenthesis. - * - * @default true - */ - parens?: boolean; - /** - * Whether to prefix the numbers with an ellipsis. - * - * @default true - */ - ellipsis?: boolean; - } = {} - ): string { - deprecated({ - deprecated: 'faker.finance.maskedNumber()', - proposed: - "faker.finance.iban().replace(/(?<=.{4})\\w(?=.{2})/g, '*') or a similar approach", - since: '9.3.0', - until: '10.0.0', - }); - - if (typeof options === 'number') { - options = { length: options }; - } - - const { ellipsis = true, length = 4, parens = true } = options; - - let template = this.faker.string.numeric({ length }); - - if (ellipsis) { - template = `...${template}`; - } - - if (parens) { - template = `(${template})`; - } - - return template; - } - - /** * Generates a random amount between the given bounds (inclusive). * * @param options An options object. diff --git a/src/modules/helpers/eval.ts b/src/modules/helpers/eval.ts index e04575bc..739f5af8 100644 --- a/src/modules/helpers/eval.ts +++ b/src/modules/helpers/eval.ts @@ -81,7 +81,7 @@ export function fakeEval( do { let index: number; if (remaining.startsWith('(')) { - [index, current] = evalProcessFunction(remaining, current, expression); + [index, current] = evalProcessFunction(remaining, current); } else { [index, current] = evalProcessExpression(remaining, current); } @@ -109,12 +109,10 @@ export function fakeEval( * * @param input The input string to parse. * @param entrypoints The entrypoints to attempt the call on. - * @param expression The full expression to use in errors. */ function evalProcessFunction( input: string, - entrypoints: ReadonlyArray<unknown>, - expression: string + entrypoints: ReadonlyArray<unknown> ): [continueIndex: number, mapped: unknown[]] { const [index, params] = findParams(input); const nextChar = input[index + 1]; @@ -135,23 +133,7 @@ function evalProcessFunction( return [ index + (nextChar === '.' ? 2 : 1), // one for the closing bracket, one for the dot entrypoints.map((entrypoint): unknown => - // TODO @ST-DDT 2023-12-11: Replace in v10 - // typeof entrypoint === 'function' ? entrypoint(...params) : undefined - { - if (typeof entrypoint === 'function') { - return entrypoint(...params); - } - - // eslint-disable-next-line no-undef - console.warn( - `[@faker-js/faker]: Invoking expressions which are not functions is deprecated since v9.0 and will be removed in v10.0. -Please remove the parentheses or replace the expression with an actual function. -${expression} -${' '.repeat(expression.length - input.length)}^` - ); - - return entrypoint; - } + typeof entrypoint === 'function' ? entrypoint(...params) : undefined ), ]; } diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts index ae4d76fe..61442dfe 100644 --- a/src/modules/image/index.ts +++ b/src/modules/image/index.ts @@ -1,5 +1,4 @@ import { toBase64 } from '../../internal/base64'; -import { deprecated } from '../../internal/deprecated'; import { ModuleBase } from '../../internal/module-base'; import type { SexType } from '../person'; @@ -10,7 +9,7 @@ import type { SexType } from '../person'; * * For a random image, use [`url()`](https://fakerjs.dev/api/image.html#url). This will not return the image directly but a URL pointing to an image from one of two demo image providers "Picsum" and "LoremFlickr". You can request an image specifically from one of two providers using [`urlLoremFlickr()`](https://fakerjs.dev/api/image.html#urlloremflickr) or [`urlPicsumPhotos()`](https://fakerjs.dev/api/image.html#urlpicsumphotos). * - * For a random placeholder image containing only solid color and text, use [`urlPlaceholder()`](https://fakerjs.dev/api/image.html#urlplaceholder) (uses a third-party service) or [`dataUri()`](https://fakerjs.dev/api/image.html#datauri) (returns a SVG string). + * For a random placeholder image containing only solid color and text, use [`dataUri()`](https://fakerjs.dev/api/image.html#datauri) (returns a SVG string). * * For a random user avatar image, use [`avatar()`](https://fakerjs.dev/api/image.html#avatar), or [`personPortrait()`](https://fakerjs.dev/api/image.html#personportrait) which has more control over the size and sex of the person. * @@ -94,32 +93,6 @@ export class ImageModule extends ModuleBase { } /** - * Generates a random avatar from `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar`. - * - * @remark This method generates a random string representing an URL from cloudflare-ipfs. Faker is not responsible for the content of the image or the service providing it. - * - * @example - * faker.image.avatarLegacy() - * // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/170.jpg' - * - * @since 8.0.0 - * - * @deprecated The links are no longer working. Use `avatar()` instead. - */ - avatarLegacy(): string { - deprecated({ - deprecated: 'faker.image.avatarLegacy()', - proposed: 'faker.image.avatar() or faker.image.personPortrait()', - since: '9.0.2', - until: '10.0.0', - }); - - return `https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/${this.faker.number.int( - 1249 - )}.jpg`; - } - - /** * Generates a random image url. * * @remark This method generates a random string representing an URL from loremflickr. Faker is not responsible for the content of the image or the service providing it. @@ -294,110 +267,6 @@ export class ImageModule extends ModuleBase { } /** - * Generates a random image url provided via https://via.placeholder.com/. - * - * @remark This method generates a random string representing an URL from via.placeholder. Faker is not responsible for the content of the image or the service providing it. - * - * @param options Options for generating a URL for an image. - * @param options.width The width of the image. Defaults to a random number between 1 and 3500. - * @param options.height The height of the image. Defaults to a random number between 1 and 3500. - * @param options.backgroundColor The background color of the image. Defaults to a random hex color. - * @param options.textColor The text color of the image. Defaults to a random hex color. - * @param options.format The format of the image. Defaults to a random format. - * @param options.text The text to display on the image. Defaults to a random string. - * - * @example - * faker.image.urlPlaceholder() // 'https://via.placeholder.com/150x180/FF0000/FFFFFF.webp?text=lorem' - * faker.image.urlPlaceholder({ width: 128 }) // 'https://via.placeholder.com/128x180/FF0000/FFFFFF.webp?text=lorem' - * faker.image.urlPlaceholder({ height: 128 }) // 'https://via.placeholder.com/150x128/FF0000/FFFFFF.webp?text=lorem' - * faker.image.urlPlaceholder({ backgroundColor: '000000' }) // 'https://via.placeholder.com/150x180/000000/FFFFFF.webp?text=lorem' - * faker.image.urlPlaceholder({ textColor: '000000' }) // 'https://via.placeholder.com/150x180/FF0000/000000.webp?text=lorem' - * faker.image.urlPlaceholder({ format: 'png' }) // 'https://via.placeholder.com/150x180/FF0000/FFFFFF.png?text=lorem' - * faker.image.urlPlaceholder({ text: 'lorem ipsum' }) // 'https://via.placeholder.com/150x180/FF0000/FFFFFF.webp?text=lorem+ipsum' - * faker.image.urlPlaceholder({ width: 128, height: 128, backgroundColor: '000000', textColor: 'FF0000', format: 'png', text: 'lorem ipsum' }) // 'https://via.placeholder.com/128x128/000000/FF0000.png?text=lorem+ipsum' - * - * @since 8.0.0 - * - * @deprecated The service has bad uptime. Use `faker.image.url()` or `faker.image.dataUri()` instead. - */ - urlPlaceholder( - options: { - /** - * The width of the image. - * - * @default faker.number.int({ min: 1, max: 3500 }) - */ - width?: number; - /** - * The height of the image. - * - * @default faker.number.int({ min: 1, max: 3500 }) - */ - height?: number; - /** - * The background color of the image. - * - * @default faker.color.rgb({ format: 'hex', prefix: '' }) - */ - backgroundColor?: string; - /** - * The text color of the image. - * - * @default faker.color.rgb({ format: 'hex', prefix: '' }) - */ - textColor?: string; - /** - * The format of the image. - * - * @default faker.helpers.arrayElement(['gif', 'jpeg', 'jpg', 'png', 'webp']) - */ - format?: 'gif' | 'jpeg' | 'jpg' | 'png' | 'webp'; - /** - * The text to display on the image. - * - * @default faker.lorem.words() - */ - text?: string; - } = {} - ): string { - deprecated({ - deprecated: 'faker.image.urlPlaceholder()', - proposed: 'faker.image.url() or faker.image.dataUri()', - since: '9.4.0', - until: '10.0.0', - }); - - const { - width = this.faker.number.int({ min: 1, max: 3500 }), - height = this.faker.number.int({ min: 1, max: 3500 }), - backgroundColor = this.faker.color.rgb({ format: 'hex', prefix: '' }), - textColor = this.faker.color.rgb({ format: 'hex', prefix: '' }), - format = this.faker.helpers.arrayElement([ - 'gif', - 'jpeg', - 'jpg', - 'png', - 'webp', - ]), - text = this.faker.lorem.words(), - } = options; - - let url = `https://via.placeholder.com`; - - url += `/${width}`; - url += `x${height}`; - - url += `/${backgroundColor}`; - url += `/${textColor}`; - - url += `.${format}`; - - url += `?text=${encodeURIComponent(text)}`; - - return url; - } - - /** * Generates a random data uri containing an URL-encoded SVG image or a Base64-encoded SVG image. * * @param options Options for generating a data uri. diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index afad6d39..2afdef39 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -1,7 +1,6 @@ import { FakerError } from '../../errors/faker-error'; import type { Faker } from '../../faker'; import { toBase64Url } from '../../internal/base64'; -import { deprecated } from '../../internal/deprecated'; import { ModuleBase } from '../../internal/module-base'; import { charMapping } from './char-mappings'; @@ -135,18 +134,6 @@ function makeValidDomainWordSlug(faker: Faker, word: string): string { } /** - * Generates a random color in hex format with the given base color. - * - * @param faker The faker instance to use. - * @param base The base color to use. - */ -function colorFromBase(faker: Faker, base: number): string { - return Math.floor((faker.number.int(256) + base) / 2) - .toString(16) - .padStart(2, '0'); -} - -/** * Module to generate internet related entries. * * ### Overview @@ -309,58 +296,6 @@ export class InternetModule extends ModuleBase { * @see faker.internet.displayName(): For generating an Unicode display name. * * @example - * faker.internet.userName() // 'Nettie_Zboncak40' - * faker.internet.userName({ firstName: 'Jeanne' }) // 'Jeanne98' - * faker.internet.userName({ firstName: 'Jeanne' }) // 'Jeanne.Smith98' - * faker.internet.userName({ firstName: 'Jeanne', lastName: 'Doe'}) // 'Jeanne_Doe98' - * faker.internet.userName({ firstName: 'John', lastName: 'Doe' }) // 'John.Doe' - * faker.internet.userName({ firstName: 'Hélene', lastName: 'Müller' }) // 'Helene_Muller11' - * faker.internet.userName({ firstName: 'Фёдор', lastName: 'Достоевский' }) // 'Fedor.Dostoevskii50' - * faker.internet.userName({ firstName: '大羽', lastName: '陳' }) // 'hlzp8d.tpv45' - note neither name is used - * - * @since 2.0.1 - * - * @deprecated Use `faker.internet.username()` instead. - */ - userName( - options: { - /** - * The optional first name to use. - * - * @default faker.person.firstName() - */ - firstName?: string; - /** - * The optional last name to use. - * - * @default faker.person.lastName() - */ - lastName?: string; - } = {} - ): string { - deprecated({ - deprecated: 'faker.internet.userName()', - proposed: 'faker.internet.username()', - since: '9.1.0', - until: '10.0.0', - }); - - return this.username(options); - } - - /** - * Generates a username using the given person's name as base. - * The resulting username may use neither, one or both of the names provided. - * This will always return a plain ASCII string. - * Some basic stripping of accents and transliteration of characters will be done. - * - * @param options An options object. - * @param options.firstName The optional first name to use. If not specified, a random one will be chosen. - * @param options.lastName The optional last name to use. If not specified, a random one will be chosen. - * - * @see faker.internet.displayName(): For generating an Unicode display name. - * - * @example * faker.internet.username() // 'Nettie_Zboncak40' * faker.internet.username({ firstName: 'Jeanne' }) // 'Jeanne98' * faker.internet.username({ firstName: 'Jeanne' }) // 'Jeanne.Smith98' @@ -807,65 +742,6 @@ export class InternetModule extends ModuleBase { } /** - * Generates a random css hex color code in aesthetically pleasing color palette. - * - * Based on - * http://stackoverflow.com/questions/43044/algorithm-to-randomly-generate-an-aesthetically-pleasing-color-palette - * - * @param options An options object. - * @param options.redBase The optional base red in range between `0` and `255`. Defaults to `0`. - * @param options.greenBase The optional base green in range between `0` and `255`. Defaults to `0`. - * @param options.blueBase The optional base blue in range between `0` and `255`. Defaults to `0`. - * - * @see faker.color.rgb(): For generating a random RGB color. - * - * @example - * faker.internet.color() // '#30686e' - * faker.internet.color({ redBase: 100, greenBase: 100, blueBase: 100 }) // '#4e5f8b' - * - * @since 2.0.1 - * - * @deprecated Please use faker.color.rgb() or any of the other color methods instead. - */ - color( - options: { - /** - * The optional base red in range between `0` and `255`. - * - * @default 0 - */ - redBase?: number; - /** - * The optional base green in range between `0` and `255`. - * - * @default 0 - */ - greenBase?: number; - /** - * The optional base blue in range between `0` and `255`. - * - * @default 0 - */ - blueBase?: number; - } = {} - ): string { - deprecated({ - deprecated: 'faker.internet.color()', - proposed: 'faker.color.rgb()', - since: '9.6.0', - until: '10.0.0', - }); - - const { redBase = 0, greenBase = 0, blueBase = 0 } = options; - - const red = colorFromBase(this.faker, redBase); - const green = colorFromBase(this.faker, greenBase); - const blue = colorFromBase(this.faker, blueBase); - - return `#${red}${green}${blue}`; - } - - /** * Generates a random mac address. * * @param options An options object. |
