1.0.2 • Published 3 years ago
fusion-helper-mapper v1.0.2
Fusion Helper Mapper
This package is similar to the c# package, automapper. It is a toned down version that does some very specific mapping for typescript/javascript objects.
Installation
npm i -S fusion-helper-mapper
Usage
import {mapper} from "fusion-helper-mapper"
const oldType = {id: 1, name: "fusion"};
const newType = {id: 1, name: ""};
const newType = mapper.map<NewType>(oldType);
Using IMapConfig
import {mapper, IMapConfig} from "fusion-helper-mapper"
const oldType = {id: 1, name: "fusion"};
const newType = {primaryKey: 1, theName: ""};
const mapConfig: Array<IMapConfig> = [
{
key: primaryKey,
value: oldType.id
},
{
key: theName,
value: oldType.name
}
]
const newType = mapper.map<newType>(oldType, mapConfig);
// you can also use functions to map values
const mapConfig: Array<IMapConfig> = [
{
key: primaryKey,
value: oldType.id
},
{
key: theName,
valueMethod: () => {return oldType.name + ' the name '}
}
]
const newType = mapper.map<newType>(oldType, mapConfig);