Skip to content

Add range() & getRandomString(), and improve quality for getRandomInt() (formaly random()) - #66

Merged
phanect merged 10 commits into
mainfrom
feat-random-string
Dec 18, 2025
Merged

phanect merged 10 commits into
mainfrom
feat-random-string

Conversation

@phanect

@phanect phanect commented Dec 17, 2025

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() to getRandomInt() 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.

Comment thread src/universal/range.test.ts Outdated
Comment thread src/universal/get-random-string.test.ts Outdated
Comment thread src/universal/pseudo-random-int.ts
Comment thread src/universal/pseudo-random-string.ts Outdated
Comment thread src/universal/get-random-string.ts Outdated
Comment thread src/universal/get-random-int.test.ts Outdated
Comment thread src/universal.ts Outdated
@phanect
phanect force-pushed the feat-random-string branch 2 times, most recently from 5c8163a to d3070aa Compare December 17, 2025 23:26
@phanect
phanect requested a review from Copilot December 17, 2025 23:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/universal/get-random-int.test.ts Outdated
Comment thread src/universal/get-random-int.test.ts Outdated
Comment thread src/universal/get-random-string.test.ts Outdated
Comment thread src/universal/range.test.ts Outdated
Comment thread src/universal/range.test.ts Outdated
Comment thread src/universal/get-random-string.test.ts Outdated
Comment thread src/universal/get-random-string.test.ts Outdated
Comment thread src/universal/get-random-int.test.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/universal/pseudo-random-int.test.ts
Comment thread src/universal/get-random-string.test.ts Outdated
@phanect
phanect force-pushed the feat-random-string branch 5 times, most recently from b0cec13 to 639c83f Compare December 18, 2025 00:11
@phanect
phanect requested a review from Copilot December 18, 2025 00:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/universal/pseudo-random-string.ts Outdated
Comment thread src/universal/get-random-int.ts Outdated
Comment thread src/universal.ts Outdated
Comment thread src/universal/pseudo-random-string.ts
Comment thread src/universal/pseudo-random-string.test.ts Outdated
Comment thread src/universal/pseudo-random-string.test.ts Outdated
Comment thread src/universal/pseudo-random-string.ts Outdated
@phanect
phanect force-pushed the feat-random-string branch 2 times, most recently from 6ae8366 to 21ce3ff Compare December 18, 2025 00:32
@phanect
phanect requested a review from Copilot December 18, 2025 00:50
@phanect
phanect merged commit cfdd74f into main Dec 18, 2025
12 checks passed
@phanect
phanect deleted the feat-random-string branch December 18, 2025 00:52
@phanect phanect changed the title Add range() & getRandomString(), and imorove quality for getRandomInt() (formaly random()) Add range() & getRandomString(), and improve quality for getRandomInt() (formaly random()) Dec 18, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 deindent to trimLines and 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.

Comment on lines +8 to +9
if (!Number.isFinite(max) || max < 0) {
throw new RangeError("max must be a finite, non-negative number");

Copilot AI Dec 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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");

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +12
if (!Number.isInteger(length) || length <= 0) {
throw new Error(`\`length\` must be a natural number, but \`${ length }\` is given.`);

Copilot AI Dec 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +9
if (!Number.isFinite(max) || max < 0) {
throw new RangeError("max must be a finite, non-negative number");

Copilot AI Dec 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants