SKELETON MAPPER
This module provides an easy object mapper from a template skeleton.
Mapping objects
The definition of the function is:
declare
-
source
is an object, or a collection of objects. -
skeleton
is the template to be mapped, its keys should have as value the fields from the source object. If the field is inside an object, you can access it by a dot notation. -
addUndefinedFields
maps the undefined fields inside the result object (usually keys undefined are not given).
Examples
Map an object
; ; ; /* { teamName: "Team 1", image: "shield.jpg", players: [ { name: "Poe", surname: "Doe", }, { name: "John", surname: "Msk", }, ], }*/
Map keys inside keys using dot notation
; ; ; /* { name: "Angel", surname: "Main", roleId: 1, universityName: "University 1", }*/
Map an array and give a different shape as output
; ; ; /* [ { athlete: { name: "Angel", }, university: { name: "University 1", team: { id: 1, name: "Team 1" } } }, { athlete: { name: "Lisa", }, university: { name: "University 2", team: { id: 2, name: "Team 2" } } } ]*/