Remap JS
Give your objects a different shape
Basic usage
Remap an object by passing its structure as a mapping, and its values is a dot-notation string path, or a function.
const remap = remap; const source = id: 'abc123' fname: 'John' lname: 'Doe' age: 20 cellNumber: '555-5555' homeNumber: '555-5556' very: deep: path: 'foo' ; ;
Output:
id: 'abc123' firstName: 'John' lastName: 'Doe' ageDescription: '20 years old' phone: cell: '555-5555' home: '555-5556' noSuchKey: undefined flattenedValue: 'foo'
Advanced Remapping
There are functions for common operations
const remap = remap;const remapArray = remapArray;const remapFrom = remapFrom;const getOr = getOr; const source = friend: list: fname: 'Bob' lname: 'Builder' fname: 'Dora' lname: 'Explorer' myProfile: profilePicture: 'picture.png' nickname: 'nicky' myStatus: 'busy' ;
Output
friends: id: 'bob-1' firstName: 'Bob' lastName: 'Builder' id: 'dora-2' firstName: 'Dora' lastName: 'Explorer' profile: avatar: 'picture.png' alias: 'nicky' status: 'available' messages: