npm install automap-js --save
The simplest way to see how it works is to view the inline.html file under the examples folder. Essentially you call the AutoMap.CreateMap to define a mapping between a source entity and a destination entity, giving it a unique string key to represent the mapping. The .forMember function defines which the member / property on the destination entity, and the .mapFrom method defines the source member / property to pull the value from. So you're defining "for this destination entity property, pull it's value from this source entity property". You can however get more complex with your mapping and use the .value, .condition, .ignore. See the examples and documentation below for more information.
For more advanced usage look at the example code in the repo under ./examples/src. Webpack was used to compile the code. The map keys, mapping, and models are all pulled in as separate modules.
An array of MapDef objects that is held in memory.
Defines a mapping between a source type and destination type.
Create MemberMap with destinationProperty and MapDef.
Creates a new MapDef object and sets it in memory, and returns it.
var mapDef = AutoMap.CreateMap('entity1=>entity2');
Uses the supplied mapKey to find the mapping in memory, then sets values on the destination object according to the defined mapping. If no mapping is found for the mapKey, the destination object is returned untouched.
NOTE: If the destination object has properties that do not exist on the source object, they are automatically ignored. Also, if a property was not explicitly mapped, and the destination property is named the exact same name as a source property, it will automatically be mapped.
NOTE: The Map function runs through three steps.