mongoose-to-typescript

Translate mongoose model to typescript class

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
mongoose-to-typescript
102.1.06 years ago6 years agoMinified + gzip package size for mongoose-to-typescript in KB

Readme

mongoose-to-typescript
It just create typescript classes from mongoose model or schema.\ It works with (MongooseType : TypescriptType):
  • Number : number
  • String : string
  • Boolean : boolean
  • Date : Date
  • Array : Array
  • ObjectID (not id) : Referenced model class
  • ObjectID (id) : string
It assigns default value for each variable (especially classes instances, so you don't have any errors in angular with a damn object being undefined. )

Installation

```bash $ npm install -g mongoose-to-typescript ```

Usage

Model naming convention
The model files must be as follow classNameModel.js (for example AuthorizedWeightCategoryModel.js)
CLI
Generates a typescript class from a mongoose model file: ```bash $ sudo mongoose-to-typescript -p ./models/ -m -o ./output Created AuthorizedWeightCategory.ts Created AutoSinister.ts Created BusinessProvider.ts Created Customer.ts Created Enterprise.ts Created PaymentFrequency.ts Created Person.ts Created Policy.ts Created Position.ts ```
Options
-V, --version - output the version number\ -p, --path <inputPath> - Input directory where your schema or model are\ -m, --model - to translate mongoose model to typescript\ -s, --schema - to translate mongoose schema (not model, light difference) to typescript\ -o, --output <output> - Output directory\
`-h, --help` - output usage information
Available types
- string - number - date - boolean - array - objectId

Rendering

output/Vehicle.ts : ```typescript import VehicleBrand from './VehicleBrand'; import VehicleModel from './VehicleModel'; import Customer from './Customer'; class Vehicle {
public brand : VehicleBrand = VehicleBrand();
public model : VehicleModel = VehicleModel();
public immatriculation : string = "";
public owner : Customer = Customer();
public _id : string = "";
}
```

Licence

Copyright (c) 2018 Thomas Cruveilher Licensed under the MIT license.