README
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]
}]
*/