# @paddls/ts-mapperize

> Typescript mapping library

Latest version **1.0.3** (published 2022-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @paddls/ts-mapperize
pnpm add @paddls/ts-mapperize
yarn add @paddls/ts-mapperize
bun add @paddls/ts-mapperize
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-02-15 |
| First published | 2022-02-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Romain Martineau |
| Maintainers | corentin.langlais, oguerin, rmartineau, thomasnisole |

## Links

- npm: https://www.npmjs.com/package/@paddls/ts-mapperize
- Repository: http://github.com/paddls/ts-mapperize
- npm.io page: https://npm.io/package/@paddls/ts-mapperize

## Recent versions

- 1.0.3 (latest) — 2022-02-15
- 1.0.3-rc.0 — 2022-02-15
- 1.0.2 — 2022-02-10
- 1.0.2-rc.0 — 2022-02-10

## README

# TS-Mapperize

![ts-mapperize-ci](https://github.com/paddls/ts-mapperize/workflows/ts-mapperize-build/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/paddls/ts-mapperize/badge.svg?branch=master)](https://coveralls.io/github/paddls/ts-mapperize?branch=master)
[![npm version](https://badge.fury.io/js/%40paddls%2Fts-mapperize.svg)](https://badge.fury.io/js/%40paddls%2Fts-mapperize)
![GitHub](https://img.shields.io/github/license/paddls/ts-mapperize)
![GitHub repo size](https://img.shields.io/github/repo-size/paddls/ts-mapperize)
![GitHub last commit](https://img.shields.io/github/last-commit/paddls/ts-mapperize)
![GitHub issues](https://img.shields.io/github/issues/paddls/ts-mapperize)
![GitHub top language](https://img.shields.io/github/languages/top/paddls/ts-mapperize)

## Informations

> :warning: Since version 1.0.2, ```ts-mapperize``` has been published under ```@paddls``` namespace. We continue to maintain ```@witty-services``` namespace.

# Get Started

## Install

```
npm install @paddls/ts-mapperize
```
or
```
npm install @witty-services/ts-mapperize
```

## Create simple mapper

```typescript
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: '...' }
```

## Working with array

### Define all mapping behavior

```typescript
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: '...' }]
```

### Reuse behavior from function

```typescript
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: '...' }]
```

## API

### MapperParamContext

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](TODO) 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

## How to run Unit Tests

To run unit tests and generate coverage with Jest, run :

```
npm run test
```

---
_Source: https://npm.io/package/@paddls/ts-mapperize · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
