typescript-mapper
v0.0.6
Published
TypeScript mapper for objects of type A to type B and vice versa
Downloads
5
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:
sourcespecifies the file path of the interfaces for the sourcetargetspecifies the file path of the interfaces for the targetviceVersaboolean field, if set totrueit will create mappers additionally fromtargettosource
Create script in your package.json file
"scripts": {
"generate-mappers": "generate-ts-mappers -c mapping-specification.json -o src/mappers/mappers.ts"
},CLI Props:
-cspecify the location of the json mapping specification-ospecify 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 typescripttypeis not supported.
