Transform data, the easy way
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Node.js v12 or higher
The project is not published yet, so you will need to clone and install it using the command below.
npm install <folder>
There is a task called test
, so a simple npm run test
should be fine.
data-map
doesn't care from where the data cames, so you are in charge of this task.
Imagine that you have this JSON:
{
"id": 123,
"title": "Introduction to map-data",
"author": {
"name": "John Doe",
"birth": "1991-06-01"
},
"publishedAt": "2020-01-01"
}
You can extract a new JSON from it:
const mapData = require("map-data");
let expression = {
name: "author.name"
};
let newJson = mapData(expression, data); // The data variable can come from wherever you want
Now your result
variable will have this value:
{
"name": "John Doe"
}
Not working with a JSON data source? Provide your own mapFn
. Here is an example to work with cheerio.
const mapData = require("map-data");
const cheerio = require("cheerio");
let expression = {
name: "li.author"
};
let config = {
mapFn: (expr, data) => cheerio(expr, data); // This function will be called every time it needs to evaluate the property's expression
};
let newJson = mapData(expression, data, config);
- NodeJs - Server Environment
- @jvretamero - Idea & Initial work
See also the list of contributors who participated in this project.
This project is licensed under the MIT License
- see the LICENSE.md file for details
This project was inspired by: