Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/DynamicMapper/DynamicMapper
Object to object mapping in JavaScript
https://github.com/DynamicMapper/DynamicMapper
angular javascript javascript-library mapper mapping typescript
Last synced: 4 days ago
JSON representation
Object to object mapping in JavaScript
- Host: GitHub
- URL: https://github.com/DynamicMapper/DynamicMapper
- Owner: DynamicMapper
- License: mit
- Created: 2019-09-17T13:39:06.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-11-10T20:15:37.000Z (about 1 year ago)
- Last Synced: 2024-11-04T01:06:35.578Z (7 days ago)
- Topics: angular, javascript, javascript-library, mapper, mapping, typescript
- Language: TypeScript
- Homepage: https://dynamic-mapper.gitbook.io
- Size: 167 KB
- Stars: 25
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# [DynamicMapper](https://dynamic-mapper.gitbook.io)
[![npm version](https://badge.fury.io/js/%40dynamic-mapper%2Fmapper.svg)](https://badge.fury.io/js/%40dynamic-mapper%2Fmapper)
[![CircleCI](https://circleci.com/gh/DynamicMapper/DynamicMapper/tree/master.svg?style=shield)](https://circleci.com/gh/DynamicMapper/DynamicMapper/tree/master)DynamicMapper is a dependency free library that provides support for object to object mapping to JavaScript
for both browser and node.js environment. Inspired by [AutoMapper](http://docs.automapper.org/en/stable/index.html).For best experience, use DynamicMapper together with [TypeScript](https://github.com/microsoft/TypeScript).
## Installation
`npm i @dynamic-mapper/mapper --save`
## Documentation
Complete documentation available [here](https://dynamic-mapper.gitbook.io).
## Motivation
Take a UI application where data are consumed in a form of `Response DTO` interface that needs to be transformed to `Domain` interface that is
later transformed into a UI view (i.e. Angular Reactive Form value). Modified view then needs to be transformed back to `Domain` and
this updated domain object should be send back to the server in form of `Request DTO`. Pretty tedious to write those mapping in an imperative
way for each individual domain object.![Example](https://raw.githubusercontent.com/DynamicMapper/DynamicMapper/master/docs/diagram.png)
## Usage
```typescript
import { MappingPair, MapperConfiguration } from '@dynamic-mapper/mapper';interface CustomerDto {
firstName: string;
lastName: string;
}interface Customer {
firstName: string;
lastName: string;
fullName: string;
}const CustomerDtoToCustomer = new MappingPair();
const configuration = new MapperConfiguration(cfg => {
cfg.createAutoMap(CustomerDtoToCustomer, {
fullName: opt => opt.mapFrom(src => `${src.firstName} ${src.lastName}`)
});
});const mapper = configuration.createMapper();
const customerDto: CustomerDto = {
firstName: 'John',
lastName: 'Doe'
};const customer = mapper.map(CustomerDtoToCustomer, customerDto);
// {
// firstName: 'John',
// lastName: 'Doe',
// fullName: 'John Doe'
// }
```## Integrations
- [Angular](https://github.com/DynamicMapper/DynamicMapper.Angular)
## License
[MIT](https://choosealicense.com/licenses/mit/)