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 Pattern4metadata:5 source: https://skillmd.com/skills/intense-visions/js-adapter-pattern6---7# JS Adapter Pattern89> Convert the interface of a class into another interface that clients expect1011## When to Use1213- You need to integrate a third-party library or legacy API whose interface does not match your codebase14- Migrating between API versions where method signatures have changed15- Normalizing data from different sources into a uniform shape1617## Instructions18191. Identify the incompatible interface — e.g., a legacy API returning XML when your code expects JSON.202. Create an adapter class or function that wraps the incompatible object.213. The adapter translates calls from the expected interface to the wrapped object's interface.224. The client code interacts only with the adapter, never with the adapted object directly.2324```javascript25// Legacy API returns { firstName, lastName }26class LegacyUser {27 constructor(data) {28 this.firstName = data.firstName;29 this.lastName = data.lastName;30 }31}3233// Modern code expects { name, email }34class UserAdapter {35 constructor(legacyUser) {36 this.legacyUser = legacyUser;37 }38 get name() {39 return `${this.legacyUser.firstName} ${this.legacyUser.lastName}`;40 }41 get email() {42 return '';43 } // field not available in legacy44}45```46475. For functional adapters, write a transform function: `const adapt = (legacy) => ({ name: legacy.firstName + ' ' + legacy.lastName })`.4849## Details5051The 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.5253**Trade-offs:**5455- Adds an indirection layer — one more thing to maintain and debug56- If the adapted interface changes, the adapter must be updated57- Can mask underlying complexity — callers may not realize they are using a legacy system5859**When NOT to use:**6061- When the interfaces are already compatible — do not add an adapter for consistency's sake62- When a simple data mapping function would suffice — a full adapter class may be overkill63- When you control both interfaces and can change one to match the other6465## Source6667https://patterns.dev/javascript/adapter-pattern6869## Process70711. Read the instructions and examples in this document.722. Apply the patterns to your implementation, adapting to your specific context.733. Verify your implementation against the details and edge cases listed above.7475## Harness Integration7677- **Type:** knowledge — this skill is a reference document, not a procedural workflow.78- **No tools or state** — consumed as context by other skills and agents.7980## Success Criteria8182- The patterns described in this document are applied correctly in the implementation.83- Edge cases and anti-patterns listed in this document are avoided.
Run npx get-skill 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. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. Capability flags: docs only. 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.