⚠️ Since version 1.0.2,ts-mapperizehas been published under@paddlsnamespace. We continue to maintain@witty-servicesnamespace.
npm install @paddls/ts-mapperize
or
npm install @witty-services/ts-mapperize
class A {
a: string;
}
class B {
b: string;
}
class MyMapper {
@Mapper(() => B, [
{target: 'b', source: 'a'}
])
public mapAToB: MapperFn<A, B>;
}
const mapper: MyMapper = new MyMapper();
mapper.mapAToB(new A())
// should return B{ b: '...' }class A {
a: string;
}
class B {
b: string;
}
class MyMapper {
@ArrayMapper(() => B, [
{target: 'b', source: 'a'}
])
public mapAToB: ArrayMapperFn<A, B>;
}
const mapper: MyMapper = new MyMapper();
mapper.mapAToB([new A()])
// should return [B{ b: '...' }]class A {
a: string;
}
class B {
b: string;
}
class MyMapper {
@Mapper(() => B, [
{target: 'b', source: 'a'}
])
public mapAToB: MapperFn<A, B>;
@ArrayMapper('mapAToB')
public mapAToBArray: ArrayMapperFn<A, B>;
}
const mapper: MyMapper = new MyMapper();
mapper.mapAToBArray([new A()])
// should return [B{ b: '...' }]| Argument | Type | Required | Description |
|---|---|---|---|
| source | string, keyof<Input> | false | select from the input, the value to be mapped |
| target | string, keyof<Output> | false | select the destination of the value inside the output object |
| customTransformer | (() => new(...args: any[]) => CustomTransformer<any, any>) | false | use an existing CustomTransformer class |
| transform | (input: any) => any | false | custom function to map value from selected source to target |
| type | () => new(...args: any[]) => any | false | type of the child object |
| params | MapperParamContext<any, any>[] | false | list of mapping information for child object |
To run unit tests and generate coverage with Jest, run :
npm run test