This package has been deprecated

Author message:

light-mapper will no longer be supported use @ht14x/light-mapper

light-mapper

1.1.9 • Public • Published

LightMapper

typescript mapper from object to object

Install

npm install light-mapper

Use

import { Mapping, MappingRequirement, LightMapper } from "light-mapper";

class Target {

    @Mapping({
        requirement: MappingRequirement.REQUIRED,
        from: ['sourceA'],
        transformation: (value: any) => {
            return value + ' transformed by decorator'
        }
    })
    public targetA: string

    @Mapping({
        requirement: MappingRequirement.REQUIRED,
        from: ['sourceB']
    })
    public targetB: string

    @Mapping({
        requirement: MappingRequirement.REQUIRED,
        from: ['sourceC']
    })
    public targetC: string

    @Mapping(MappingRequirement.REQUIRED)
    public targetD: string

}

class Source {
    public sourceA: string = 'to target A'
    public sourceB: string = 'to target B'
}

const mapper = new LightMapper()

const result = mapper
    .transform('targetA', value => value + ' transformed A')
    .transform('targetB', value => value + ' transformed B')
    .replace('targetC', 'replaced C')
    .replace('targetD', 'replaced D')
    .map(Target, new Source())

console.log(result)
/* Output
Target {
  targetA: 'to target A transformed by decorator transformed A',
  targetB: 'to target B transformed B',
  targetC: 'replaced C',
  targetD: 'replaced D' }
*/

Package Sidebar

Install

npm i light-mapper

Weekly Downloads

180

Version

1.1.9

License

MIT

Unpacked Size

31.2 kB

Total Files

26

Last publish

Collaborators

  • hajekj14