The Adapter pattern (also called Wrapper) lets classes with incompatible interfaces work together. In JavaScript, this often takes the form of a thin translation layer between an external API and your internal types.
Trade-offs:
Adds an indirection layer — one more thing to maintain and debug
If the adapted interface changes, the adapter must be updated
Can mask underlying complexity — callers may not realize they are using a legacy system
When NOT to use:
When the interfaces are already compatible — do not add an adapter for consistency's sake
When a simple data mapping function would suffice — a full adapter class may be overkill
When you control both interfaces and can change one to match the other
Read the instructions and examples in this document.
Apply the patterns to your implementation, adapting to your specific context.
Verify your implementation against the details and edge cases listed above.
Harness Integration
Type: knowledge — this skill is a reference document, not a procedural workflow.
No tools or state — consumed as context by other skills and agents.
Success Criteria
The patterns described in this document are applied correctly in the implementation.
Edge cases and anti-patterns listed in this document are avoided.
1---2name: js-adapter-pattern3description: JS Adapter Pattern4---5# JS Adapter Pattern67> Convert the interface of a class into another interface that clients expect89## When to Use1011- You need to integrate a third-party library or legacy API whose interface does not match your codebase12- Migrating between API versions where method signatures have changed13- Normalizing data from different sources into a uniform shape1415## Instructions16171. Identify the incompatible interface — e.g., a legacy API returning XML when your code expects JSON.182. Create an adapter class or function that wraps the incompatible object.193. The adapter translates calls from the expected interface to the wrapped object's interface.204. The client code interacts only with the adapter, never with the adapted object directly.2122```javascript23// Legacy API returns { firstName, lastName }24class LegacyUser {25 constructor(data) {26 this.firstName = data.firstName;27 this.lastName = data.lastName;28 }29}3031// Modern code expects { name, email }32class UserAdapter {33 constructor(legacyUser) {34 this.legacyUser = legacyUser;35 }36 get name() {37 return `${this.legacyUser.firstName} ${this.legacyUser.lastName}`;38 }39 get email() {40 return '';41 } // field not available in legacy42}43```44455. For functional adapters, write a transform function: `const adapt = (legacy) => ({ name: legacy.firstName + ' ' + legacy.lastName })`.4647## Details4849The Adapter pattern (also called Wrapper) lets classes with incompatible interfaces work together. In JavaScript, this often takes the form of a thin translation layer between an external API and your internal types.5051**Trade-offs:**5253- Adds an indirection layer — one more thing to maintain and debug54- If the adapted interface changes, the adapter must be updated55- Can mask underlying complexity — callers may not realize they are using a legacy system5657**When NOT to use:**5859- When the interfaces are already compatible — do not add an adapter for consistency's sake60- When a simple data mapping function would suffice — a full adapter class may be overkill61- When you control both interfaces and can change one to match the other6263## Source6465https://patterns.dev/javascript/adapter-pattern6667## Process68691. Read the instructions and examples in this document.702. Apply the patterns to your implementation, adapting to your specific context.713. Verify your implementation against the details and edge cases listed above.7273## Harness Integration7475- **Type:** knowledge — this skill is a reference document, not a procedural workflow.76- **No tools or state** — consumed as context by other skills and agents.7778## Success Criteria7980- The patterns described in this document are applied correctly in the implementation.81- Edge cases and anti-patterns listed in this document are avoided.
Run npx skillmds@latest add intense-visions/js-adapter-pattern in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
JS Adapter Pattern It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Intense-Visions (@intense-visions) published this skill. Their other Agent Skills are listed on their SkillMD profile.