Normalize your data
with Precision.

Redon Mapper is a lightweight, high-performance utility library for JavaScript designed to solve the perennial problem of normalizing and transforming inconsistent data structures from various RESTful APIs into a single, predictable schema.

High Performance

Optimized reducer-based path drilling ensures minimal overhead even with complex nested objects.

Robust Safety

Built-in error handling and default values prevent your application from crashing due to unexpected API responses.

Schema Evolution

Easily map multiple legacy source keys to a single modern key to maintain compatibility across versions.

Installation

Simply download the redon-mapper.js file and include it in your project via ES Modules.

import { RedonMapper } from './lib/redon-mapper.js';

Basic Usage

Defining a template allows you to pick multiple source keys. The mapper will take the first one that exists.

const template = {
    username: { 
        sourceKeys: ["username", "user", "name"], 
        defaultValue: "Anonymous" 
    }
};

const rawData = { user: "joseph_m" };
const result = RedonMapper.map(rawData, template);
// Result: { username: "joseph_m" }

Real-World Normalization

Based on the One of One test scenario, here is how you handle inconsistent arrays from different API versions:

const apiResponse = [
    { username: "mike_code", regDate: "2024-02-29T11:15:00Z" },
    { user: "user1", registrationDate: "2024-01-15T09:30:00Z" }
];

const template = {
    username: { sourceKeys: ["username", "user", "name"] },
    registeredDate: {
        sourceKeys: ["regDate", "registrationDate"],
        transform: (value) => new Date(value)
    }
};

const data = RedonMapper.map(apiResponse, template);

API Reference

.map(source, template)

The main entry point. Automatically detects if source is an object or an array and applies the appropriate mapping logic.

.getValueByPath(obj, path)

Safely retrieves deep nested values using dot notation (e.g., "user.meta.id").

.setNestedValue(obj, path, value)

Sets a value at a nested path, creating intermediate objects if they don't exist.