Agent skill
snippet-manager
Stars
163
Forks
31
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/snippet-manager
SKILL.md
đĻ Snippet Manager Skill
name: snippet-manager description: Manage, organize, and quickly access reusable code snippets
đ¯ Purpose
ā¸ā¸ąā¸ā¸ā¸˛ā¸Ŗ, ā¸ā¸ąā¸ā¸Ŗā¸°āšā¸ā¸ĩā¸ĸā¸, āšā¸Ĩ⏰āšā¸āšā¸˛ā¸ā¸ļ⏠code snippets ā¸ā¸ĩāšāšā¸āšā¸āšā¸ā¸ĸā¸ā¸ĸāšā¸˛ā¸ā¸Ŗā¸§ā¸āšā¸Ŗāšā¸§
đ When to Use
- ā¸āšā¸ā¸ā¸ā¸˛ā¸Ŗ code pattern ā¸ā¸ĩāšāšā¸āšā¸āšā¸ā¸ĸ
- Save code ā¸Ē⏺ā¸Ģā¸Ŗā¸ąā¸āšā¸āšā¸āšā¸ŗ
- Share code ā¸ā¸ąā¸ team
- Build component library
đ§ Snippet Structure
Snippet Format
markdown
## Snippet: {name}
**Tags**: {tag1}, {tag2}
**Language**: {language}
**Category**: {category}
### Description
{what this snippet does}
### Code
```{language}
{code}
Usage
{how to use this snippet}
## đ Snippet Categories
### React Patterns
```typescript
// Custom Hook Template
function useCustomHook<T>(initialValue: T) {
const [value, setValue] = useState<T>(initialValue);
const update = useCallback((newValue: T) => {
setValue(newValue);
}, []);
return { value, update };
}
API Patterns
typescript
// Fetch with Error Handling
async function fetchData<T>(url: string): Promise<T> {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}
Form Patterns
typescript
// React Hook Form + Zod
const schema = z.object({
email: z.string().email('Invalid email'),
password: z.string().min(8, 'Min 8 characters'),
});
type FormData = z.infer<typeof schema>;
function MyForm() {
const { register, handleSubmit, formState: { errors } } = useForm<FormData>({
resolver: zodResolver(schema),
});
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register('email')} />
{errors.email && <span>{errors.email.message}</span>}
<button type="submit">Submit</button>
</form>
);
}
Utility Functions
typescript
// Debounce
function debounce<T extends (...args: any[]) => any>(
func: T,
wait: number
): (...args: Parameters<T>) => void {
let timeout: NodeJS.Timeout;
return (...args: Parameters<T>) => {
clearTimeout(timeout);
timeout = setTimeout(() => func(...args), wait);
};
}
// Throttle
function throttle<T extends (...args: any[]) => any>(
func: T,
limit: number
): (...args: Parameters<T>) => void {
let inThrottle: boolean;
return (...args: Parameters<T>) => {
if (!inThrottle) {
func(...args);
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
}
};
}
đ Snippet Organization
snippets/
âââ react/
â âââ hooks/
â â âââ useDebounce.ts
â â âââ useLocalStorage.ts
â â âââ useFetch.ts
â âââ components/
â âââ LoadingSpinner.tsx
â âââ ErrorBoundary.tsx
âââ utils/
â âââ array.ts
â âââ string.ts
â âââ date.ts
âââ api/
â âââ fetch.ts
â âââ axios.ts
âââ patterns/
âââ singleton.ts
âââ observer.ts
đ§ Quick Access Snippets
Array Utilities
typescript
// Unique values
const unique = [...new Set(array)];
// Group by key
const grouped = array.reduce((acc, item) => {
const key = item[keyField];
(acc[key] = acc[key] || []).push(item);
return acc;
}, {});
// Chunk array
const chunk = (arr, size) =>
Array.from({ length: Math.ceil(arr.length / size) }, (_, i) =>
arr.slice(i * size, i * size + size)
);
String Utilities
typescript
// Capitalize
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
// Truncate
const truncate = (s, length) =>
s.length > length ? s.slice(0, length) + '...' : s;
// Slug
const slug = (s) =>
s.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, '');
Date Utilities
typescript
// Format date
const formatDate = (date) =>
new Intl.DateTimeFormat('th-TH').format(new Date(date));
// Relative time
const relativeTime = (date) => {
const rtf = new Intl.RelativeTimeFormat('th');
const diff = Date.now() - new Date(date).getTime();
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
return rtf.format(-days, 'day');
};
đ Snippet Template
markdown
## {Snippet Name}
**Tags**: #{tag1} #{tag2}
**Created**: {date}
**Updated**: {date}
### Description
{Brief description of what this snippet does}
### Dependencies
- {dependency 1}
- {dependency 2}
### Code
```{language}
{snippet code}
Example Usage
{language}
{example of how to use}
Notes
- {important note 1}
- {important note 2}
## đ Finding Snippets
### By Tag
#react #hook #typescript
### By Category
react/hooks utils/string patterns/singleton
### By Keyword
Search: "debounce" Results: utils/debounce.ts, react/hooks/useDebounce.ts
## â
Snippet Best Practices
- [ ] Clear naming
- [ ] Complete typing
- [ ] Include usage example
- [ ] Add JSDoc comments
- [ ] Keep focused (one purpose)
- [ ] Test before saving
- [ ] Tag appropriately
- [ ] Update when improved
## đ Related Skills
- `code-search` - Find existing snippets
- `code-generation` - Generate new code
- `documentation` - Document snippets
Didn't find tool you were looking for?