1.0.2 • Published 3 years ago

fusion-helper-mapper v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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);
1.0.2

3 years ago

1.0.0

3 years ago