-
Notifications
You must be signed in to change notification settings - Fork 5
Add helper.ts #75
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
Add helper.ts #75
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,31 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
export function formatString(input: string): string { | ||||||||||||||||||||||||||||||||||||||||||||||||
return input.trim().toLowerCase().replace(/\s+/g, '-'); | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
export function calculateSum(numbers: number[]): number { | ||||||||||||||||||||||||||||||||||||||||||||||||
return numbers.reduce((acc, num) => acc + num, 0); | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
export function isValidEmail(email: string): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||
return emailRegex.test(email); | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
export function debounce<T extends (...args: any[]) => any>( | ||||||||||||||||||||||||||||||||||||||||||||||||
func: T, | ||||||||||||||||||||||||||||||||||||||||||||||||
delay: number | ||||||||||||||||||||||||||||||||||||||||||||||||
): (...args: Parameters<T>) => void { | ||||||||||||||||||||||||||||||||||||||||||||||||
let timeoutId: NodeJS.Timeout; | ||||||||||||||||||||||||||||||||||||||||||||||||
return (...args: Parameters<T>) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
clearTimeout(timeoutId); | ||||||||||||||||||||||||||||||||||||||||||||||||
timeoutId = setTimeout(() => func(...args), delay); | ||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+14
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add input validation for debounce function. The function should validate that export function debounce<T extends (...args: any[]) => any>(
func: T,
delay: number
): (...args: Parameters<T>) => void {
+ if (delay < 0) {
+ throw new Error('Delay must be non-negative');
+ }
let timeoutId: NodeJS.Timeout;
return (...args: Parameters<T>) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => func(...args), delay);
};
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
export function chunk<T>(array: T[], size: number): T[][] { | ||||||||||||||||||||||||||||||||||||||||||||||||
const chunks: T[][] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||
for (let i = 0; i < array.length; i += size) { | ||||||||||||||||||||||||||||||||||||||||||||||||
chunks.push(array.slice(i, i + size)); | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
return chunks; | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+25
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add input validation for chunk function. The function should validate that export function chunk<T>(array: T[], size: number): T[][] {
+ if (size <= 0 || !Number.isInteger(size)) {
+ 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;
} 🤖 Prompt for AI Agents
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove calculateSum function - organizational constraint violation.
According to the organizational documentation, the
calculateSum
function should NOT be included in this file because it already exists elsewhere in the codebase.📝 Committable suggestion
🤖 Prompt for AI Agents