typescript-mapper
v0.0.6
Published
TypeScript mapper for objects of type A to type B and vice versa
Downloads
27
Readme
TypeScript Mapper
A tool used for generating mapping functions between two typescript
interfaces
Install
npm i -D typescript-mapper
Usage
Create a json file which specifies the source
and target
files of the interfaces which we want to generate mapper functions
For example, for a file mapping-specification.json
Inside the structure should look like:
[
{
"source": "src/model/Models.ts",
"target": "src/view-model/ViewModels.ts",
"viceVersa": true
},
{
"source": "src/model/SecondModel.ts",
"target": "src/view-model/SecondViewModel.ts",
"viceVersa": true
}
]
The properties:
source
specifies the file path of the interfaces for the sourcetarget
specifies the file path of the interfaces for the targetviceVersa
boolean field, if set totrue
it will create mappers additionally fromtarget
tosource
Create script in your package.json
file
"scripts": {
"generate-mappers": "generate-ts-mappers -c mapping-specification.json -o src/mappers/mappers.ts"
},
CLI Props:
-c
specify the location of the json mapping specification-o
specify the location of the output file where the mapper functions will be places (has to be .ts)
Run the script npm run generate-mappers
to generate file with the mapping functions
[!IMPORTANT] The mappers are generated only for exported
interface
. Currently the typescripttype
is not supported.