From fac93cfeee02166c2328b27116f71008d268079d Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Fri, 19 Jan 2024 14:16:09 +0700 Subject: [PATCH 1/7] docs: improve docs for faker.number.float --- docs/guide/upgrading_v9/2472.md | 9 ++++++++ src/modules/number/index.ts | 37 +++++++++++++-------------------- 2 files changed, 24 insertions(+), 22 deletions(-) create mode 100644 docs/guide/upgrading_v9/2472.md diff --git a/docs/guide/upgrading_v9/2472.md b/docs/guide/upgrading_v9/2472.md new file mode 100644 index 00000000000..f4262c327e4 --- /dev/null +++ b/docs/guide/upgrading_v9/2472.md @@ -0,0 +1,9 @@ +### Images now have a random width and height by default + +`faker.image.url()` now returns an image with a random width and height by default. To obtain the previous behavior, pass `{width: 640, height: 480}`. + +`faker.image.urlLoremFlickr()` now returns an image with a random width and height by default. To obtain the previous behavior, pass `{width: 640, height: 480}`. + +`faker.image.urlPicsumPhotos()` now returns an image with a random width and height by default, additionally images may be converted to grayscale and blurred at random. To obtain the previous behavior, pass `{width: 640, height: 480, blur: 0, grayscale: false}` + +`faker.image.dataUri()` now returns an image with a random width and height by default, additionally the type of the image is now random. To obtain the previous behavior, pass `{width: 640, height: 480, type: 'svg-uri'}`. diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts index cb32938220f..596a2755db5 100644 --- a/src/modules/number/index.ts +++ b/src/modules/number/index.ts @@ -86,21 +86,14 @@ export class NumberModule extends SimpleModuleBase { } /** - * Returns a single random floating-point number. - * The lower bound is inclusive, the upper bound is exclusive, unless `multipleOf` is passed. + * Returns a single random floating-point number, by default between `0.0` and `1.0`. To change the range, pass a `min` and `max` value. To limit the number of decimal places, pass a `multipleOf` or `fractionDigits` parameter. * * @param options Upper bound or options object. - * @param options.min Lower bound for generated number. Defaults to `0.0`. - * @param options.max Upper bound for generated number. Defaults to `1.0`. - * @param options.precision Precision of the generated number, for example `0.01` will round to 2 decimal points. - * If precision is passed, the upper bound is inclusive. - * @param options.multipleOf The generated number will be a multiple of this property. - * This property can be used to limit the result to a specific number of decimal digits. - * For example `0.01` will round to 2 decimal points. - * If `multipleOf` is passed, the upper bound is inclusive. - * This option is incompatible with the `fractionDigits` option. - * @param options.fractionDigits The maximum number of digits to appear after the decimal point. - * This option is incompatible with the `multipleOf` option. + * @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. * * @throws When `min` is greater than `max`. * @throws When `precision` is negative. @@ -111,13 +104,14 @@ export class NumberModule extends SimpleModuleBase { * @example * faker.number.float() // 0.5688541042618454 * faker.number.float(3) // 2.367973240558058 - * faker.number.float({ min: -1000000 }) //-780678.849672846 + * faker.number.float({ min: -1000000, max: 0 }) //-780678.849672846 * faker.number.float({ max: 100 }) // 17.3687307164073 - * faker.number.float({ multipleOf: 0.25 }) // 3.75 + * faker.number.float({ multipleOf: 0.25 }) // 0.75 + * faker.number.float({ multipleOf: 0.25, min: 0, max:10 }) // 7.75 * faker.number.float({ fractionDigits: 1 }) // 0.9 * faker.number.float({ min: 10, max: 100, multipleOf: 0.02 }) // 35.42 * faker.number.float({ min: 10, max: 100, fractionDigits: 3 }) // 65.716 - * + * faker.number.float({ min: 10, max: 100, multipleOf: 0.001 }) // 65.716 - same as above * @since 8.0.0 */ float( @@ -125,30 +119,29 @@ export class NumberModule extends SimpleModuleBase { | number | { /** - * Lower bound for generated number. + * Lower bound for generated number, inclusive. Defaults to `0.0`. * * @default 0.0 */ min?: number; /** - * Upper bound for generated number. + * exclusive, unless `multipleOf`, `precision` or `fractionDigits` are passed. Defaults to `1.0`. * * @default 1.0 */ max?: number; /** - * The number of digits to appear after the decimal point. + * 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. */ fractionDigits?: number; /* - * Precision of the generated 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 property. - * If multipleOf is passed, the upper bound is inclusive. + * The generated number will be a multiple of this parameter. Only one of `multipleOf`, `precision` or `fractionDigits` should be passed. */ multipleOf?: number; } = {} From eff78406e4258a0363a2d9d230bde8a09dafff80 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Fri, 19 Jan 2024 14:18:42 +0700 Subject: [PATCH 2/7] revert accidental commit --- docs/guide/upgrading_v9/2472.md | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 docs/guide/upgrading_v9/2472.md diff --git a/docs/guide/upgrading_v9/2472.md b/docs/guide/upgrading_v9/2472.md deleted file mode 100644 index f4262c327e4..00000000000 --- a/docs/guide/upgrading_v9/2472.md +++ /dev/null @@ -1,9 +0,0 @@ -### Images now have a random width and height by default - -`faker.image.url()` now returns an image with a random width and height by default. To obtain the previous behavior, pass `{width: 640, height: 480}`. - -`faker.image.urlLoremFlickr()` now returns an image with a random width and height by default. To obtain the previous behavior, pass `{width: 640, height: 480}`. - -`faker.image.urlPicsumPhotos()` now returns an image with a random width and height by default, additionally images may be converted to grayscale and blurred at random. To obtain the previous behavior, pass `{width: 640, height: 480, blur: 0, grayscale: false}` - -`faker.image.dataUri()` now returns an image with a random width and height by default, additionally the type of the image is now random. To obtain the previous behavior, pass `{width: 640, height: 480, type: 'svg-uri'}`. From 7dbcafca144290f81b86d2afe4fe9d34d4256931 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Fri, 19 Jan 2024 14:19:24 +0700 Subject: [PATCH 3/7] fix missing txt --- src/modules/number/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts index 596a2755db5..6c54bd0232d 100644 --- a/src/modules/number/index.ts +++ b/src/modules/number/index.ts @@ -125,7 +125,7 @@ export class NumberModule extends SimpleModuleBase { */ min?: number; /** - * exclusive, unless `multipleOf`, `precision` or `fractionDigits` are passed. Defaults to `1.0`. + * Upper bound for generated number, exclusive, unless `multipleOf`, `precision` or `fractionDigits` are passed. Defaults to `1.0`. * * @default 1.0 */ From 26e42863d1f3ec800b51786731da251579fc3bfd Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Fri, 19 Jan 2024 14:23:55 +0700 Subject: [PATCH 4/7] fix lint error --- src/modules/number/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts index 6c54bd0232d..6c3fc70750a 100644 --- a/src/modules/number/index.ts +++ b/src/modules/number/index.ts @@ -112,6 +112,7 @@ export class NumberModule extends SimpleModuleBase { * faker.number.float({ min: 10, max: 100, multipleOf: 0.02 }) // 35.42 * faker.number.float({ min: 10, max: 100, fractionDigits: 3 }) // 65.716 * faker.number.float({ min: 10, max: 100, multipleOf: 0.001 }) // 65.716 - same as above + * * @since 8.0.0 */ float( From a982b707c5fcc10d5b68ed50bca43fd2bf79451e Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:41:57 +0700 Subject: [PATCH 5/7] Update src/modules/number/index.ts Co-authored-by: ST-DDT --- src/modules/number/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts index 6c3fc70750a..3ef570c6888 100644 --- a/src/modules/number/index.ts +++ b/src/modules/number/index.ts @@ -120,7 +120,7 @@ export class NumberModule extends SimpleModuleBase { | number | { /** - * Lower bound for generated number, inclusive. Defaults to `0.0`. + * Lower bound for generated number, inclusive. * * @default 0.0 */ From 29b0f3caa4facafaaf26ffd0fee98a2e30fcddea Mon Sep 17 00:00:00 2001 From: Matt Mayer <152770+matthewmayer@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:42:04 +0700 Subject: [PATCH 6/7] Update src/modules/number/index.ts Co-authored-by: ST-DDT --- src/modules/number/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts index 3ef570c6888..cbf742c1401 100644 --- a/src/modules/number/index.ts +++ b/src/modules/number/index.ts @@ -126,7 +126,7 @@ export class NumberModule extends SimpleModuleBase { */ min?: number; /** - * Upper bound for generated number, exclusive, unless `multipleOf`, `precision` or `fractionDigits` are passed. Defaults to `1.0`. + * Upper bound for generated number, exclusive, unless `multipleOf`, `precision` or `fractionDigits` are passed. * * @default 1.0 */ From 6e4fb140aa56bfac30718fb6347a903598ebbd97 Mon Sep 17 00:00:00 2001 From: Matt Mayer Date: Fri, 19 Jan 2024 15:45:15 +0700 Subject: [PATCH 7/7] a more normal min/max example --- src/modules/number/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modules/number/index.ts b/src/modules/number/index.ts index cbf742c1401..b4137ccebe5 100644 --- a/src/modules/number/index.ts +++ b/src/modules/number/index.ts @@ -104,9 +104,8 @@ export class NumberModule extends SimpleModuleBase { * @example * faker.number.float() // 0.5688541042618454 * faker.number.float(3) // 2.367973240558058 - * faker.number.float({ min: -1000000, max: 0 }) //-780678.849672846 * faker.number.float({ max: 100 }) // 17.3687307164073 - * faker.number.float({ multipleOf: 0.25 }) // 0.75 + * faker.number.float({ min: 20, max: 30 }) // 23.94764115102589 * faker.number.float({ multipleOf: 0.25, min: 0, max:10 }) // 7.75 * faker.number.float({ fractionDigits: 1 }) // 0.9 * faker.number.float({ min: 10, max: 100, multipleOf: 0.02 }) // 35.42