Add range() & getRandomString(), and improve quality for getRandomInt() (formaly random()) - #66
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors and extends the random number generation utilities in the codebase. It renames the existing random() function to getRandomInt() for better clarity, adds a new range() utility function for array generation, and introduces getRandomString() for generating pseudo-random alphanumeric strings. Backward compatibility is maintained through a deprecated export of the old random() function name.
Key Changes:
- Renamed
random()togetRandomInt()with improved documentation specifying it generates non-negative integers - Added
range()function to create arrays populated with sequential index values - Added
getRandomString()function to generate random alphanumeric strings of specified length
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/universal/random.ts | Removed old random() function implementation |
| src/universal/get-random-int.ts | New file containing renamed getRandomInt() with improved documentation |
| src/universal/get-random-int.test.ts | Test file for getRandomInt() function |
| src/universal/range.ts | New utility function to generate arrays with sequential index values |
| src/universal/range.test.ts | Test file for range() function |
| src/universal/get-random-string.ts | New utility to generate random alphanumeric strings |
| src/universal/get-random-string.test.ts | Test file for getRandomString() function |
| src/universal.ts | Updated exports with deprecated random() alias and new function exports |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5c8163a to
d3070aa
Compare
c0f8afc to
16e47b6
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
16e47b6 to
c3b6034
Compare
c3b6034 to
29313a0
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b0cec13 to
639c83f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6ae8366 to
21ce3ff
Compare
a25ff5e to
a39cf1e
Compare
75cdbf3 to
5e1c646
Compare
range() & getRandomString(), and imorove quality for getRandomInt() (formaly random())range() & getRandomString(), and improve quality for getRandomInt() (formaly random())
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
src/universal/trim-lines.test.ts:4
- The test name "deindent" doesn't match the function being tested. Since the function has been renamed from
deindenttotrimLinesand the deprecated alias is being removed, the test name should be updated to "trimLines" to maintain consistency.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!Number.isFinite(max) || max < 0) { | ||
| throw new RangeError("max must be a finite, non-negative number"); |
There was a problem hiding this comment.
The validation only checks if max is non-negative, but doesn't validate that it's an integer. The function is documented to return an "integer number" and the implementation uses Math.floor(), but accepting non-integer values for max could lead to unexpected behavior. Consider adding a check like !Number.isInteger(max) to ensure max is an integer, or document that non-integer values are acceptable.
| if (!Number.isFinite(max) || max < 0) { | |
| throw new RangeError("max must be a finite, non-negative number"); | |
| if (!Number.isFinite(max) || !Number.isInteger(max) || max < 0) { | |
| throw new RangeError("max must be a finite, non-negative integer number"); |
| if (!Number.isInteger(length) || length <= 0) { | ||
| throw new Error(`\`length\` must be a natural number, but \`${ length }\` is given.`); |
There was a problem hiding this comment.
Missing test coverage for non-integer length values. The validation on line 11 checks !Number.isInteger(length), but there are no tests verifying that the function throws an error for non-integer values like 5.5 or NaN. Add test cases for these scenarios.
| if (!Number.isFinite(max) || max < 0) { | ||
| throw new RangeError("max must be a finite, non-negative number"); |
There was a problem hiding this comment.
Missing test coverage for the validation logic. The function throws a RangeError when max is negative or not finite, but there are no tests verifying this behavior. Add tests for these edge cases, such as passing negative numbers, NaN, or Infinity.
No description provided.