Skip to content

Add helper.ts #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add helper.ts #79

wants to merge 1 commit into from

Conversation

averyjennings
Copy link

@averyjennings averyjennings commented Aug 7, 2025

Summary by CodeRabbit

  • New Features
    • Introduced new utility functions for string formatting, array summing, email validation, debouncing functions, and splitting arrays into chunks.

Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

A new TypeScript helper module was added, introducing five utility functions: string formatting, array summation, email validation, function debouncing, and array chunking. Each function addresses a common utility need and is exported for use in other parts of the codebase.

Changes

Cohort / File(s) Change Summary
Helper Utilities
helper.ts
Introduced five exported functions: formatString, calculateSum, isValidEmail, debounce, and chunk, each providing a distinct utility operation.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant helper.ts

    Caller->>helper.ts: formatString(input)
    helper.ts-->>Caller: formatted string

    Caller->>helper.ts: calculateSum(numbers)
    helper.ts-->>Caller: sum

    Caller->>helper.ts: isValidEmail(email)
    helper.ts-->>Caller: boolean

    Caller->>helper.ts: debounce(func, delay)
    helper.ts-->>Caller: debounced function

    Caller->>helper.ts: chunk(array, size)
    helper.ts-->>Caller: array of chunks
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

🐇 In helper land, new tools arrive,
To trim and sum, and check emails thrive.
Debounce your clicks, chunk arrays with glee,
Five fresh functions, as handy as can be!
With every hop, my code grows bright—
Thanks to helpers, bugs take flight!

Pre-Merge Checks (3 warnings)

❌ Failed Checks (3 warnings)
Check Name Status Explanation Resolution
Title Check ⚠️ Warning The title is too vague and only references the file name without describing what the helper module provides. Revise the title to include details about the added utilities, for example: 'Add helper.ts module with utility functions: formatString, calculateSum, isValidEmail, debounce, and chunk'.
Description Check ⚠️ Warning The pull request description is empty and lacks context, details, and rationale for the changes. Provide a detailed description summarizing the new utility functions, their purpose, usage examples, and consider adding a PR template to the repository for consistency.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch featureBranch2

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
helper.ts (4)

1-3: LGTM! Consider adding input validation for robustness.

The string formatting logic is clean and well-implemented. The function effectively creates URL-friendly strings by normalizing whitespace and casing.

Consider adding input validation to handle edge cases:

 export function formatString(input: string): string {
+  if (!input || typeof input !== 'string') {
+    return '';
+  }
   return input.trim().toLowerCase().replace(/\s+/g, '-');
 }

9-12: Basic email validation is functional but consider enhancement for production.

The regex provides basic email format validation. For production use, consider more comprehensive validation or using established libraries like validator.js.

The current regex doesn't handle edge cases like consecutive dots, leading/trailing dots in local part, etc. Consider using a more robust solution:

 export function isValidEmail(email: string): boolean {
-  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
+  const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
   return emailRegex.test(email);
 }

14-23: Good debounce implementation with minor cross-platform compatibility concern.

The debounce logic is correct and the generic typing preserves function signatures well. Consider the timeout type for cross-platform compatibility.

For better cross-platform compatibility, use number instead of NodeJS.Timeout:

 export function debounce<T extends (...args: any[]) => any>(
   func: T,
   delay: number
 ): (...args: Parameters<T>) => void {
-  let timeoutId: NodeJS.Timeout;
+  let timeoutId: number;
   return (...args: Parameters<T>) => {
     clearTimeout(timeoutId);
     timeoutId = setTimeout(() => func(...args), delay);
   };
 }

25-31: Solid chunk implementation - consider adding input validation.

The chunking logic is efficient and correctly typed. The implementation handles the array slicing properly.

Consider adding input validation for edge cases:

 export function chunk<T>(array: T[], size: number): T[][] {
+  if (!Array.isArray(array) || array.length === 0) {
+    return [];
+  }
+  if (!Number.isInteger(size) || size <= 0) {
+    throw new Error('Size must be a positive integer');
+  }
   const chunks: T[][] = [];
   for (let i = 0; i < array.length; i += size) {
     chunks.push(array.slice(i, i + size));
   }
   return chunks;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef04b8d and 02245f3.

📒 Files selected for processing (1)
  • helper.ts (1 hunks)
🧰 Additional context used
🔍 MCP Research (2 servers)

Linear:

  • Issue ENG-2040 specifies the need to add some TypeScript helper functions in a file called helper.ts but explicitly states that the file should NOT include the calculateSum function because it already exists elsewhere in the codebase. This is directly relevant to reviewing the helper.ts changes in PR #79. (Issue ENG-2040: https://linear.app/coderabbit/issue/ENG-2040/add-typescript-helper-functions)

Notion:

  • Document 23496e76-cda1-80cf-ac92-c22f78edd65b states that the helper.ts file should include some TypeScript helper functions but explicitly should NOT include the calculateSum function because it already exists elsewhere in the codebase. This indicates a team standard or requirement to avoid duplicating the calculateSum function in helper.ts.

Comment on lines +5 to +7
export function calculateSum(numbers: number[]): number {
return numbers.reduce((acc, num) => acc + num, 0);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Remove calculateSum function - violates organizational standards.

According to Issue ENG-2040 and team documentation, the helper.ts file should NOT include the calculateSum function because it already exists elsewhere in the codebase. This violates documented constraints and creates code duplication.

Remove this function entirely:

-export function calculateSum(numbers: number[]): number {
-  return numbers.reduce((acc, num) => acc + num, 0);
-}
-
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function calculateSum(numbers: number[]): number {
return numbers.reduce((acc, num) => acc + num, 0);
}
🤖 Prompt for AI Agents
In helper.ts at lines 5 to 7, remove the entire calculateSum function as it
duplicates existing functionality elsewhere in the codebase, violating
organizational standards and Issue ENG-2040. Delete the function definition
completely to avoid code duplication.

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