Util function

From berkcangumusisik/claude-code-practices · View interactive version

Util function is an AI agent skill from the GitHub repository berkcangumusisik/claude-code-practices. Creates a well-typed, tested utility function from a description

How to use this skill

Skill file

Generate Utility Function

Description: $ARGUMENTS

  1. Check if a similar utility already exists:
grep -rn "export.*function\|export const" src/utils/ src/lib/ src/helpers/ 2>/dev/null | head -20
  1. If a similar one exists, consider extending it instead of creating a new one.
  1. Implement the function:
  1. Write unit tests covering:
  1. Place in the appropriate utils file or create src/utils/<name>.ts.
  1. Add a usage example in JSDoc.

Example output:

/**
 * Chunks an array into smaller arrays of the specified size.
 * @example chunk([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
 */
export function chunk<T>(arr: T[], size: number): T[][] {
  if (size <= 0) return []
  return Array.from({ length: Math.ceil(arr.length / size) }, (_, i) =>
    arr.slice(i * size, i * size + size)
  )
}
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.