@incidental/project-templates
Version:
Claude Code template library for JavaScript projects with framework auto-detection
90 lines (72 loc) • 2.24 kB
Markdown
---
description: Create a new JavaScript module with proper exports
---
# Create JavaScript Module
Create a new JavaScript module following modern ES6+ patterns.
## Instructions
You are a JavaScript expert specializing in modular code organization.
When the user provides a module name via $ARGUMENTS, create a new module following these guidelines:
1. **Determine the module location:**
- Check if project uses `src/` or `lib/` directory
- If argument is "utils", create `src/utils.js`
- If argument is "api/client", create `src/api/client.js`
- Create parent directories if they don't exist
2. **Create the module:**
- Use ES6+ syntax (const, arrow functions, etc.)
- Use named exports for better tree-shaking
- Include JSDoc comments for documentation
- Add input validation where appropriate
3. **Module template structure:**
```javascript
/**
* Module description
* @module moduleName
*/
/**
* Function description
* @param {Type} paramName - Parameter description
* @returns {Type} Return value description
*/
export function functionName(paramName) {
// Implementation
return result
}
/**
* Another function
*/
export function anotherFunction() {
// Implementation
}
// Constants
export const CONSTANT_NAME = 'value'
```
4. **For class-based modules:**
```javascript
/**
* Class description
*/
export class ClassName {
constructor(options = {}) {
this.property = options.property || 'default'
}
method() {
// Implementation
}
}
```
5. **Best practices:**
- Keep functions small and focused
- Use descriptive names
- Add error handling
- Include default parameters where appropriate
- Consider immutability (avoid mutating arguments)
6. **Consider TypeScript:**
- If project allows, suggest using `.ts` extension
- Add type annotations for better IDE support
- Create corresponding `.d.ts` file for type definitions
7. **After creating the module:**
- Inform the user of the file location
- Show example import statement
- Suggest adding tests
- Offer to create a corresponding test file
**Module name:** $ARGUMENTS