fix: restrict {{$randomInt}} output to 0–1000 as per docs (#4847) (#4938)

Previously, `{{$randomInt}}` returned values across the full JavaScript number range.
This commit updates the generator to produce integers between 0 and 1000,
matching the documented behavior.

Fixes #4847
This commit is contained in:
Jungsub Ryoo
2025-07-05 01:03:01 +09:00
committed by GitHub
parent b948e4a26d
commit 795b365df3
3 changed files with 3 additions and 3 deletions

View File

@@ -458,7 +458,7 @@ describe('interpolate - mock variable interpolation', () => {
const result = interpolate(inputString, {});
// Validate the result using regex patterns
const randomIntPattern = /^\d+$/;
const randomIntPattern = /^(?:[0-9]{1,2}|[1-9][0-9]{2}|1000)$/;
const randomIPPattern = /^([\da-f]{1,4}:){7}[\da-f]{1,4}$|^(\d{1,3}\.){3}\d{1,3}$/;
const randomIPV4Pattern = /^(\d{1,3}\.){3}\d{1,3}$/;
const randomIPV6Pattern = /^([\da-f]{1,4}:){7}[\da-f]{1,4}$/;

View File

@@ -25,7 +25,7 @@ describe("mockDataFunctions Regex Validation", () => {
randomNanoId: /^[\w-]{21,}$/,
randomAlphaNumeric: /^[\w]$/,
randomBoolean: /^(true|false)$/,
randomInt: /^\d+$/,
randomInt: /^(?:[0-9]{1,2}|[1-9][0-9]{2}|1000)$/,
randomColor: /^[\w\s]+$/,
randomHexColor: /^#[\da-f]{6}$/,
randomAbbreviation: /^\w{2,6}$/,

View File

@@ -8,7 +8,7 @@ export const mockDataFunctions = {
randomNanoId: () => faker.string.nanoid(),
randomAlphaNumeric: () => faker.string.alphanumeric(),
randomBoolean: () => faker.datatype.boolean(),
randomInt: () => faker.number.int(),
randomInt: () => faker.number.int(1000),
randomColor: () => faker.color.human(),
randomHexColor: () => faker.color.rgb(),
randomAbbreviation: () => faker.hacker.abbreviation(),