Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
supermapper
Advanced tools
mappedData = supermap(dataToMap, keyMapping, opts);
//compile your mapping for much faster runtime
compiledMap = supermap.compile(keyMapping, opts);
mappedData = compiledMap(dataToMap, opts);
const supermap = require('supermapper');
var dataToMap = {
name: "greg",
job: {
type: "programmer",
responsibilities: ["write code", "conference calls"]
}
}
var keyMapping = {
"name": "employee.person.name",
"job.type": "employee.job.title",
"job.responsibilities[0]": "employee.job.skills[0]",
"job.responsibilities[1]": "employee.job.skills[1]",
}
supermap(dataToMap, keyMapping);
//result
// {
// "employee": {
// "person": {
// "name": "greg"
// },
// "job": {
// "title": "programmer",
// "skills": [
// "write code",
// "conference calls"
// ]
// }
// }
// }
var dataToMap = {
name: "greg",
job: {
type: "programmer",
tier: "band 8"
},
}
var keyMapping = {
"name": "employee.person.name",
"job.type": {
key: "employee.job",
compose: (pointer, value, data) => {
return `${data.job.tier} ${value}`
}
},
}
supermap(dataToMap, keyMapping);
//result
// {
// "employee": {
// "person": {
// "name": "greg"
// },
// "job": "band 8 programmer"
// }
// }
var dataToMap = {
name: "greg",
job: {
type: "programmer"
}
}
var keyMapping = {
"name": "employee.person.name",
"job.type": "employee.job",
}
supermap(dataToMap, keyMapping, {
callback: (source, dest, value) => {
return `${value}, awesome`
}
});
//result
// {
// "employee": {
// "person": {
// "name": "greg, awesome"
// },
// "job": "programmer, awesome"
// }
// }
var dataToMap = {
name: "greg",
job: {
type: "programmer"
}
}
var keyMapping = {
"name": "employee.person.name",
"job.type": {
key: "employee.job",
valueMap: {
"programmer": "Engineer",
"_": "Unemployed" //Default Value if not found in map
}
}
}
supermap(dataToMap, keyMapping);
//result
// {
// "employee": {
// "person": {
// "name": "greg"
// },
// "job": "Engineer"
// }
// }
var dataToMap = {
name: "greg",
job: {
type: "programmer"
}
}
var keyMapping = {
"name": "employee.person.name",
"job": {
key: "employee.job",
valueMap: [
[{"type": "programmer"}, {"role": "Engineer"}],
["_", {"role": "Something Else"}], //Default Value if not found in array
]
}
}
supermap(dataToMap, keyMapping);
// {
// "employee": {
// "person": {
// "name": "greg"
// },
// "job": {
// "role": "Engineer"
// }
// }
// }
var dataToMap = {
name: "greg"
}
var keyMapping = {
"name": "person.name",
"height": {
key: "person.height",
default: "N/A"
}
}
supermap(dataToMap, keyMapping);
//result
// {
// "person": {
// "name": "greg",
// "height": "N/A"
// }
// }
var dataToMap = {
name: "greg"
}
var keyMapping = {
"name": {
key: "person.name",
compose: (_, val) => {
return val.replace(/^\w/, c => c.toUpperCase()) //capitalize first name
},
additional: [
"person.firstName",
"person.givenName"
]
},
}
supermap(dataToMap, keyMapping);
//result
// {
// "person": {
// "name": "Greg",
// "firstName": "Greg",
// "givenName": "Greg"
// }
// }
enclose the json pointer in {brackets}
to interpolate the value of the incoming data and use as a key.
var dataToMap = {
job: {
type: "programmer",
responsibilities: ["write code", "conference calls"]
}
}
var keyMapping = {
"job.responsibilities": "{job.type}.skills"
}
supermap(dataToMap, keyMapping);
//result
// {
// "programmer": {
// "skills": [
// "write code",
// "conference calls"
// ]
// }
// }
the each
parameter will iterate over objects in an array and map them
let dataToMap = {
company: {
resources: [
{
firstName: "Greg",
role: "Programmer"
},
{
firstName: "Adam",
role: "Admin"
}
]
}
}
let keyMapping = {
"company.resources" : {
key: "people.employees",
each: {
map: {
firstName: "name",
role: "job"
}
}
}
}
supermap(dataToMap, keyMapping);
// result
// {
// "people": {
// "employees": [
// {
// "name": "Greg",
// "job": "Programmer"
// },
// {
// "name": "Adam",
// "job": "Admin"
// }
// ]
// }
// }
passing a number says to treat the target like an array. passing a +
symbol is like passing a number, but it will append to the array.
var dataToMap = {
people: {
job1: "designer",
job2: "programmer",
job3: "admin"
}
}
var keyMapping = {
"people.job1": "positions[0].job",
"people.job2": "positions[1].job",
"people.job3": "positions[+].job"
}
supermap(dataToMap, keyMapping);
//result
// {
// "positions": [
// {
// "job": "designer"
// },
// {
// "job": "programmer"
// },
// {
// "job": "admin"
// }
// ]
// }
{
writeNull: true | false // (default: false) if the incoming data value is null or undefined, create the key in mapped object
base: Object // rather than creating a new object for the map, pass a mutable object to be altered
}
{
flip: true | false // (default: false) flip the direction of keys and values in mapping
}
FAQs
map any object to any schema.
The npm package supermapper receives a total of 2 weekly downloads. As such, supermapper popularity was classified as not popular.
We found that supermapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.