Pattern for functions that accept either a single item or an array. Use when creating CRUD operations, batch processing APIs, or factory functions that should flexibly handle one or many inputs.
The single-or-array-pattern skill is designed for functions that need to accept either a single item or an array of items, providing a flexible interface for various operations. This pattern is particularly beneficial in scenarios such as CRUD operations, batch processing APIs, and factory functions, enabling developers to create more versatile and user-friendly APIs. By allowing both single and multiple inputs, it simplifies the implementation and enhances code maintainability, ensuring that users can work with a consistent interface regardless of the number of items being processed.
You can implement this pattern by checking if the input is an array using Array.isArray() and normalizing it to always handle arrays internally.
Yes, it is compatible with any project where functions need to handle single or multiple items, especially in CRUD and batch processing scenarios.
This pattern is not suitable when single and batch operations have significantly different semantics or return types.
Quick Setup:
.claude/skills/Repository
EpicenterHQ/epicenter