npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@danielrlimax/retrofit-js

v1.0.0

Published

A lightweight, self-healing HTTP client wrapper that dynamically repairs API drift and schema mismatches.

Readme

🩹 Retrofit.js

A lightweight, zero-dependency, self-healing HTTP client wrapper that dynamically repairs API drift and schema mismatches in real time.

npm version License Bundle Size


💡 What is Retrofit.js?

Modern applications often depend on third-party APIs that can change unexpectedly. A backend deployment that renames a property from user_id to userId may silently break frontend code and trigger runtime errors such as:

Cannot read properties of undefined

Retrofit.js acts as a protective layer between your application and external APIs.

It intercepts HTTP responses (fetch or Axios) and applies lightweight fuzzy-matching heuristics to automatically remap deviated response keys back to the contract your frontend expects.

This allows applications to remain functional even when API providers introduce minor schema changes.


✨ Features

📦 Ultra Lightweight

  • Zero external dependencies
  • Less than 2KB minified and gzipped

🧠 Intelligent Key Matching

Automatically maps common naming variations:

user_id
user-id
UserID
USER_ID

into:

userId

🛡️ Self-Healing Fallbacks

Injects safe fallback values when expected properties are missing:

| Type | Default Value | | ------- | ------------- | | string | "" | | number | 0 | | boolean | false | | object | {} | | array | [] |

🔌 Universal Adapters

Works seamlessly with:

  • Native Fetch API
  • Axios instances
  • Custom HTTP layers

🌲 Deep Recursive Mapping

Supports:

  • Nested objects
  • Arrays of objects
  • Complex API response trees

🚀 Installation

npm install retrofit-js

Quick Start

1. Global Fetch Interception

Install Retrofit.js once at application startup.

import { hookFetch } from 'retrofit-js';

const userSchema = {
  userId: 'number',
  fullName: 'string',
  preferences: {
    themeMode: 'string'
  }
};

hookFetch({
  expectedSchema: userSchema,
  urlFilter: '/api/v1'
});

Now every matching request is automatically normalized.

const response = await fetch('/api/v1/profile');
const user = await response.json();

console.log(user.userId);
console.log(user.fullName);
console.log(user.preferences.themeMode);

Even if the backend returns:

{
  "user_id": 42,
  "full_name": "John Doe",
  "preferences": {
    "theme_mode": "dark"
  }
}

Your frontend receives:

{
  "userId": 42,
  "fullName": "John Doe",
  "preferences": {
    "themeMode": "dark"
  }
}

2. Axios Integration

For projects using custom Axios instances:

import axios from 'axios';
import { hookAxios } from 'retrofit-js';

const apiClient = axios.create({
  baseURL: 'https://api.domain.com'
});

hookAxios(apiClient, {
  expectedSchema: {
    productId: 'number',
    tags: []
  },
  silent: true
});

All responses passing through the instance will be normalized automatically.


🛠️ Schema Definition

Schemas describe the structure your application expects.

Primitive Types

const schema = {
  userId: 'number',
  fullName: 'string',
  active: 'boolean'
};

Nested Objects

const schema = {
  userId: 'number',
  preferences: {
    themeMode: 'string'
  }
};

Arrays

const schema = {
  tags: [],
  categories: []
};

📊 Architecture

Raw API Response
        │
        ▼
Retrofit.js Interceptor
        │
        ▼
Fuzzy Matching Engine
        │
        ▼
Schema Normalization
        │
        ▼
UI-Ready Application State

⚙️ How It Works

Retrofit.js performs three core operations:

  1. Key Normalization

    • Converts keys into a canonical format.
  2. Similarity Matching

    • Detects equivalent property names using lightweight heuristics.
  3. Fallback Injection

    • Provides safe defaults for missing values.

This process helps applications tolerate minor API contract drift without introducing runtime failures.


📈 Performance

Designed for high-throughput applications:

  • Zero dependencies
  • Minimal memory overhead
  • Recursive traversal optimized for nested structures
  • Sub-millisecond processing for typical API payloads

🤝 Contributing

Contributions are welcome.

You can help by:

  • Reporting bugs
  • Suggesting new features
  • Improving documentation
  • Submitting pull requests

Before opening a pull request, please ensure:

npm run lint
npm test

📄 License

This project is licensed under the MIT License.

See the LICENSE file for details.


👨‍💻 Author

Developed with ❤️ by Daniel de Lima.