[go: up one dir, main page]

@christiansandor/transform
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Transform

This module have born to help you transform one object into another.

Example use

If you'd like to transform data from multiple weather APIs, you can write:

const definitionFromOneAPI = {
    base: 'results',
    keys: {
        'coordinates': 'coordinates'
    }
};

const definitionFromOtherAPI = {
    keys: {
        'coordinates': 'weather.coords'
    }
};

const responseBodyFromOneAPI = {
    results: [{
        coordinates: [0, 0]
    }, {
        coordinates: [1, 1]
    }]
};

const responseBodyFromOtherAPI = [{
    weather: {
        coords: [2, 2]
    }
}, {
    weather: {
        coords: [3, 3]
    }
}]

const responses = [].concat(
    ...transform(definitionFromOneAPI, responseBodyFromOneAPI),
    ...transform(definitionFromOtherAPI, responseBodyFromOtherAPI)
);

/* Where responses will be:
    [{
        coordinates: [0, 0]
    }, {
        coordinates: [1, 1]
    }, {
        coordinates: [2, 2]
    }, {
        coordinates: [3, 3]
    }]
*/

Readme

Keywords

none

Package Sidebar

Install

npm i @christiansandor/transform

Repository

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

6.96 kB

Total Files

7

Last publish

Collaborators

  • christiansandor