JavaScript design patterns and architectural best practices.
Provides JavaScript design patterns (Factory, Observer, Strategy, etc.) with ready-to-use code examples. Use when refactoring code, solving architectural problems, or implementing common patterns like event handling, object creation, and validation.
/plugin marketplace add pluginagentmarketplace/custom-plugin-javascript/plugin install javascript-developer-plugin@pluginagentmarketplace-javascriptThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/config.yamlassets/schema.jsonreferences/GUIDE.mdreferences/PATTERNS.mdscripts/validate.pyFactory
function createUser(type) {
const users = {
admin: () => ({ role: 'admin', permissions: ['all'] }),
user: () => ({ role: 'user', permissions: ['read'] })
};
return users[type]?.() ?? users.user();
}
Singleton
class Database {
static #instance;
static getInstance() {
if (!Database.#instance) {
Database.#instance = new Database();
}
return Database.#instance;
}
}
Builder
class QueryBuilder {
#query = { select: '*', from: '', where: [] };
select(fields) { this.#query.select = fields; return this; }
from(table) { this.#query.from = table; return this; }
where(condition) { this.#query.where.push(condition); return this; }
build() { return this.#query; }
}
new QueryBuilder()
.select('name, email')
.from('users')
.where('active = true')
.build();
Module
const Counter = (function() {
let count = 0; // Private
return {
increment: () => ++count,
decrement: () => --count,
get: () => count
};
})();
Facade
class ApiClient {
async getUser(id) {
const response = await fetch(`/api/users/${id}`);
if (!response.ok) throw new Error('Failed');
return response.json();
}
async updateUser(id, data) {
return this.#request('PUT', `/api/users/${id}`, data);
}
#request(method, url, data) {
return fetch(url, {
method,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}).then(r => r.json());
}
}
Decorator
function withLogging(fn) {
return function(...args) {
console.log('Calling:', fn.name, args);
const result = fn.apply(this, args);
console.log('Result:', result);
return result;
};
}
const add = withLogging((a, b) => a + b);
Observer (Pub/Sub)
class EventEmitter {
#events = new Map();
on(event, handler) {
if (!this.#events.has(event)) this.#events.set(event, []);
this.#events.get(event).push(handler);
return () => this.off(event, handler);
}
off(event, handler) {
const handlers = this.#events.get(event) ?? [];
this.#events.set(event, handlers.filter(h => h !== handler));
}
emit(event, data) {
(this.#events.get(event) ?? []).forEach(h => h(data));
}
}
Strategy
const validators = {
email: (v) => /\S+@\S+/.test(v),
phone: (v) => /^\d{10}$/.test(v),
required: (v) => v?.trim().length > 0
};
function validate(value, rules) {
return rules.every(rule => validators[rule]?.(value) ?? true);
}
validate('test@test.com', ['required', 'email']); // true
Command
class CommandManager {
#history = [];
#index = -1;
execute(command) {
command.execute();
this.#history = this.#history.slice(0, this.#index + 1);
this.#history.push(command);
this.#index++;
}
undo() {
if (this.#index >= 0) {
this.#history[this.#index--].undo();
}
}
redo() {
if (this.#index < this.#history.length - 1) {
this.#history[++this.#index].execute();
}
}
}
Composition
const withLogger = (obj) => ({
...obj,
log: (msg) => console.log(`[${obj.name}] ${msg}`)
});
const withValidator = (obj) => ({
...obj,
validate: () => !!obj.value
});
const field = withValidator(withLogger({ name: 'email', value: '' }));
Middleware
function createPipeline(...middlewares) {
return (input) => middlewares.reduce(
(acc, fn) => fn(acc),
input
);
}
const process = createPipeline(
(x) => x.trim(),
(x) => x.toLowerCase(),
(x) => x.replace(/\s+/g, '-')
);
process(' Hello World '); // 'hello-world'
| Pattern | Use When |
|---|---|
| Factory | Multiple similar objects |
| Singleton | Single shared instance |
| Observer | Event-driven communication |
| Strategy | Swappable algorithms |
| Facade | Complex subsystem |
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.