diff --git a/docs/.vitepress/api-pages.ts b/docs/.vitepress/api-pages.ts index 88f6c48edfc..ff4ccece630 100644 --- a/docs/.vitepress/api-pages.ts +++ b/docs/.vitepress/api-pages.ts @@ -23,7 +23,6 @@ export const apiPages = [ { text: 'Phone', link: '/api/phone.html' }, { text: 'Random', link: '/api/random.html' }, { text: 'System', link: '/api/system.html' }, - { text: 'Time', link: '/api/time.html' }, { text: 'Unique', link: '/api/unique.html' }, { text: 'Vehicle', link: '/api/vehicle.html' }, { text: 'Word', link: '/api/word.html' }, diff --git a/docs/guide/index.md b/docs/guide/index.md index 61fe9a3dc61..18bd257c0f8 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -46,7 +46,6 @@ import { faker } from '@faker-js/faker'; const randomName = faker.name.findName(); // Rowan Nikolaus const randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz -const randomCard = faker.helpers.createCard(); // An object representing a random contact card containing many properties ``` ### Browser @@ -60,10 +59,6 @@ const randomCard = faker.helpers.createCard(); // An object representing a rando // Rusty@arne.info const randomEmail = faker.internet.email(); - - // An object representing a random contact card - // containing many properties - const randomCard = faker.helpers.createCard(); ``` @@ -78,7 +73,6 @@ import { faker } from 'https://cdn.skypack.dev/@faker-js/faker'; const randomName = faker.name.findName(); // Willie Bahringer const randomEmail = faker.internet.email(); // Tomasa_Ferry14@hotmail.com -const randomCard = faker.helpers.createCard(); // random contact card containing many properties ``` :::tip Note diff --git a/src/faker.ts b/src/faker.ts index e9fa978e5e3..3a7962c8fd0 100644 --- a/src/faker.ts +++ b/src/faker.ts @@ -1,6 +1,5 @@ import type { LocaleDefinition } from './definitions'; import { FakerError } from './errors/faker-error'; -import { deprecated } from './internal/deprecated'; import type { KnownLocale } from './locales'; import { Address } from './modules/address'; import { Animal } from './modules/animal'; @@ -23,7 +22,6 @@ import { Name } from './modules/name'; import { Phone } from './modules/phone'; import { Random } from './modules/random'; import { System } from './modules/system'; -import { Time } from './modules/time'; import { Unique } from './modules/unique'; import { Vehicle } from './modules/vehicle'; import { Word } from './modules/word'; @@ -50,8 +48,6 @@ export class Faker { readonly definitions: LocaleDefinition = this.initDefinitions(); - private _seedValue: number | number[]; - readonly fake: Fake['fake'] = new Fake(this).fake; readonly unique: Unique['unique'] = new Unique().unique; @@ -78,7 +74,6 @@ export class Faker { readonly name: Name = new Name(this); readonly phone: Phone = new Phone(this); readonly system: System = new System(this); - readonly time: Time = new Time(); readonly vehicle: Vehicle = new Vehicle(this); readonly word: Word = new Word(this); @@ -100,24 +95,6 @@ export class Faker { this.localeFallback = opts.localeFallback || 'en'; } - /** - * The seed that was last set. - * Please note that generated values are dependent on both the seed and the number of calls that have been made since it was set. - * - * Use the `seed` function to set a new seed. - * - * @deprecated Use the return value of `faker.seed()` instead. - */ - public get seedValue(): number | number[] { - deprecated({ - deprecated: 'faker.seedValue', - proposed: 'return value of faker.seed()', - since: '6.3.0', - until: '7.0.0', - }); - return this._seedValue; - } - /** * Creates a Proxy based LocaleDefinition that virtually merges the locales. */ @@ -235,7 +212,6 @@ export class Faker { seed( seed: number | number[] = Math.ceil(Math.random() * Number.MAX_SAFE_INTEGER) ): number | number[] { - this._seedValue = seed; if (Array.isArray(seed) && seed.length) { this.mersenne.seed_array(seed); } else if (!Array.isArray(seed) && !isNaN(seed)) { diff --git a/src/modules/datatype/index.ts b/src/modules/datatype/index.ts index 653d4d3fe95..a81a9681b33 100644 --- a/src/modules/datatype/index.ts +++ b/src/modules/datatype/index.ts @@ -1,6 +1,5 @@ import type { Faker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { deprecated } from '../../internal/deprecated'; /** * Module to generate various primitive values and data types. @@ -185,30 +184,6 @@ export class Datatype { return !!this.number(1); } - /** - * Returns a [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) number. - * - * @param length Length of the generated number. Defaults to `1`. - * - * @see faker.datatype.hexadecimal() - * - * @example - * faker.datatype.hexaDecimal() // '0xb' - * faker.datatype.hexaDecimal(10) // '0xaE13F044fb' - * - * @deprecated - */ - hexaDecimal(length = 1): string { - deprecated({ - deprecated: 'faker.datatype.hexaDecimal()', - proposed: 'faker.datatype.hexadecimal()', - since: 'v6.1.2', - until: 'v7.0.0', - }); - - return this.hexadecimal(length); - } - /** * Returns a [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) number. * diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index a74dceba4da..e73f7225965 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -423,11 +423,10 @@ export class Finance { * // 'invoice transaction at Kilback - Durgan using card ending with ***(...4316) for UAH 783.82 in account ***16168663' */ transactionDescription(): string { - const transaction = this.faker.helpers.createTransaction(); - const account = transaction.account; - const amount = transaction.amount; - const transactionType = transaction.type; - const company = transaction.business; + const amount = this.amount(); + const company = this.faker.company.companyName(); + const transactionType = this.transactionType(); + const account = this.account(); const card = this.mask(); const currency = this.currencyCode(); diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 7f056b9f3e0..386bcce89eb 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -1,115 +1,4 @@ import type { Faker } from '../..'; -import { deprecated } from '../../internal/deprecated'; - -/** - * A full card with various details. - */ -export interface Card { - name: string; - username: string; - email: string; - address: { - streetA: string; - streetB: string; - streetC: string; - streetD: string; - city: string; - state: string; - country: string; - zipcode: string; - geo: { - lat: string; - lng: string; - }; - }; - phone: string; - website: string; - company: { - name: string; - catchPhrase: string; - bs: string; - }; - posts: Array<{ - words: string; - sentence: string; - sentences: string; - paragraph: string; - }>; - accountHistory: Array<{ - amount: string; - date: Date; - business: string; - name: string; - type: string; - account: string; - }>; -} - -/** - * A persons card with various details attempting to use a consistent context. - */ -export interface ContextualCard { - name: string; - username: string; - avatar: string; - email: string; - dob: Date; - phone: string; - address: { - street: string; - suite: string; - city: string; - zipcode: string; - geo: { - lat: string; - lng: string; - }; - }; - website: string; - company: { - name: string; - catchPhrase: string; - bs: string; - }; -} - -/** - * A user card with various details. - */ -export interface UserCard { - name: string; - username: string; - email: string; - address: { - street: string; - suite: string; - city: string; - zipcode: string; - geo: { - lat: string; - lng: string; - }; - }; - phone: string; - website: string; - company: { - name: string; - catchPhrase: string; - bs: string; - }; -} - -/** - * A transaction info. - */ -export interface Transaction { - amount: string; - date: Date; - business: string; - name: string; - type: string; - account: string; -} /** * Module with various helper methods that transform the method input rather than returning values from locales. @@ -126,34 +15,6 @@ export class Helpers { } } - /** - * Backward-compatibility. Use `faker.helpers.arrayElement()` instead. - * - * Takes an array and returns a random element of the array. - * - * @template T The type of the entries to pick from. - * @param array The array to select an element from. - * - * @see faker.helpers.arrayElement() - * - * @example - * faker.helpers.randomize() // 'c' - * faker.helpers.randomize([1, 2, 3]) // '2' - * - * @deprecated - */ - randomize( - array: ReadonlyArray = ['a', 'b', 'c'] as unknown as ReadonlyArray - ): T { - deprecated({ - deprecated: 'faker.helpers.randomize()', - proposed: 'faker.helpers.arrayElement()', - // since: 'v5.0.0', (?) - until: 'v7.0.0', - }); - return this.arrayElement(array); - } - /** * Slugifies the given string. * For that all spaces (` `) are replaced by hyphens (`-`) @@ -493,204 +354,6 @@ export class Helpers { return str; } - /** - * Generates a full card with various random details. - * - * @example - * faker.helpers.createCard() - * // { - * // name: 'Maxine Abbott', - * // username: 'Idell_Kautzer60', - * // email: 'Nora_Bruen@hotmail.com', - * // address: { - * // streetA: 'Drake Avenue', - * // ... - * @deprecated If you need some specific object you should create your own method. - */ - createCard(): Card { - deprecated({ - deprecated: 'helpers.createCard()', - proposed: 'a self-build function', - since: 'v6.1.0', - until: 'v7.0.0', - }); - return { - name: this.faker.name.findName(), - username: this.faker.internet.userName(), - email: this.faker.internet.email(), - address: { - streetA: this.faker.address.streetName(), - streetB: this.faker.address.streetAddress(), - streetC: this.faker.address.streetAddress(true), - streetD: this.faker.address.secondaryAddress(), - city: this.faker.address.city(), - state: this.faker.address.state(), - country: this.faker.address.country(), - zipcode: this.faker.address.zipCode(), - geo: { - lat: this.faker.address.latitude(), - lng: this.faker.address.longitude(), - }, - }, - phone: this.faker.phone.phoneNumber(), - website: this.faker.internet.domainName(), - company: { - name: this.faker.company.companyName(), - catchPhrase: this.faker.company.catchPhrase(), - bs: this.faker.company.bs(), - }, - posts: [ - { - words: this.faker.lorem.words(), - sentence: this.faker.lorem.sentence(), - sentences: this.faker.lorem.sentences(), - paragraph: this.faker.lorem.paragraph(), - }, - { - words: this.faker.lorem.words(), - sentence: this.faker.lorem.sentence(), - sentences: this.faker.lorem.sentences(), - paragraph: this.faker.lorem.paragraph(), - }, - { - words: this.faker.lorem.words(), - sentence: this.faker.lorem.sentence(), - sentences: this.faker.lorem.sentences(), - paragraph: this.faker.lorem.paragraph(), - }, - ], - accountHistory: [ - this.createTransaction(), - this.createTransaction(), - this.createTransaction(), - ], - }; - } - - /** - * Generates a persons card with various details attempting to use a consistent context. - * - * @example - * faker.helpers.contextualCard() - * // { - * // name: 'Eveline', - * // username: 'Eveline.Brekke56', - * // avatar: 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/122.jpg', - * // email: 'Eveline.Brekke56.Hoppe@yahoo.com', - * // dob: 1964-05-06T05:14:37.874Z, - * // ... - * @deprecated If you need some specific object you should create your own method. - */ - contextualCard(): ContextualCard { - deprecated({ - deprecated: 'helpers.contextualCard()', - proposed: 'a self-build function', - since: 'v6.1.0', - until: 'v7.0.0', - }); - const name = this.faker.name.firstName(); - const userName = this.faker.internet.userName(name); - return { - name: name, - username: userName, - avatar: this.faker.internet.avatar(), - email: this.faker.internet.email(userName), - dob: this.faker.date.past( - 50, - new Date('Sat Sep 20 1992 21:35:02 GMT+0200 (CEST)') - ), - phone: this.faker.phone.phoneNumber(), - address: { - street: this.faker.address.streetName(), - suite: this.faker.address.secondaryAddress(), - city: this.faker.address.city(), - zipcode: this.faker.address.zipCode(), - geo: { - lat: this.faker.address.latitude(), - lng: this.faker.address.longitude(), - }, - }, - website: this.faker.internet.domainName(), - company: { - name: this.faker.company.companyName(), - catchPhrase: this.faker.company.catchPhrase(), - bs: this.faker.company.bs(), - }, - }; - } - - /** - * Generates a user card with various details. - * - * @example - * faker.helpers.userCard() - * // { - * // name: 'Jodi Ferry', - * // username: 'Maybell.Kris', - * // email: 'Zoey_Lubowitz@yahoo.com', - * // address: { - * // street: 'McKenzie Estates', - * // .... - * @deprecated If you need some specific object you should create your own method. - */ - userCard(): UserCard { - deprecated({ - deprecated: 'helpers.userCard()', - proposed: 'a self-build function', - since: 'v6.1.0', - until: 'v7.0.0', - }); - return { - name: this.faker.name.findName(), - username: this.faker.internet.userName(), - email: this.faker.internet.email(), - address: { - street: this.faker.address.streetName(), - suite: this.faker.address.secondaryAddress(), - city: this.faker.address.city(), - zipcode: this.faker.address.zipCode(), - geo: { - lat: this.faker.address.latitude(), - lng: this.faker.address.longitude(), - }, - }, - phone: this.faker.phone.phoneNumber(), - website: this.faker.internet.domainName(), - company: { - name: this.faker.company.companyName(), - catchPhrase: this.faker.company.catchPhrase(), - bs: this.faker.company.bs(), - }, - }; - } - - /** - * Generates an example transaction. - * - * @example - * faker.helpers.createTransaction() - * // { - * // amount: '551.32', - * // date: 2012-02-01T23:00:00.000Z, - * // business: 'Will, Fisher and Marks', - * // name: 'Investment Account (...8755)', - * // type: 'invoice', - * // account: '41796240' - * // } - */ - createTransaction(): Transaction { - return { - amount: this.faker.finance.amount(), - date: new Date(2012, 1, 2), // TODO: add a ranged date method - business: this.faker.company.companyName(), - name: [this.faker.finance.accountName(), this.faker.finance.mask()].join( - ' ' - ), - type: this.arrayElement(this.faker.definitions.finance.transaction_type), - account: this.faker.finance.account(), - }; - } - /** * Returns the result of the callback if the probability check was successful, otherwise `undefined`. * diff --git a/src/modules/name/index.ts b/src/modules/name/index.ts index c1ac22a75eb..f1d357e7277 100644 --- a/src/modules/name/index.ts +++ b/src/modules/name/index.ts @@ -1,41 +1,11 @@ import type { Faker } from '../..'; -import { deprecated } from '../../internal/deprecated'; export enum Gender { female = 'female', male = 'male', } -// TODO @Shinigami92 2022-03-21: Remove 0 and 1 in v7 -export type GenderType = 'female' | 'male' | 0 | 1; - -/** - * Normalize gender. - * - * @param gender Gender. - * @param functionName Temporary parameter for deprecation message. - * @returns Normalized gender. - */ -function normalizeGender( - gender?: GenderType, - functionName?: string -): Exclude | undefined { - if (gender == null || typeof gender === 'string') { - // TODO @Shinigami92 2022-03-21: Cast can be removed when we set `strict: true` - return gender as Exclude; - } - - const normalizedGender = gender === 0 ? 'male' : 'female'; - - deprecated({ - deprecated: `name.${functionName}(number)`, - proposed: "'female' or 'male'", - since: 'v6.1.0', - until: 'v7.0.0', - }); - - return normalizedGender; -} +export type GenderType = 'female' | 'male'; /** * Select a definition based on given gender. @@ -46,7 +16,6 @@ function normalizeGender( * @param param2.generic Non-gender definitions. * @param param2.female Female definitions. * @param param2.male Male definitions. - * @param functionName Temporary parameter for deprecation message. * @returns Definition based on given gender. */ function selectDefinition( @@ -57,13 +26,10 @@ function selectDefinition( generic, female, male, - }: { generic?: string[]; female?: string[]; male?: string[] } = {}, - functionName?: string + }: { generic?: string[]; female?: string[]; male?: string[] } = {} ) { - const normalizedGender = normalizeGender(gender, functionName); - let values: string[] | undefined; - switch (normalizedGender) { + switch (gender) { case 'female': values = female; break; @@ -115,16 +81,11 @@ export class Name { const { first_name, female_first_name, male_first_name } = this.faker.definitions.name; - return selectDefinition( - this.faker, - gender, - { - generic: first_name, - female: female_first_name, - male: male_first_name, - }, - 'firstName' - ); + return selectDefinition(this.faker, gender, { + generic: first_name, + female: female_first_name, + male: male_first_name, + }); } /** @@ -142,16 +103,11 @@ export class Name { const { last_name, female_last_name, male_last_name } = this.faker.definitions.name; - return selectDefinition( - this.faker, - gender, - { - generic: last_name, - female: female_last_name, - male: male_last_name, - }, - 'lastName' - ); + return selectDefinition(this.faker, gender, { + generic: last_name, + female: female_last_name, + male: male_last_name, + }); } /** @@ -169,16 +125,11 @@ export class Name { const { middle_name, female_middle_name, male_middle_name } = this.faker.definitions.name; - return selectDefinition( - this.faker, - gender, - { - generic: middle_name, - female: female_middle_name, - male: male_middle_name, - }, - 'middleName' - ); + return selectDefinition(this.faker, gender, { + generic: middle_name, + female: female_middle_name, + male: male_middle_name, + }); } /** @@ -201,9 +152,8 @@ export class Name { let prefix = ''; let suffix = ''; - const normalizedGender: Exclude = - normalizeGender(gender, 'findName') ?? - this.faker.helpers.arrayElement(['female', 'male']); + const normalizedGender: GenderType = + gender ?? this.faker.helpers.arrayElement(['female', 'male']); firstName = firstName || this.firstName(normalizedGender); lastName = lastName || this.lastName(normalizedGender); @@ -260,16 +210,11 @@ export class Name { prefix(gender?: GenderType): string { const { prefix, female_prefix, male_prefix } = this.faker.definitions.name; - return selectDefinition( - this.faker, - gender, - { - generic: prefix, - female: female_prefix, - male: male_prefix, - }, - 'prefix' - ); + return selectDefinition(this.faker, gender, { + generic: prefix, + female: female_prefix, + male: male_prefix, + }); } /** @@ -283,25 +228,6 @@ export class Name { return this.faker.helpers.arrayElement(this.faker.definitions.name.suffix); } - /** - * Generates a random job title. - * - * @example - * faker.name.title() // 'International Integration Manager' - * - * @deprecated - */ - title(): string { - deprecated({ - deprecated: 'faker.name.title()', - proposed: 'faker.name.jobTitle()', - since: 'v6.1.2', - until: 'v7.0.0', - }); - - return this.jobTitle(); - } - /** * Generates a random job title. * diff --git a/src/modules/random/index.ts b/src/modules/random/index.ts index 7939b298d53..e3e36ec4168 100644 --- a/src/modules/random/index.ts +++ b/src/modules/random/index.ts @@ -1,6 +1,5 @@ import type { Faker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { deprecated } from '../../internal/deprecated'; /** * Method to reduce array of characters. @@ -17,7 +16,7 @@ function arrayRemove(arr: T[], values: readonly T[]): T[] { } /** - * Generates random values of different kinds. Some methods are deprecated and have been moved to dedicated modules. + * Generates random values of different kinds. */ export class Random { constructor(private readonly faker: Faker) { @@ -30,267 +29,6 @@ export class Random { } } - /** - * Returns a single random number between zero and the given max value or the given range with the specified precision. - * The bounds are inclusive. - * - * @param options Maximum value or options object. - * @param options.min Lower bound for generated number. Defaults to `0`. - * @param options.max Upper bound for generated number. Defaults to `99999`. - * @param options.precision Precision of the generated number. Defaults to `1`. - * - * @see faker.datatype.number() - * - * @example - * faker.random.number() // 55422 - * faker.random.number(100) // 52 - * faker.random.number({ min: 1000000 }) // 431433 - * faker.random.number({ max: 100 }) // 42 - * faker.random.number({ precision: 0.01 }) // 64246.18 - * faker.random.number({ min: 10, max: 100, precision: 0.01 }) // 36.94 - * - * @deprecated - */ - number( - options?: number | { min?: number; max?: number; precision?: number } - ): number { - deprecated({ - deprecated: 'faker.random.number()', - proposed: 'faker.datatype.number()', - // since: 'v5.0.0', (?) - until: 'v7.0.0', - }); - return this.faker.datatype.number(options); - } - - /** - * Returns a single random floating-point number for the given precision or range and precision. - * - * @param options Precision or options object. - * @param options.min Lower bound for generated number. Defaults to `0`. - * @param options.max Upper bound for generated number. Defaults to `99999`. - * @param options.precision Precision of the generated number. Defaults to `0.01`. - * - * @see faker.datatype.float() - * - * @example - * faker.random.float() // 51696.36 - * faker.random.float(0.1) // 52023.2 - * faker.random.float({ min: 1000000 }) // 212859.76 - * faker.random.float({ max: 100 }) // 28.11 - * faker.random.float({ precision: 0.1 }) // 84055.3 - * faker.random.float({ min: 10, max: 100, precision: 0.001 }) // 57.315 - * - * @deprecated - */ - float( - options?: number | { min?: number; max?: number; precision?: number } - ): number { - deprecated({ - deprecated: 'faker.random.float()', - proposed: 'faker.datatype.float()', - // since: 'v5.0.0', (?) - until: 'v7.0.0', - }); - return this.faker.datatype.float(options); - } - - /** - * Returns random element from the given array. - * - * @template T The type of the entries to pick from. - * @param array Array to pick the value from. Defaults to `['a', 'b', 'c']`. - * - * @example - * faker.random.arrayElement() // 'b' - * faker.random.arrayElement(['cat', 'dog', 'mouse']) // 'dog' - * - * @deprecated - */ - arrayElement( - array: ReadonlyArray = ['a', 'b', 'c'] as unknown as ReadonlyArray - ): T { - deprecated({ - deprecated: 'faker.random.arrayElement()', - proposed: 'faker.helpers.arrayElement()', - since: 'v6.3.0', - until: 'v7.0.0', - }); - return this.faker.helpers.arrayElement(array); - } - - /** - * Returns a subset with random elements of the given array in random order. - * - * @template T The type of the entries to pick from. - * @param array Array to pick the value from. Defaults to `['a', 'b', 'c']`. - * @param count Number of elements to pick. - * When not provided, random number of elements will be picked. - * When value exceeds array boundaries, it will be limited to stay inside. - * - * @example - * faker.random.arrayElements() // ['b', 'c'] - * faker.random.arrayElements(['cat', 'dog', 'mouse']) // ['mouse', 'cat'] - * faker.random.arrayElements([1, 2, 3, 4, 5], 2) // [4, 2] - * - * @deprecated - */ - arrayElements( - array: ReadonlyArray = ['a', 'b', 'c'] as unknown as ReadonlyArray, - count?: number - ): T[] { - deprecated({ - deprecated: 'faker.random.arrayElements()', - proposed: 'faker.helpers.arrayElements()', - since: 'v6.3.0', - until: 'v7.0.0', - }); - return this.faker.helpers.arrayElements(array, count); - } - - /** - * Returns a random key from given object. - * - * @template T The type of `Record` to pick from. - * @template K The keys of `T`. - * @param object The object to get the keys from. - * @param field If this is set to `'key'`, this method will a return a random key of the given instance. - * - * @see faker.helpers.objectKey() - * - * @example - * const object = { keyA: 'valueA', keyB: 42 }; - * faker.random.objectElement(object, 'key') // 'keyB' - * - * @deprecated - */ - objectElement, K extends keyof T>( - object: T, - field: 'key' - ): K; - /** - * Returns a random value from given object. - * - * @template T The type of `Record` to pick from. - * @template K The keys of `T`. - * @param object The object to get the values from. - * @param field If this is set to `'value'`, this method will a return a random value of the given instance. - * - * @see faker.helpers.objectValue() - * - * @example - * const object = { keyA: 'valueA', keyB: 42 }; - * faker.random.objectElement(object) // 42 - * faker.random.objectElement(object, 'value') // 'valueA' - * - * @deprecated - */ - objectElement, K extends keyof T>( - object: T, - field?: unknown - ): T[K]; - /** - * Returns a random key or value from given object. - * - * @template T The type of `Record` to pick from. - * @template K The keys of `T`. - * @param object The object to get the keys or values from. - * @param field If this is set to `'key'`, this method will a return a random key of the given instance. - * If this is set to `'value'`, this method will a return a random value of the given instance. - * Defaults to `'value'`. - * - * @see faker.helpers.objectKey() - * @see faker.helpers.objectValue() - * - * @example - * const object = { keyA: 'valueA', keyB: 42 }; - * faker.random.objectElement(object) // 42 - * faker.random.objectElement(object, 'key') // 'keyB' - * faker.random.objectElement(object, 'value') // 'valueA' - * - * @deprecated - */ - objectElement, K extends keyof T>( - object?: T, - field?: 'key' | 'value' - ): K | T[K]; - /** - * Returns a random key or value from given object. - * - * @template T The type of `Record` to pick from. - * @template K The keys of `T`. - * @param object The object to get the keys or values from. - * @param field If this is set to `'key'`, this method will a return a random key of the given instance. - * If this is set to `'value'`, this method will a return a random value of the given instance. - * Defaults to `'value'`. - * - * @see faker.helpers.objectKey() - * @see faker.helpers.objectValue() - * - * @example - * const object = { keyA: 'valueA', keyB: 42 }; - * faker.random.objectElement(object) // 42 - * faker.random.objectElement(object, 'key') // 'keyB' - * faker.random.objectElement(object, 'value') // 'valueA' - * - * @deprecated - */ - objectElement, K extends keyof T>( - object: T = { foo: 'bar', too: 'car' } as unknown as T, - field: 'key' | 'value' = 'value' - ): K | T[K] { - const useKey = field === 'key'; - deprecated({ - deprecated: `faker.random.objectElement(${useKey ? "obj, 'key'" : ''})`, - proposed: `faker.helpers.object${useKey ? 'Key' : 'Value'}()`, - since: 'v6.3.0', - until: 'v7.0.0', - }); - return field === 'key' - ? (this.faker.helpers.objectKey(object) as K) - : (this.faker.helpers.objectValue(object) as T[K]); - } - - /** - * Returns a UUID v4 ([Universally Unique Identifier](https://en.wikipedia.org/wiki/Universally_unique_identifier)). - * - * @see faker.datatype.uuid() - * - * @example - * faker.random.uuid() // '4136cd0b-d90b-4af7-b485-5d1ded8db252' - * - * @deprecated - */ - uuid(): string { - deprecated({ - deprecated: 'faker.random.uuid()', - proposed: 'faker.datatype.uuid()', - // since: 'v5.0.0', (?) - until: 'v7.0.0', - }); - return this.faker.datatype.uuid(); - } - - /** - * Returns the boolean value `true` or `false`. - * - * @see faker.datatype.boolean() - * - * @example - * faker.random.boolean() // false - * - * @deprecated - */ - boolean(): boolean { - deprecated({ - deprecated: 'faker.random.boolean()', - proposed: 'faker.datatype.boolean()', - // since: 'v5.0.0', (?) - until: 'v7.0.0', - }); - return this.faker.datatype.boolean(); - } - /** * Returns random word. * @@ -391,26 +129,6 @@ export class Random { return words.join(' '); } - /** - * Returns a random image url. - * - * @see faker.random.image() - * - * @example - * faker.random.image() // 'http://placeimg.com/640/480/animals' - * - * @deprecated - */ - image(): string { - deprecated({ - deprecated: 'faker.random.image()', - proposed: 'faker.image.image()', - // since: 'v5.0.0', (?) - until: 'v7.0.0', - }); - return this.faker.image.image(); - } - /** * Returns a random locale, that is available in this faker instance. * You can use the returned locale with `faker.setLocale(result)`. @@ -621,28 +339,4 @@ export class Random { return result; } - - /** - * Returns a hexadecimal number. - * - * @param count Length of the generated number. Defaults to `1`. - * - * @see faker.datatype.hexadecimal() - * - * @example - * faker.random.hexaDecimal() // '0xb' - * faker.random.hexaDecimal(10) // '0xaE13F044fb' - * - * @deprecated - */ - hexaDecimal(count?: number): string { - deprecated({ - deprecated: 'faker.random.hexaDecimal()', - proposed: 'faker.datatype.hexadecimal()', - // since: 'v5.0.0', (?) - until: 'v7.0.0', - }); - - return this.faker.datatype.hexadecimal(count); - } } diff --git a/src/modules/time/index.ts b/src/modules/time/index.ts deleted file mode 100644 index 021d75c8b64..00000000000 --- a/src/modules/time/index.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { deprecated } from '../../internal/deprecated'; -import type { LiteralUnion } from '../../utils/types'; - -/** - * Module to generate time of dates in various formats. - * - * @deprecated You should stop using this module, as it will be removed in the future. - */ -export class Time { - /** - * Returns recent time. - * - * @param format The format to use. - * - * - `'abbr'` Return a string with only the time. `Date.toLocaleTimeString`. - * - `'date'` Return a date instance. - * - `'wide'` Return a string with a long time. `Date.toTimeString()`. - * - `'unix'` Returns a unix timestamp. - * - * Defaults to `'unix'`. - * - * @example - * faker.time.recent() // 1643067231856 - * faker.time.recent('abbr') // '12:34:07 AM' - * faker.time.recent('date') // 2022-03-01T20:35:47.402Z - * faker.time.recent('wide') // '00:34:11 GMT+0100 (Central European Standard Time)' - * faker.time.recent('unix') // 1643067231856 - * - * @deprecated You should stop using this function, as it will be removed in the future. Use the native `new Date()` with one of the wanted functions directly. - */ - recent( - format: LiteralUnion<'abbr' | 'date' | 'wide' | 'unix'> = 'unix' - ): string | number | Date { - deprecated({ - deprecated: 'faker.time.recent()', - proposed: 'native `new Date()` and call the function you want on it', - since: 'v6.1.0', - until: 'v7.0.0', - }); - - let date: string | number | Date = new Date(); - - switch (format) { - case 'abbr': - date = date.toLocaleTimeString(); - break; - case 'wide': - date = date.toTimeString(); - break; - case 'unix': - date = date.getTime(); - break; - } - - return date; - } -} diff --git a/src/modules/unique/index.ts b/src/modules/unique/index.ts index 798fc29e51f..d77004e496c 100644 --- a/src/modules/unique/index.ts +++ b/src/modules/unique/index.ts @@ -1,4 +1,3 @@ -import { deprecated } from '../../internal/deprecated'; import type { RecordKey } from './unique'; import * as uniqueExec from './unique'; @@ -6,80 +5,6 @@ import * as uniqueExec from './unique'; * Module to generate unique entries. */ export class Unique { - /** - * Maximum time `unique.exec` will attempt to run before aborting. - * - * @deprecated Use options instead. - */ - private _maxTime = 10; - - /** - * Maximum time `unique.exec` will attempt to run before aborting. - * - * @deprecated Use options instead. - */ - get maxTime(): number { - deprecated({ - deprecated: 'faker.unique.maxTime', - proposed: 'Options', - since: 'v6.2.0', - until: 'v7.0.0', - }); - return this._maxTime; - } - - /** - * Maximum time `unique.exec` will attempt to run before aborting. - * - * @deprecated Use options instead. - */ - set maxTime(value: number) { - deprecated({ - deprecated: 'faker.unique.maxTime', - proposed: 'Options', - since: 'v6.2.0', - until: 'v7.0.0', - }); - this._maxTime = value; - } - - /** - * Maximum retries `unique.exec` will recurse before aborting (max loop depth). - * - * @deprecated Use options instead. - */ - private _maxRetries = 10; - - /** - * Maximum retries `unique.exec` will recurse before aborting (max loop depth). - * - * @deprecated Use options instead. - */ - get maxRetries(): number { - deprecated({ - deprecated: 'faker.unique.maxRetries', - proposed: 'Options', - since: 'v6.2.0', - until: 'v7.0.0', - }); - return this._maxRetries; - } - - /** - * Maximum retries `unique.exec` will recurse before aborting (max loop depth). - * - * @deprecated Use options instead. - */ - set maxRetries(value: number) { - deprecated({ - deprecated: 'faker.unique.maxRetries', - proposed: 'Options', - since: 'v6.2.0', - until: 'v7.0.0', - }); - this._maxRetries = value; - } - constructor() { // Bind `this` so namespaced is working correctly for (const name of Object.getOwnPropertyNames(Unique.prototype)) { @@ -127,7 +52,7 @@ export class Unique { store?: Record; } = {} ): ReturnType { - const { maxTime = this._maxTime, maxRetries = this._maxRetries } = options; + const { maxTime = 50, maxRetries = 50 } = options; return uniqueExec.exec(method, args, { ...options, startTime: new Date().getTime(), diff --git a/test/datatype.spec.ts b/test/datatype.spec.ts index 54504e02d33..96d40cff027 100644 --- a/test/datatype.spec.ts +++ b/test/datatype.spec.ts @@ -1,4 +1,4 @@ -import { describe, expect, it, vi } from 'vitest'; +import { describe, expect, it } from 'vitest'; import { faker } from '../src'; const seededRuns = [ @@ -661,30 +661,6 @@ describe('datatype', () => { }); }); - describe('hexaDecimal', () => { - it('should display deprecated message', () => { - const spy = vi.spyOn(console, 'warn'); - - faker.datatype.hexaDecimal(); - - expect(spy).toHaveBeenCalledWith( - '[@faker-js/faker]: faker.datatype.hexaDecimal() is deprecated since v6.1.2 and will be removed in v7.0.0. Please use faker.datatype.hexadecimal() instead.' - ); - - spy.mockRestore(); - }); - - it('should display call hexadecimal()', () => { - const spy = vi.spyOn(faker.datatype, 'hexadecimal'); - - faker.datatype.hexaDecimal(10); - - expect(spy).toHaveBeenCalledWith(10); - - spy.mockRestore(); - }); - }); - describe('hexadecimal', () => { it('generates single hex character when no additional argument was provided', () => { const hex = faker.datatype.hexadecimal(); diff --git a/test/finance.spec.ts b/test/finance.spec.ts index 0a110870e73..7ae4a0f376d 100644 --- a/test/finance.spec.ts +++ b/test/finance.spec.ts @@ -26,7 +26,7 @@ const seedRuns = [ iban: 'GT30Y75110867098F1E3542612J4', bic: 'UYEOSCP1514', transactionDescription: - 'deposit transaction at Wiegand, Deckow and Renner using card ending with ***(...6009) for SGD 374.54 in account ***00483617', + 'invoice transaction at Wiegand, Deckow and Renner using card ending with ***(...8361) for SDG 374.54 in account ***55141004', }, }, { @@ -50,7 +50,7 @@ const seedRuns = [ iban: 'FO7710540350900318', bic: 'OEFELYL1032', transactionDescription: - 'deposit transaction at Cronin - Effertz using card ending with ***(...1830) for PEN 262.02 in account ***55239273', + 'withdrawal transaction at Cronin - Effertz using card ending with ***(...3927) for GTQ 262.02 in account ***54032552', }, }, { @@ -74,7 +74,7 @@ const seedRuns = [ iban: 'TN0382001124170679299069', bic: 'LXUEBTZ1', transactionDescription: - 'deposit transaction at Trantow - Sanford using card ending with ***(...8076) for PYG 928.52 in account ***62743167', + 'deposit transaction at Trantow - Sanford using card ending with ***(...4316) for STN 928.52 in account ***19061627', }, }, ]; diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts index 819f08a39d4..772e520ce9a 100644 --- a/test/helpers.spec.ts +++ b/test/helpers.spec.ts @@ -1,4 +1,4 @@ -import { afterEach, describe, expect, it, vi } from 'vitest'; +import { afterEach, describe, expect, it } from 'vitest'; import { faker } from '../src'; import { luhnCheck } from './support/luhnCheck'; @@ -6,7 +6,6 @@ const seededRuns = [ { seed: 42, expectations: { - randomize: 'b', slugify: '', replaceSymbolWithNumber: '', replaceSymbols: '', @@ -16,147 +15,11 @@ const seededRuns = [ shuffle: [], uniqueArray: [], mustache: '', - createCard: { - accountHistory: [ - { - account: '62615449', - amount: '266.78', - business: 'Wolf - Kuvalis', - date: expect.any(Date), - name: 'Investment Account (...0023)', - type: 'invoice', - }, - { - account: '83469635', - amount: '552.89', - business: 'McLaughlin LLC', - date: expect.any(Date), - name: 'Checking Account (...7322)', - type: 'payment', - }, - { - account: '85362075', - amount: '816.44', - business: 'Schmeler Group', - date: expect.any(Date), - name: 'Savings Account (...3516)', - type: 'deposit', - }, - ], - address: { - city: 'Leopoldview', - country: 'Aruba', - geo: { - lat: '51.3317', - lng: '42.6190', - }, - state: 'Connecticut', - streetA: 'Estella Lodge', - streetB: '1760 Mireya Causeway', - streetC: '920 Christelle Estate Suite 365', - streetD: 'Apt. 402', - zipcode: '93240', - }, - company: { - bs: 'implement scalable communities', - catchPhrase: 'Self-enabling exuding encryption', - name: 'Weissnat, Wintheiser and MacGyver', - }, - email: 'Isabel5@gmail.com', - name: 'Darnell Deckow', - phone: '559.640.8661', - posts: [ - { - paragraph: - 'Adipisci occaecati quae sapiente voluptas nulla iure. Enim ut eum officia ex delectus minima est. Ad qui exercitationem et dolorem architecto perferendis.', - sentence: - 'Quia est dolores fugiat aperiam quia voluptates reprehenderit.', - sentences: - 'Distinctio possimus enim nihil. Quia unde similique amet doloremque ut voluptas. Ducimus itaque qui saepe molestiae mollitia qui et voluptas.', - words: 'nobis et odio', - }, - { - paragraph: - 'Aliquam quos ipsa cupiditate impedit molestiae aut accusantium odio. Sed doloremque eveniet. Voluptatum ipsam error molestias optio et eos magnam.', - sentence: - 'Velit exercitationem consequatur perferendis illum velit.', - sentences: - 'Qui temporibus est id architecto molestiae ea et. Repudiandae eos pariatur. Ducimus sit explicabo veritatis quis enim libero. Nam qui deserunt quidem ad. Natus rem eum sed ut quo pariatur omnis quisquam natus.', - words: 'maiores nihil est', - }, - { - paragraph: - 'Sed enim laboriosam et earum dolorem quia eius. Iste nihil ea commodi et ut aliquam. Dolore magnam optio dolores quo ullam ratione veniam repellat eaque.', - sentence: 'Sed tempora earum beatae animi nostrum optio neque aut.', - sentences: - 'Consequatur exercitationem harum odit accusamus blanditiis aut. Amet esse saepe aut. Quia consequatur quia eveniet ex voluptatem et. Enim tempora est. Alias illum aliquid eos corporis consequatur. Excepturi provident esse atque.', - words: 'id velit ut', - }, - ], - username: 'Moses_Satterfield', - website: 'irritating-banyan.com', - }, - contextualCard: { - address: { - city: 'Cicero', - geo: { - lat: '-18.0250', - lng: '-129.7822', - }, - street: 'Riley Walk', - suite: 'Suite 201', - zipcode: '36504-0256', - }, - avatar: - 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/974.jpg', - company: { - bs: 'reinvent dynamic relationships', - catchPhrase: 'Compatible regional middleware', - name: 'Feest - Klocko', - }, - dob: new Date('1984-12-04T21:58:56.056Z'), - email: 'Garnett.Schinner7344@yahoo.com', - name: 'Garnett', - phone: '(248) 461-7600', - username: 'Garnett.Schinner73', - website: 'ashamed-e-reader.org', - }, - userCard: { - address: { - city: 'North Wainomouth', - geo: { - lat: '4.4562', - lng: '-177.4562', - }, - street: 'Estella Lodge', - suite: 'Suite 176', - zipcode: '92019-1636', - }, - company: { - bs: 'exploit seamless infomediaries', - catchPhrase: 'Persistent holistic alliance', - name: 'Langworth - Wyman', - }, - email: 'Isabel5@gmail.com', - name: 'Darnell Deckow', - phone: '225-631-0293 x240', - username: 'Moses_Satterfield', - website: 'sparse-ottoman.biz', - }, - createTransaction: { - account: '00483617', - amount: '374.54', - business: 'Wiegand, Deckow and Renner', - date: expect.any(Date), - name: 'Auto Loan Account (...5514)', - type: 'deposit', - }, }, }, { seed: 1337, expectations: { - randomize: 'a', slugify: '', replaceSymbolWithNumber: '', replaceSymbols: '', @@ -166,146 +29,11 @@ const seededRuns = [ shuffle: [], uniqueArray: [], mustache: '', - createCard: { - accountHistory: [ - { - account: '74726042', - amount: '407.15', - business: 'Tromp - Ullrich', - date: expect.any(Date), - name: 'Credit Card Account (...8720)', - type: 'payment', - }, - { - account: '96491055', - amount: '521.69', - business: 'Bauch - Graham', - date: expect.any(Date), - name: 'Personal Loan Account (...4932)', - type: 'withdrawal', - }, - { - account: '45684786', - amount: '705.74', - business: 'Hamill - Cronin', - date: expect.any(Date), - name: 'Money Market Account (...7936)', - type: 'payment', - }, - ], - address: { - city: 'Noelbury', - country: 'Kyrgyz Republic', - geo: { - lat: '-57.8577', - lng: '-129.2926', - }, - state: 'Georgia', - streetA: 'Donald Hill', - streetB: '318 Murazik Junction', - streetC: '1791 Patricia Loaf Suite 703', - streetD: 'Apt. 435', - zipcode: '86444', - }, - company: { - bs: 'orchestrate bleeding-edge infrastructures', - catchPhrase: 'Polarised zero tolerance moratorium', - name: 'Armstrong, Smitham and Renner', - }, - email: 'Darron.Larson@gmail.com', - name: 'Eugene Effertz', - phone: '818-698-6199 x848', - posts: [ - { - paragraph: - 'Voluptatibus dolor est totam praesentium ducimus tempore. Rerum autem atque quos esse est. Autem eligendi aliquid. Voluptates quis quo.', - sentence: - 'Aut alias cum consequatur pariatur inventore omnis temporibus.', - sentences: - 'Illo cumque cupiditate quos cum. Placeat quo ut est ut error quo repellat id aliquam. Perferendis corporis sunt est itaque ad aut aut quos. Laboriosam molestias quisquam ratione aut. Omnis necessitatibus tempore ut consectetur voluptas nam praesentium. Libero neque iste voluptates temporibus quia officiis cumque eos ut.', - words: 'esse autem harum', - }, - { - paragraph: - 'At perferendis asperiores et exercitationem. Reprehenderit placeat cumque modi ex modi doloremque reprehenderit. Corrupti atque velit ab laboriosam. Accusamus est rem est qui aspernatur hic eaque est quaerat.', - sentence: 'Sed totam nam et ut harum.', - sentences: - 'Sit labore voluptatem rerum non natus ratione. Quas ut corporis et vel qui doloribus excepturi autem. Eius nobis natus accusantium. Ut impedit id cupiditate recusandae sit laborum beatae.', - words: 'deserunt eveniet deleniti', - }, - { - paragraph: - 'Aut aut voluptas at laboriosam. Omnis error suscipit autem culpa dolorem ipsum ex. Rerum enim animi maxime repellendus error dolorum ut eveniet. Velit accusantium eum vitae error tenetur deserunt. Fugiat ratione explicabo cum optio fuga.', - sentence: 'Suscipit soluta nulla deleniti.', - sentences: - 'Blanditiis culpa modi amet eum amet delectus laboriosam aperiam et. Beatae ad quidem quasi. Praesentium est ut.', - words: 'nostrum consequuntur alias', - }, - ], - username: 'Dudley.Littel', - website: 'lovable-principle.name', - }, - contextualCard: { - address: { - city: 'Schimmeltown', - geo: { - lat: '46.8309', - lng: '-46.8173', - }, - street: 'Wilmer Creek', - suite: 'Apt. 487', - zipcode: '44355', - }, - avatar: - 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/347.jpg', - company: { - bs: 'synergize transparent channels', - catchPhrase: 'Monitored client-server budgetary management', - name: 'Ortiz, Jacobson and Kuphal', - }, - dob: new Date('1980-12-16T23:18:00.988Z'), - email: 'Devyn2132@yahoo.com', - name: 'Devyn', - phone: '1-623-927-3183 x063', - username: 'Devyn21', - website: 'dependent-ischemia.biz', - }, - userCard: { - address: { - city: 'North Llewellyn', - geo: { - lat: '65.2766', - lng: '104.2410', - }, - street: 'Donald Hill', - suite: 'Suite 318', - zipcode: '17914', - }, - company: { - bs: 'e-enable back-end experiences', - catchPhrase: 'Inverse secondary complexity', - name: 'Daugherty - Connelly', - }, - email: 'Darron.Larson@gmail.com', - name: 'Eugene Effertz', - phone: '803.543.5573 x1428', - username: 'Dudley.Littel', - website: 'queasy-guide.info', - }, - createTransaction: { - account: '55239273', - amount: '262.02', - business: 'Cronin - Effertz', - date: expect.any(Date), - name: 'Money Market Account (...5403)', - type: 'deposit', - }, }, }, { seed: 1211, expectations: { - randomize: 'c', slugify: '', replaceSymbolWithNumber: '', replaceSymbols: '', @@ -315,140 +43,6 @@ const seededRuns = [ shuffle: [], uniqueArray: [], mustache: '', - createCard: { - accountHistory: [ - { - account: '22174368', - amount: '362.33', - business: 'Wisoky, Smitham and Harvey', - date: expect.any(Date), - name: 'Personal Loan Account (...6184)', - type: 'invoice', - }, - { - account: '23584206', - amount: '108.51', - business: 'Hessel - Lesch', - date: expect.any(Date), - name: 'Money Market Account (...5696)', - type: 'invoice', - }, - { - account: '51479656', - amount: '253.29', - business: 'Schuppe, Corkery and Windler', - date: expect.any(Date), - name: 'Personal Loan Account (...9398)', - type: 'payment', - }, - ], - address: { - city: 'Kansas City', - country: 'Algeria', - geo: { - lat: '85.0485', - lng: '-122.7807', - }, - state: 'Rhode Island', - streetA: 'Neil Divide', - streetB: '076 Rickey Ports', - streetC: '428 Yasmeen Way Apt. 459', - streetD: 'Apt. 136', - zipcode: '39054', - }, - company: { - bs: 'mesh 24/7 models', - catchPhrase: 'Organized client-driven architecture', - name: 'Jacobi and Sons', - }, - email: 'Marlen.Effertz35@gmail.com', - name: 'Henrietta Sanford', - phone: '621-735-9398', - posts: [ - { - paragraph: - 'Cupiditate pariatur laudantium. Inventore autem qui totam quo sunt. Consequatur rerum perspiciatis. Non tenetur ut quod vel explicabo officiis.', - sentence: 'Nulla quos quidem et sed voluptate et quia.', - sentences: - 'Esse in similique deleniti beatae eaque facilis optio unde. Dolorum impedit et ad. Omnis libero excepturi optio. Atque eius sequi laborum perspiciatis officiis.', - words: 'tempora eos ipsa', - }, - { - paragraph: - 'Harum vero eum facilis facere odio nulla. Voluptates earum sed libero nisi vitae sed eius ducimus earum. Ducimus eum perferendis velit quia. Doloribus explicabo labore dolore dolores eaque voluptas non quo quam. Sint sapiente mollitia magnam a quibusdam maiores et aliquid ea. Nisi placeat voluptas et distinctio magni eveniet.', - sentence: - 'Nam fugiat quos laboriosam qui necessitatibus alias voluptatem.', - sentences: - 'Vel omnis maiores totam ut vitae accusamus. Officia eos natus minima voluptates. Iusto voluptates saepe asperiores. Esse consequatur consectetur qui. Quia error et culpa vel et facere.', - words: 'quia eius cumque', - }, - { - paragraph: - 'Esse perferendis voluptatem molestiae dolorem ut quas exercitationem. Quo maiores ut et pariatur dolor velit rem officiis praesentium. Hic quo aut quis facilis. Est aut sint dolor illum. Architecto asperiores velit aut qui.', - sentence: 'Minus aut aliquam perspiciatis.', - sentences: - 'Recusandae atque sequi magnam nihil est architecto nostrum iusto corrupti. Vero ipsam illum accusantium possimus tempora nihil incidunt. Molestiae saepe mollitia ea est velit sed incidunt. Assumenda mollitia voluptas eveniet sapiente ducimus voluptatem totam. Qui aspernatur omnis libero voluptatem sed sunt maxime totam. Odio facilis explicabo quidem.', - words: 'cupiditate debitis est', - }, - ], - username: 'Dangelo.Christiansen67', - website: 'fresh-geek.name', - }, - contextualCard: { - address: { - city: 'Susieberg', - geo: { - lat: '-88.0651', - lng: '-37.2858', - }, - street: 'Wilton Greens', - suite: 'Suite 924', - zipcode: '36947', - }, - avatar: - 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/162.jpg', - company: { - bs: 'empower e-business models', - catchPhrase: 'Decentralized context-sensitive leverage', - name: 'Johnston - Witting', - }, - dob: new Date('1982-03-04T22:21:46.523Z'), - email: 'Tito_Koch22.Batz68@hotmail.com', - name: 'Tito', - phone: '531.778.0766 x7894', - username: 'Tito_Koch22', - website: 'forthright-tuxedo.com', - }, - userCard: { - address: { - city: 'Reingerfield', - geo: { - lat: '73.0714', - lng: '-108.2073', - }, - street: 'Neil Divide', - suite: 'Suite 076', - zipcode: '42898-9245', - }, - company: { - bs: 'disintermediate sexy experiences', - catchPhrase: 'Focused client-driven orchestration', - name: 'Fahey LLC', - }, - email: 'Marlen.Effertz35@gmail.com', - name: 'Henrietta Sanford', - phone: '469.570.3390', - username: 'Dangelo.Christiansen67', - website: 'mild-hearth.org', - }, - createTransaction: { - account: '62743167', - amount: '928.52', - business: 'Trantow - Sanford', - date: expect.any(Date), - name: 'Savings Account (...1906)', - type: 'deposit', - }, }, }, ]; @@ -456,7 +50,6 @@ const seededRuns = [ const NON_SEEDED_BASED_RUN = 5; const functionNames = [ - 'randomize', 'slugify', 'replaceSymbolWithNumber', 'replaceSymbols', @@ -466,10 +59,6 @@ const functionNames = [ 'shuffle', 'uniqueArray', 'mustache', - 'createCard', - 'contextualCard', - 'userCard', - 'createTransaction', ]; describe('helpers', () => { @@ -557,15 +146,6 @@ describe('helpers', () => { }); }); - describe('randomize()', () => { - it('returns a random element from an array', () => { - const arr = ['a', 'b', 'c']; - const elem = faker.helpers.randomize(arr); - expect(elem).toBeTruthy(); - expect(arr).toContain(elem); - }); - }); - describe('slugify()', () => { it('removes unwanted characters from URI string', () => { expect(faker.helpers.slugify('Aiden.HarÂȘann')).toBe('Aiden.Harann'); @@ -831,40 +411,6 @@ describe('helpers', () => { }); }); - describe('createCard()', () => { - it('returns an object', () => { - const card = faker.helpers.createCard(); - expect(card).toBeTypeOf('object'); - }); - }); - - describe('contextualCard()', () => { - it('returns an object', () => { - const card = faker.helpers.contextualCard(); - expect(card).toBeTypeOf('object'); - }); - }); - - describe('userCard()', () => { - it('returns an object', () => { - const card = faker.helpers.userCard(); - expect(card).toBeTypeOf('object'); - }); - }); - - describe('createTransaction()', () => { - it('should create a random transaction', () => { - const transaction = faker.helpers.createTransaction(); - expect(transaction).toBeTruthy(); - expect(transaction.amount).toBeTruthy(); - expect(transaction.date).toBeTruthy(); - expect(transaction.business).toBeTruthy(); - expect(transaction.name).toBeTruthy(); - expect(transaction.type).toBeTruthy(); - expect(transaction.account).toBeTruthy(); - }); - }); - describe('maybe', () => { it('should always return the callback result when probability is 1', () => { const actual = faker.helpers.maybe(() => 'foo', { probability: 1 }); @@ -924,38 +470,6 @@ describe('helpers', () => { expect(actual).toBeUndefined(); }); }); - - describe('deprecation warnings', () => { - it.each([['randomize', 'helpers.arrayElement']])( - 'should warn user that function helpers.%s is deprecated', - (functionName, newLocation) => { - const spy = vi.spyOn(console, 'warn'); - - faker.helpers[functionName](); - - expect(spy).toHaveBeenCalledWith( - `[@faker-js/faker]: faker.helpers.${functionName}() is deprecated and will be removed in v7.0.0. Please use faker.${newLocation}() instead.` - ); - spy.mockRestore(); - } - ); - }); } }); - - describe('deprecation warnings', () => { - it.each(['createCard', 'contextualCard', 'userCard'])( - 'should warn user that function random.%s is deprecated', - (functionName) => { - const spy = vi.spyOn(console, 'warn'); - - faker.helpers[functionName](); - - expect(spy).toHaveBeenCalledWith( - `[@faker-js/faker]: helpers.${functionName}() is deprecated since v6.1.0 and will be removed in v7.0.0. Please use a self-build function instead.` - ); - spy.mockRestore(); - } - ); - }); }); diff --git a/test/name.spec.ts b/test/name.spec.ts index a182f5f0856..b0f1dae3fa3 100644 --- a/test/name.spec.ts +++ b/test/name.spec.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { faker } from '../src'; const seededRuns = [ @@ -29,9 +29,6 @@ const seededRuns = [ suffix: { noArgs: 'III', }, - title: { - noArgs: 'Regional Data Representative', - }, jobDescriptor: { noArgs: 'Regional', }, @@ -70,9 +67,6 @@ const seededRuns = [ suffix: { noArgs: 'I', }, - title: { - noArgs: 'Future Infrastructure Liaison', - }, jobDescriptor: { noArgs: 'Future', }, @@ -111,9 +105,6 @@ const seededRuns = [ suffix: { noArgs: 'DVM', }, - title: { - noArgs: 'Chief Division Agent', - }, jobDescriptor: { noArgs: 'Chief', }, @@ -138,7 +129,6 @@ const functionNames = [ 'gender', 'prefix', 'suffix', - 'title', 'jobDescriptor', 'jobArea', 'jobType', @@ -180,25 +170,7 @@ describe('name', () => { expect(first_name.length).toBeGreaterThan(0); }); - it('should return a gender-specific first name when passed a number', () => { - const spy = vi.spyOn(console, 'warn'); - - let name = faker.name.firstName(0); - expect(faker.definitions.name.male_first_name).toContain(name); - expect(spy).toHaveBeenCalledWith( - "[@faker-js/faker]: name.firstName(number) is deprecated since v6.1.0 and will be removed in v7.0.0. Please use 'female' or 'male' instead." - ); - - name = faker.name.firstName(1); - expect(faker.definitions.name.female_first_name).toContain(name); - expect(spy).toHaveBeenCalledWith( - "[@faker-js/faker]: name.firstName(number) is deprecated since v6.1.0 and will be removed in v7.0.0. Please use 'female' or 'male' instead." - ); - - spy.mockRestore(); - }); - - it('should return a gender-specific first name when passed a string', () => { + it('should return a gender-specific first name', () => { let name = faker.name.firstName('female'); expect(faker.definitions.name.female_first_name).toContain(name); @@ -231,27 +203,7 @@ describe('name', () => { expect(last_name.length).toBeGreaterThan(0); }); - it('should return a gender-specific last name when passed a number', () => { - faker.locale = 'az'; - - const spy = vi.spyOn(console, 'warn'); - - let name = faker.name.lastName(0); - expect(faker.definitions.name.male_last_name).toContain(name); - expect(spy).toHaveBeenCalledWith( - "[@faker-js/faker]: name.lastName(number) is deprecated since v6.1.0 and will be removed in v7.0.0. Please use 'female' or 'male' instead." - ); - - name = faker.name.lastName(1); - expect(faker.definitions.name.female_last_name).toContain(name); - expect(spy).toHaveBeenCalledWith( - "[@faker-js/faker]: name.lastName(number) is deprecated since v6.1.0 and will be removed in v7.0.0. Please use 'female' or 'male' instead." - ); - - spy.mockRestore(); - }); - - it('should return a gender-specific last name when passed a string', () => { + it('should return a gender-specific last name', () => { faker.locale = 'az'; let name = faker.name.lastName('female'); @@ -288,27 +240,7 @@ describe('name', () => { expect(faker.definitions.name.male_middle_name).toContain(name); }); - it('should return a gender-specific middle name when passed a number', () => { - const spy = vi.spyOn(console, 'warn'); - - faker.locale = 'uk'; - - let name = faker.name.middleName(0); - expect(faker.definitions.name.male_middle_name).toContain(name); - expect(spy).toHaveBeenCalledWith( - "[@faker-js/faker]: name.middleName(number) is deprecated since v6.1.0 and will be removed in v7.0.0. Please use 'female' or 'male' instead." - ); - - name = faker.name.middleName(1); - expect(faker.definitions.name.female_middle_name).toContain(name); - expect(spy).toHaveBeenCalledWith( - "[@faker-js/faker]: name.middleName(number) is deprecated since v6.1.0 and will be removed in v7.0.0. Please use 'female' or 'male' instead." - ); - - spy.mockRestore(); - }); - - it('should return a gender-specific middle name when passed a string', () => { + it('should return a gender-specific middle name', () => { faker.locale = 'uk'; let name = faker.name.middleName('female'); @@ -460,40 +392,6 @@ describe('name', () => { expect(prefix).toBeTypeOf('string'); expect(faker.definitions.name.male_prefix).toContain(prefix); }); - - it('should return a male prefix with given number', () => { - const spy = vi.spyOn(console, 'warn'); - - faker.locale = 'mk'; - - const prefix = faker.name.prefix(0); - - expect(prefix).toBeTypeOf('string'); - expect(faker.definitions.name.male_prefix).toContain(prefix); - - expect(spy).toHaveBeenCalledWith( - "[@faker-js/faker]: name.prefix(number) is deprecated since v6.1.0 and will be removed in v7.0.0. Please use 'female' or 'male' instead." - ); - - spy.mockRestore(); - }); - - it('should return a female prefix with given number', () => { - const spy = vi.spyOn(console, 'warn'); - - faker.locale = 'mk'; - - const prefix = faker.name.prefix(1); - - expect(prefix).toBeTypeOf('string'); - expect(faker.definitions.name.female_prefix).toContain(prefix); - - expect(spy).toHaveBeenCalledWith( - "[@faker-js/faker]: name.prefix(number) is deprecated since v6.1.0 and will be removed in v7.0.0. Please use 'female' or 'male' instead." - ); - - spy.mockRestore(); - }); }); describe('suffix()', () => { @@ -510,47 +408,6 @@ describe('name', () => { }); }); - describe('title()', () => { - beforeEach(() => { - faker.locale = 'en'; - faker.localeFallback = 'en'; - }); - - it('should display deprecated message', () => { - const spy = vi.spyOn(console, 'warn'); - - faker.name.title(); - - expect(spy).toHaveBeenCalledWith( - '[@faker-js/faker]: faker.name.title() is deprecated since v6.1.2 and will be removed in v7.0.0. Please use faker.name.jobTitle() instead.' - ); - - spy.mockRestore(); - }); - - it('should call jobTitle()', () => { - const spy = vi.spyOn(faker.name, 'jobTitle'); - - faker.name.title(); - - expect(spy).toHaveBeenCalledWith(); - - spy.mockRestore(); - }); - - it('should return a title consisting of a descriptor, area, and type', () => { - const title = faker.name.title(); - - expect(title).toBeTypeOf('string'); - - const [descriptor, level, job] = title.split(' '); - - expect(faker.definitions.name.title.descriptor).toContain(descriptor); - expect(faker.definitions.name.title.level).toContain(level); - expect(faker.definitions.name.title.job).toContain(job); - }); - }); - describe('jobTitle()', () => { beforeEach(() => { faker.locale = 'en'; diff --git a/test/random.spec.ts b/test/random.spec.ts index bf081b5c4cc..d6fe3da7cd0 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, it, vi } from 'vitest'; +import { beforeEach, describe, expect, it } from 'vitest'; import { faker, FakerError } from '../src'; import { times } from './support/times'; @@ -8,17 +8,8 @@ const seededRuns = [ expectations: { alpha: 'j', alphaNumeric: 'd', - arrayElement: 'b', - arrayElements: ['b', 'c'], - boolean: false, - float: 37453.64, - hexaDecimal: '0x8', - image: 'http://loremflickr.com/640/480/city', locale: 'es_MX', - number: 37454, numeric: '4', - objectElement: 'bar', - uuid: '5cf2bc99-2721-407d-992b-a00fbdf302f2', word: 'extend', words: 'mobile Fish', }, @@ -28,17 +19,8 @@ const seededRuns = [ expectations: { alpha: 'g', alphaNumeric: '9', - arrayElement: 'a', - arrayElements: ['b'], - boolean: false, - float: 26202.2, - hexaDecimal: '0x5', - image: 'http://loremflickr.com/640/480/cats', locale: 'en_GH', - number: 26202, numeric: '3', - objectElement: 'bar', - uuid: '48234870-5389-445f-8b41-c61a52bf27dc', word: 'leading', words: 'Delaware', }, @@ -48,17 +30,8 @@ const seededRuns = [ expectations: { alpha: 'y', alphaNumeric: 'x', - arrayElement: 'c', - arrayElements: ['a', 'c', 'b'], - boolean: true, - float: 92851.09, - hexaDecimal: '0xE', - image: 'http://loremflickr.com/640/480/transport', locale: 'ur', - number: 92852, numeric: '9', - objectElement: 'car', - uuid: 'e7ec32f0-a2a3-4c65-abbd-0caabde64dfd', word: 'Division', words: 'Turnpike Frozen Handcrafted', }, @@ -70,17 +43,8 @@ const NON_SEEDED_BASED_RUN = 5; const functionNames = [ 'alpha', 'alphaNumeric', - 'arrayElement', - 'arrayElements', - 'boolean', - 'float', - 'hexaDecimal', - 'image', 'locale', - 'number', 'numeric', - 'objectElement', - 'uuid', 'word', 'words', ]; @@ -103,95 +67,6 @@ describe('random', () => { faker.seed() )}`, () => { describe.each(times(NON_SEEDED_BASED_RUN))('%s', () => { - describe('arrayElement', () => { - it('should return a random element in the array', () => { - const testArray = ['hello', 'to', 'you', 'my', 'friend']; - const actual = faker.random.arrayElement(testArray); - - expect(testArray).toContain(actual); - }); - - it('should return a random element in the array when there is only 1', () => { - const testArray = ['hello']; - const actual = faker.random.arrayElement(testArray); - - expect(actual).toBe('hello'); - }); - }); - - describe('arrayElements', () => { - it('should return a subset with random elements in the array', () => { - const testArray = ['hello', 'to', 'you', 'my', 'friend']; - const subset = faker.random.arrayElements(testArray); - - // Check length - expect(subset.length).toBeGreaterThanOrEqual(1); - expect(subset.length).toBeLessThanOrEqual(testArray.length); - - // Check elements - subset.forEach((element) => { - expect(testArray).toContain(element); - }); - - // Check uniqueness - expect(subset).toHaveLength(new Set(subset).size); - }); - - it('should return a subset of fixed length with random elements in the array', () => { - const testArray = ['hello', 'to', 'you', 'my', 'friend']; - const subset = faker.random.arrayElements(testArray, 3); - - // Check length - expect(subset).toHaveLength(3); - - // Check elements - subset.forEach((element) => { - expect(testArray).toContain(element); - }); - - // Check uniqueness - expect(subset).toHaveLength(new Set(subset).size); - }); - }); - - describe('objectElement', () => { - it('should return a random value', () => { - const spy = vi.spyOn(console, 'warn'); - - const testObject = { - hello: 'to', - you: 'my', - friend: '!', - }; - const actual = faker.random.objectElement(testObject); - - expect(Object.values(testObject)).toContain(actual); - expect(spy).toHaveBeenCalledWith( - `[@faker-js/faker]: faker.random.objectElement() is deprecated since v6.3.0 and will be removed in v7.0.0. Please use faker.helpers.objectValue() instead.` - ); - - spy.mockRestore(); - }); - - it('should return a random key', () => { - const spy = vi.spyOn(console, 'warn'); - - const testObject = { - hello: 'to', - you: 'my', - friend: '!', - }; - const actual = faker.random.objectElement(testObject, 'key'); - - expect(Object.keys(testObject)).toContain(actual); - expect(spy).toHaveBeenCalledWith( - `[@faker-js/faker]: faker.random.objectElement(obj, 'key') is deprecated since v6.3.0 and will be removed in v7.0.0. Please use faker.helpers.objectKey() instead.` - ); - - spy.mockRestore(); - }); - }); - describe('word', () => { const bannedChars = [ '!', @@ -493,29 +368,6 @@ describe('random', () => { expect(actual).toMatch(/^[0235679]{1000}$/); }); }); - - describe('deprecation warnings', () => { - it.each([ - ['number', 'datatype.number'], - ['float', 'datatype.float'], - ['uuid', 'datatype.uuid'], - ['boolean', 'datatype.boolean'], - ['image', 'image.image'], - ['hexaDecimal', 'datatype.hexadecimal'], - ])( - 'should warn user that function random.%s is deprecated', - (functionName, newLocation) => { - const spy = vi.spyOn(console, 'warn'); - - faker.random[functionName](); - - expect(spy).toHaveBeenCalledWith( - `[@faker-js/faker]: faker.random.${functionName}() is deprecated and will be removed in v7.0.0. Please use faker.${newLocation}() instead.` - ); - spy.mockRestore(); - } - ); - }); }); }); }); diff --git a/test/time.spec.ts b/test/time.spec.ts deleted file mode 100644 index c9b7068df99..00000000000 --- a/test/time.spec.ts +++ /dev/null @@ -1,105 +0,0 @@ -import { describe, expect, it, vi } from 'vitest'; -import { faker } from '../src'; - -const seededRuns = [ - { - seed: 42, - expectations: { - recent: { - noArgs: 'number', - }, - }, - }, - { - seed: 1337, - expectations: { - recent: { - noArgs: 'number', - }, - }, - }, - { - seed: 1211, - expectations: { - recent: { - noArgs: 'number', - }, - }, - }, -]; - -const NON_SEEDED_BASED_RUN = 5; - -const functionNames = ['recent']; - -describe('time', () => { - // TODO @Shinigami92 2022-02-04: Results are not seeded yet - for (const { seed, expectations } of seededRuns) { - describe(`seed: ${seed}`, () => { - for (const functionName of functionNames) { - it(`${functionName}()`, () => { - faker.seed(seed); - - const actual = faker.time[functionName](); - expect(actual).toBeTypeOf(expectations[functionName].noArgs); - }); - } - }); - } - - describe(`random seeded tests for seed ${JSON.stringify( - faker.seed() - )}`, () => { - for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) { - describe('recent()', () => { - it('should return the recent timestamp in unix time format by default', () => { - const spy = vi.spyOn(console, 'warn'); - - const date = faker.time.recent(); - expect(date).toBeTypeOf('number'); - - expect(spy).toHaveBeenCalledWith( - '[@faker-js/faker]: faker.time.recent() is deprecated since v6.1.0 and will be removed in v7.0.0. Please use native `new Date()` and call the function you want on it instead.' - ); - spy.mockRestore(); - }); - - it('should return the recent timestamp in full time string format', () => { - const spy = vi.spyOn(console, 'warn'); - - const date = faker.time.recent('wide'); - expect(date).toBeTypeOf('string'); - - expect(spy).toHaveBeenCalledWith( - '[@faker-js/faker]: faker.time.recent() is deprecated since v6.1.0 and will be removed in v7.0.0. Please use native `new Date()` and call the function you want on it instead.' - ); - spy.mockRestore(); - }); - - it('should return the recent timestamp in abbreviated string format', () => { - const spy = vi.spyOn(console, 'warn'); - - const date = faker.time.recent('abbr'); - expect(date).toBeTypeOf('string'); - - expect(spy).toHaveBeenCalledWith( - '[@faker-js/faker]: faker.time.recent() is deprecated since v6.1.0 and will be removed in v7.0.0. Please use native `new Date()` and call the function you want on it instead.' - ); - spy.mockRestore(); - }); - - it('should return the recent timestamp in unix time format', () => { - const spy = vi.spyOn(console, 'warn'); - - const date = faker.time.recent('unix'); - expect(date).toBeTypeOf('number'); - - expect(spy).toHaveBeenCalledWith( - '[@faker-js/faker]: faker.time.recent() is deprecated since v6.1.0 and will be removed in v7.0.0. Please use native `new Date()` and call the function you want on it instead.' - ); - spy.mockRestore(); - }); - }); - } - }); -});