SimpleMapper
SimpleMapper provides simple, object-to-object mapping by convention. It was created to solve the problem of recursively mapping JSON to models, in order to gain the benefits of those models, particularly their methods and default values. However, it can be used to map from Javascript objects of any type, to objects of any type.
Usage
;;
The optional third argument turns on (default) or off warnings about missing destination properties.
Models
Due to the way Typescript works (as of v2.2), you should define your models so they always have default values. Otherwise, their properties will not be visible to the mapper.
Be sure the default values for iterables are empty iterables (both in the source and destination), otherwise the properties will be mapped like ordinary properties.
If providing model names as strings instead of references, then you must provide a model collection during import (see Setup).
If a source property exists while a destination does not, a warning will be issued by default. You can turn this off by providing a third parameter:
;mapper.mapMyWidget, json, false;
Installation
npm install --save-dev simple-mapper
Setup
// if you are using dependency injection, your setup might look like this: ;; ; diContainer.bindMapperServiceToken.toMapperService; // or with configuration... ;diContainer.bindMapperServiceToken.tonew MapperServiceconfig, console;
Options
Build
Run npm run build
to build the project. The build artifacts will be stored in the dist/
directory.
Running unit tests
Run npm test
to execute the unit tests.
Run npm run cover
to run tests and generate a code coverage report.
Code coverage will be available at ./coverage/index.html.
Documentation
The scaffolding exists, but no real documentation, for the moment. Run 'npm run compodoc' to generate documentation. Then run 'npm run compodoc-serve' to see auto-generated documentation and documentation coverage on port 8080.
Further help
Feel free to post issues.