From c7ebec3ec809c1b201bb07fe7f7a0a34734aa836 Mon Sep 17 00:00:00 2001
From: Shinigami92 <chrissi92@hotmail.de>
Date: Tue, 12 Mar 2024 10:07:49 +0100
Subject: [PATCH] refactor(number)!: remove v8 deprecated number parameter

---
 src/modules/number/index.ts                   | 41 ++-------
 .../modules/__snapshots__/number.spec.ts.snap |  6 --
 test/modules/number.spec.ts                   | 83 +------------------
 3 files changed, 11 insertions(+), 119 deletions(-)

diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts
index 9e9eb4edcd0..d8d92c59d23 100644
--- a/src/modules/number/index.ts
+++ b/src/modules/number/index.ts
@@ -1,5 +1,4 @@
 import { FakerError } from '../../errors/faker-error';
-import { deprecated } from '../../internal/deprecated';
 import { SimpleModuleBase } from '../../internal/module-base';
 
 /**
@@ -90,13 +89,11 @@ export class NumberModule extends SimpleModuleBase {
    *
    * @param options Upper bound or options object.
    * @param options.min Lower bound for generated number, inclusive. Defaults to `0.0`.
-   * @param options.max Upper bound for generated number, exclusive, unless `multipleOf`, `precision` or `fractionDigits` are passed. Defaults to `1.0`.
-   * @param options.precision Deprecated alias for `multipleOf`. Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
-   * @param options.multipleOf The generated number will be a multiple of this parameter. Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
-   * @param options.fractionDigits The maximum number of digits to appear after the decimal point, for example `2` will round to 2 decimal points.  Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
+   * @param options.max Upper bound for generated number, exclusive, unless `multipleOf` or `fractionDigits` are passed. Defaults to `1.0`.
+   * @param options.multipleOf The generated number will be a multiple of this parameter. Only one of `multipleOf` or `fractionDigits` should be passed.
+   * @param options.fractionDigits The maximum number of digits to appear after the decimal point, for example `2` will round to 2 decimal points.  Only one of `multipleOf` or `fractionDigits` should be passed.
    *
    * @throws When `min` is greater than `max`.
-   * @throws When `precision` is negative.
    * @throws When `multipleOf` is negative.
    * @throws When `fractionDigits` is negative.
    * @throws When `fractionDigits` and `multipleOf` is passed in the same options object.
@@ -125,23 +122,17 @@ export class NumberModule extends SimpleModuleBase {
            */
           min?: number;
           /**
-           * Upper bound for generated number, exclusive, unless `multipleOf`, `precision` or `fractionDigits` are passed.
+           * Upper bound for generated number, exclusive, unless `multipleOf` or `fractionDigits` are passed.
            *
            * @default 1.0
            */
           max?: number;
           /**
-           * The maximum number of digits to appear after the decimal point, for example `2` will round to 2 decimal points.  Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
+           * The maximum number of digits to appear after the decimal point, for example `2` will round to 2 decimal points.  Only one of `multipleOf` or `fractionDigits` should be passed.
            */
           fractionDigits?: number;
           /**
-           * Deprecated alias for `multipleOf`. Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
-           *
-           * @deprecated Use `multipleOf` instead.
-           */
-          precision?: number;
-          /**
-           * The generated number will be a multiple of this parameter. Only one of `multipleOf`, `precision` or `fractionDigits` should be passed.
+           * The generated number will be a multiple of this parameter. Only one of `multipleOf` or `fractionDigits` should be passed.
            */
           multipleOf?: number;
         } = {}
@@ -156,23 +147,10 @@ export class NumberModule extends SimpleModuleBase {
       min = 0,
       max = 1,
       fractionDigits,
-      // eslint-disable-next-line deprecation/deprecation
-      precision,
-      // eslint-disable-next-line deprecation/deprecation
-      multipleOf: originalMultipleOf = precision,
-      multipleOf = precision ??
-        (fractionDigits == null ? undefined : 10 ** -fractionDigits),
+      multipleOf: originalMultipleOf,
+      multipleOf = fractionDigits == null ? undefined : 10 ** -fractionDigits,
     } = options;
 
-    if (precision != null) {
-      deprecated({
-        deprecated: 'faker.number.float({ precision })',
-        proposed: 'faker.number.float({ multipleOf })',
-        since: '8.4',
-        until: '9.0',
-      });
-    }
-
     if (max === min) {
       return min;
     }
@@ -201,8 +179,7 @@ export class NumberModule extends SimpleModuleBase {
 
     if (multipleOf != null) {
       if (multipleOf <= 0) {
-        // TODO @xDivisionByZerox: Clean up in v9.0
-        throw new FakerError(`multipleOf/precision should be greater than 0.`);
+        throw new FakerError(`multipleOf should be greater than 0.`);
       }
 
       const logPrecision = Math.log10(multipleOf);
diff --git a/test/modules/__snapshots__/number.spec.ts.snap b/test/modules/__snapshots__/number.spec.ts.snap
index 49bd667584a..8c3f5cccf2e 100644
--- a/test/modules/__snapshots__/number.spec.ts.snap
+++ b/test/modules/__snapshots__/number.spec.ts.snap
@@ -30,8 +30,6 @@ exports[`number > 42 > float > with min, max and fractionDigits 1`] = `-0.4261`;
 
 exports[`number > 42 > float > with min, max and multipleOf 1`] = `-0.4261`;
 
-exports[`number > 42 > float > with min, max and precision 1`] = `-0.4261`;
-
 exports[`number > 42 > float > with plain number 1`] = `1.49816047538945`;
 
 exports[`number > 42 > hex > noArgs 1`] = `"5"`;
@@ -82,8 +80,6 @@ exports[`number > 1211 > float > with min, max and fractionDigits 1`] = `61.0658
 
 exports[`number > 1211 > float > with min, max and multipleOf 1`] = `61.0658`;
 
-exports[`number > 1211 > float > with min, max and precision 1`] = `61.0658`;
-
 exports[`number > 1211 > float > with plain number 1`] = `3.714080615610337`;
 
 exports[`number > 1211 > hex > noArgs 1`] = `"e"`;
@@ -134,8 +130,6 @@ exports[`number > 1337 > float > with min, max and fractionDigits 1`] = `-12.915
 
 exports[`number > 1337 > float > with min, max and multipleOf 1`] = `-12.9153`;
 
-exports[`number > 1337 > float > with min, max and precision 1`] = `-12.9153`;
-
 exports[`number > 1337 > float > with plain number 1`] = `1.0480987000623267`;
 
 exports[`number > 1337 > hex > noArgs 1`] = `"4"`;
diff --git a/test/modules/number.spec.ts b/test/modules/number.spec.ts
index 43d0bc99dec..475af30d205 100644
--- a/test/modules/number.spec.ts
+++ b/test/modules/number.spec.ts
@@ -23,11 +23,6 @@ describe('number', () => {
         .it('with min', { min: -42 })
         .it('with max', { max: 69 })
         .it('with min and max', { min: -42, max: 69 })
-        .it('with min, max and precision', {
-          min: -42,
-          max: 69,
-          precision: 0.0001,
-        })
         .it('with min, max and fractionDigits', {
           min: -42,
           max: 69,
@@ -238,22 +233,6 @@ describe('number', () => {
         }
       });
 
-      it('provides numbers with a given precision of 0.5 steps', () => {
-        const results = [
-          ...new Set(
-            Array.from({ length: 50 }, () =>
-              faker.number.float({
-                min: 0,
-                max: 1.5,
-                precision: 0.5,
-              })
-            )
-          ),
-        ].sort();
-
-        expect(results).toEqual([0, 0.5, 1, 1.5]);
-      });
-
       it('provides numbers with a given multipleOf of 0.5 steps', () => {
         const results = [
           ...new Set(
@@ -270,22 +249,6 @@ describe('number', () => {
         expect(results).toEqual([0, 0.5, 1, 1.5]);
       });
 
-      it('provides numbers with a given precision of 0.4 steps', () => {
-        const results = [
-          ...new Set(
-            Array.from({ length: 50 }, () =>
-              faker.number.float({
-                min: 0,
-                max: 1.9,
-                precision: 0.4,
-              })
-            )
-          ),
-        ].sort();
-
-        expect(results).toEqual([0, 0.4, 0.8, 1.2, 1.6]);
-      });
-
       it.each(times(100))(
         'provides numbers with an exact fractional digits',
         () => {
@@ -325,57 +288,15 @@ describe('number', () => {
         );
       });
 
-      it('provides numbers with a given precision of 0.2', () => {
-        const results = [
-          ...new Set(
-            Array.from({ length: 50 }, () =>
-              faker.number.float({
-                min: 0,
-                max: 0.4,
-                precision: 0.2,
-              })
-            )
-          ),
-        ].sort();
-
-        expect(results).toEqual([0, 0.2, 0.4]);
-      });
-
-      it.each(times(18))(
-        `provides numbers with an exact precision of 10^-%d`,
-        (exponent) => {
-          for (let i = 0; i < 100; i++) {
-            const actual = faker.number.float({
-              min: 0.5,
-              max: 0.99,
-              precision: 10 ** -exponent,
-            });
-            expect(actual).toBe(Number(actual.toFixed(exponent)));
-          }
-        }
-      );
-
-      it('throws an error for precision 0', () => {
-        expect(() => faker.number.float({ precision: 0 })).toThrow(
-          new FakerError('multipleOf/precision should be greater than 0.')
-        );
-      });
-
       it('throws an error for multipleOf 0', () => {
         expect(() => faker.number.float({ multipleOf: 0 })).toThrow(
-          new FakerError('multipleOf/precision should be greater than 0.')
-        );
-      });
-
-      it('throws an error for negative precision', () => {
-        expect(() => faker.number.float({ precision: -0.01 })).toThrow(
-          new FakerError('multipleOf/precision should be greater than 0.')
+          new FakerError('multipleOf should be greater than 0.')
         );
       });
 
       it('throws an error for negative multipleOf', () => {
         expect(() => faker.number.float({ multipleOf: -0.01 })).toThrow(
-          new FakerError('multipleOf/precision should be greater than 0.')
+          new FakerError('multipleOf should be greater than 0.')
         );
       });