diff --git a/docs/guide/upgrading_v9/2752.md b/docs/guide/upgrading_v9/2752.md new file mode 100644 index 00000000000..518d304478c --- /dev/null +++ b/docs/guide/upgrading_v9/2752.md @@ -0,0 +1,7 @@ +### Remove deprecated commerce method + +Removed deprecated commerce method + +| old | replacement | +| --------------------------------------------- | ------------------------------------------------- | +| `faker.commerce.price(min, max, dec, symbol)` | `faker.commerce.price({ min, max, dec, symbol })` | diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index fa3efb26596..12ab94b8575 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -1,5 +1,4 @@ import { FakerError } from '../../errors/faker-error'; -import { deprecated } from '../../internal/deprecated'; import { ModuleBase } from '../../internal/module-base'; // Source for official prefixes: https://www.isbn-international.org/range_file_generation @@ -138,176 +137,34 @@ export class CommerceModule extends ModuleBase { * * @since 3.0.0 */ - price(options?: { - /** - * The minimum price. - * - * @default 1 - */ - min?: number; - /** - * The maximum price. - * - * @default 1000 - */ - max?: number; - /** - * The number of decimal places. - * - * @default 2 - */ - dec?: number; - /** - * The currency value to use. - * - * @default '' - */ - symbol?: string; - }): string; - /** - * Generates a price between min and max (inclusive). - * - * To better represent real-world prices, when `options.dec` is greater than `0`, the final decimal digit in the returned string will be generated as follows: - * - * - 50% of the time: `9` - * - 30% of the time: `5` - * - 10% of the time: `0` - * - 10% of the time: a random digit from `0` to `9` - * - * @param min The minimum price. Defaults to `1`. - * @param max The maximum price. Defaults to `1000`. - * @param dec The number of decimal places. Defaults to `2`. - * @param symbol The currency value to use. Defaults to `''`. - * - * @example - * faker.commerce.price() // 828.07 - * faker.commerce.price(100) // 904.19 - * faker.commerce.price(100, 200) // 154.55 - * faker.commerce.price(100, 200, 0) // 133 - * faker.commerce.price(100, 200, 0, '$') // $114 - * - * @since 3.0.0 - * - * @deprecated Use `faker.commerce.price({ min, max, dec, symbol })` instead. - */ - price(min?: number, max?: number, dec?: number, symbol?: string): string; - /** - * Generates a price between min and max (inclusive). - * - * To better represent real-world prices, when `options.dec` is greater than `0`, the final decimal digit in the returned string will be generated as follows: - * - * - 50% of the time: `9` - * - 30% of the time: `5` - * - 10% of the time: `0` - * - 10% of the time: a random digit from `0` to `9` - * - * @param options The minimum price or an options object. - * @param options.min The minimum price. Defaults to `1`. - * @param options.max The maximum price. Defaults to `1000`. - * @param options.dec The number of decimal places. Defaults to `2`. - * @param options.symbol The currency value to use. Defaults to `''`. - * @param legacyMax The maximum price. This argument is deprecated. Defaults to `1000`. - * @param legacyDec The number of decimal places. This argument is deprecated. Defaults to `2`. - * @param legacySymbol The currency value to use. This argument is deprecated. Defaults to `''`. - * - * @example - * faker.commerce.price() // 828.07 - * faker.commerce.price({ min: 100 }) // 904.19 - * faker.commerce.price({ min: 100, max: 200 }) // 154.55 - * faker.commerce.price({ min: 100, max: 200, dec: 0 }) // 133 - * faker.commerce.price({ min: 100, max: 200, dec: 0, symbol: '$' }) // $114 - * - * @since 3.0.0 - */ - price( - options?: - | number - | { - /** - * The minimum price. - * - * @default 1 - */ - min?: number; - /** - * The maximum price. - * - * @default 1000 - */ - max?: number; - /** - * The number of decimal places. - * - * @default 2 - */ - dec?: number; - /** - * The currency value to use. - * - * @default '' - */ - symbol?: string; - }, - legacyMax?: number, - legacyDec?: number, - legacySymbol?: string - ): string; - /** - * Generates a price between min and max (inclusive). - * - * To better represent real-world prices, when `options.dec` is greater than `0`, the final decimal digit in the returned string will be generated as follows: - * - * - 50% of the time: `9` - * - 30% of the time: `5` - * - 10% of the time: `0` - * - 10% of the time: a random digit from `0` to `9` - * - * @param options The minimum price or an options object. - * @param options.min The minimum price. Defaults to `1`. - * @param options.max The maximum price. Defaults to `1000`. - * @param options.dec The number of decimal places. Defaults to `2`. - * @param options.symbol The currency value to use. Defaults to `''`. - * @param legacyMax The maximum price. This argument is deprecated. Defaults to `1000`. - * @param legacyDec The number of decimal places. This argument is deprecated. Defaults to `2`. - * @param legacySymbol The currency value to use. This argument is deprecated. Defaults to `''`. - * - * @example - * faker.commerce.price() // 828.07 - * faker.commerce.price({ min: 100 }) // 904.19 - * faker.commerce.price({ min: 100, max: 200 }) // 154.55 - * faker.commerce.price({ min: 100, max: 200, dec: 0 }) // 133 - * faker.commerce.price({ min: 100, max: 200, dec: 0, symbol: '$' }) // $114 - * - * @since 3.0.0 - */ price( - options: - | number - | { - min?: number; - max?: number; - dec?: number; - symbol?: string; - } = {}, - legacyMax: number = 1000, - legacyDec: number = 2, - legacySymbol: string = '' + options: { + /** + * The minimum price. + * + * @default 1 + */ + min?: number; + /** + * The maximum price. + * + * @default 1000 + */ + max?: number; + /** + * The number of decimal places. + * + * @default 2 + */ + dec?: number; + /** + * The currency value to use. + * + * @default '' + */ + symbol?: string; + } = {} ): string { - if (typeof options === 'number') { - deprecated({ - deprecated: 'faker.commerce.price(min, max, dec, symbol)', - proposed: 'faker.commerce.price({ min, max, dec, symbol })', - since: '8.0', - until: '9.0', - }); - options = { - min: options, - dec: legacyDec, - max: legacyMax, - symbol: legacySymbol, - }; - } - const { dec = 2, max = 1000, min = 1, symbol = '' } = options; if (min < 0 || max < 0) { diff --git a/test/modules/__snapshots__/commerce.spec.ts.snap b/test/modules/__snapshots__/commerce.spec.ts.snap index b7841fd5f45..2cd27effddf 100644 --- a/test/modules/__snapshots__/commerce.spec.ts.snap +++ b/test/modules/__snapshots__/commerce.spec.ts.snap @@ -16,18 +16,8 @@ exports[`commerce > 42 > price > noArgs 1`] = `"375.15"`; exports[`commerce > 42 > price > with float min and float max option 1`] = `"1.05"`; -exports[`commerce > 42 > price > with max 1`] = `"375.15"`; - exports[`commerce > 42 > price > with max option 1`] = `"501.35"`; -exports[`commerce > 42 > price > with min 1`] = `"405.85"`; - -exports[`commerce > 42 > price > with min and max 1`] = `"68.75"`; - -exports[`commerce > 42 > price > with min and max and decimals 1`] = `"68.7275"`; - -exports[`commerce > 42 > price > with min and max and decimals and symbol 1`] = `"$68.7275"`; - exports[`commerce > 42 > price > with min and max and decimals and symbol option 1`] = `"$68.7275"`; exports[`commerce > 42 > price > with min and max and decimals option 1`] = `"68.7275"`; @@ -62,18 +52,8 @@ exports[`commerce > 1211 > price > noArgs 1`] = `"928.69"`; exports[`commerce > 1211 > price > with float min and float max option 1`] = `"1.10"`; -exports[`commerce > 1211 > price > with max 1`] = `"928.69"`; - exports[`commerce > 1211 > price > with max option 1`] = `"1241.59"`; -exports[`commerce > 1211 > price > with min 1`] = `"932.19"`; - -exports[`commerce > 1211 > price > with min and max 1`] = `"96.49"`; - -exports[`commerce > 1211 > price > with min and max and decimals 1`] = `"96.4269"`; - -exports[`commerce > 1211 > price > with min and max and decimals and symbol 1`] = `"$96.4269"`; - exports[`commerce > 1211 > price > with min and max and decimals and symbol option 1`] = `"$96.4269"`; exports[`commerce > 1211 > price > with min and max and decimals option 1`] = `"96.4269"`; @@ -108,18 +88,8 @@ exports[`commerce > 1337 > price > noArgs 1`] = `"262.79"`; exports[`commerce > 1337 > price > with float min and float max option 1`] = `"1.09"`; -exports[`commerce > 1337 > price > with max 1`] = `"262.79"`; - exports[`commerce > 1337 > price > with max option 1`] = `"351.09"`; -exports[`commerce > 1337 > price > with min 1`] = `"298.99"`; - -exports[`commerce > 1337 > price > with min and max 1`] = `"63.19"`; - -exports[`commerce > 1337 > price > with min and max and decimals 1`] = `"63.1019"`; - -exports[`commerce > 1337 > price > with min and max and decimals and symbol 1`] = `"$63.1019"`; - exports[`commerce > 1337 > price > with min and max and decimals and symbol option 1`] = `"$63.1019"`; exports[`commerce > 1337 > price > with min and max and decimals option 1`] = `"63.1019"`; diff --git a/test/modules/commerce.spec.ts b/test/modules/commerce.spec.ts index 9ac013c27b1..e009e93057d 100644 --- a/test/modules/commerce.spec.ts +++ b/test/modules/commerce.spec.ts @@ -19,11 +19,6 @@ describe('commerce', () => { t.describe('price', (t) => { t.it('noArgs') - .it('with min', 50) - .it('with max', undefined, 100) - .it('with min and max', 50, 100) - .it('with min and max and decimals', 50, 100, 4) - .it('with min and max and decimals and symbol', 50, 100, 4, '$') .it('with min option', { min: 42 }) .it('with max option', { max: 1337 }) .it('with min and max option', { min: 50, max: 100 }) @@ -115,21 +110,21 @@ describe('commerce', () => { }); it('should handle negative amounts, but return 0', () => { - const amount = faker.commerce.price(-200, -1); + const amount = faker.commerce.price({ min: -200, max: -1 }); expect(amount).toBeTruthy(); expect(amount, 'the amount should equal 0').toBe('0'); }); it('should handle argument dec', () => { - const price = faker.commerce.price(100, 100, 1); + const price = faker.commerce.price({ min: 100, max: 100, dec: 1 }); expect(price).toBeTruthy(); expect(price, 'the price should equal 100.0').toBe('100.0'); }); it('should handle argument dec = 0', () => { - const price = faker.commerce.price(100, 100, 0); + const price = faker.commerce.price({ min: 100, max: 100, dec: 0 }); expect(price).toBeTruthy(); expect(price, 'the price should equal 100').toBe('100'); @@ -137,7 +132,7 @@ describe('commerce', () => { it('should return decimal values between min and max', () => { const result = faker.helpers.multiple( - () => faker.commerce.price(1, 1.1, 2), + () => faker.commerce.price({ min: 1, max: 1.1, dec: 2 }), { count: 50 } );