Skip to content

feat(utils): add number utilities#21

Merged
maitamdev merged 1 commit intomainfrom
feat/number-utils
Mar 4, 2026
Merged

feat(utils): add number utilities#21
maitamdev merged 1 commit intomainfrom
feat/number-utils

Conversation

@maitamdev
Copy link
Copy Markdown
Owner

@maitamdev maitamdev commented Mar 4, 2026

Number helpers: random, percentage, round, ordinal, range.


Summary by cubic

Added src/utils/numberUtils.ts with common number helpers for random ranges, percentages, rounding, ordinals, and ranges. This standardizes number calculations and reduces duplicate code.

  • New Features
    • randomBetween(min, max): inclusive integer between min and max.
    • percentage(value, total): whole percent; returns 0 if total is 0.
    • roundTo(num, decimals): rounds to a fixed number of decimals.
    • ordinal(n): returns "1st", "2nd", "3rd", etc.
    • range(start, end, step=1): inclusive array from start to end.

Written for commit 496b210. Summary will update on new commits.

Co-authored-by: DHV Team <dhvteam@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dhv-guiding-light Ready Ready Preview, Comment Mar 4, 2026 7:25pm

@maitamdev maitamdev merged commit 153dc05 into main Mar 4, 2026
1 of 3 checks passed
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 4, 2026

Warning

Rate limit exceeded

@maitamdev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 32 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5587cb87-2213-4957-976f-1605455bdb8a

📥 Commits

Reviewing files that changed from the base of the PR and between b3a0753 and 496b210.

📒 Files selected for processing (1)
  • src/utils/numberUtils.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/number-utils

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/utils/numberUtils.ts">

<violation number="1" location="src/utils/numberUtils.ts:20">
P1: `range` can enter an infinite loop and does not handle descending ranges because the loop condition ignores step direction and zero-step input.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

}
export function range(start: number, end: number, step: number = 1): number[] {
const result: number[] = [];
for (let i = start; i <= end; i += step) result.push(i);
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 4, 2026

Choose a reason for hiding this comment

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

P1: range can enter an infinite loop and does not handle descending ranges because the loop condition ignores step direction and zero-step input.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/utils/numberUtils.ts, line 20:

<comment>`range` can enter an infinite loop and does not handle descending ranges because the loop condition ignores step direction and zero-step input.</comment>

<file context>
@@ -0,0 +1,22 @@
+}
+export function range(start: number, end: number, step: number = 1): number[] {
+  const result: number[] = [];
+  for (let i = start; i <= end; i += step) result.push(i);
+  return result;
+}
</file context>
Fix with Cubic

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.

1 participant