2.0.0 • Published 3 years ago

@zcong/ts-mongoose-code-generator v2.0.0

Weekly downloads
54
License
MIT
Repository
-
Last release
3 years ago

ts-mongoose-code-generator

NPM version NPM downloads CircleCI codecov

generate ts model types from mongoose schema

Install

$ yarn add @zcong/ts-mongoose-code-generator

Usage

modelGenerator

import { ModelGenerator } from '@zcong/ts-mongoose-code-generator'

const testSchema = new Schema({
  name: String,
  age: {
    type: Number
  },
  requiredName: {
    type: String,
    required: true
  }
}

// useInterface: use class or interface as type declaration
const dtoGen = new ModelGenerator({
  filename: `${__dirname}/modelGen.ts`,
  useInterface: true, // use interface type or class type
  arrayStyle: 'squareBrackets', // arrayStyle squareBrackets(T[]) or generic(Array<T>)
  stringEnumUseUnionType: true, // if set true, String type with enum field ['test1', 'test2'] will be type `'test1' | 'test2'`
})
dtoGen.generateModelBySchema(testSchema, 'Test')
dtoGen.getFile().saveSync() // save generated code as file
dtoGen.getGeneratedCode() // get generated code content

// export interface TestModel {
//   name?: string;
//   age?: number;
//   requiredName: string;
// }

License

MIT © zcong1993

2.0.0

3 years ago

2.0.0-beta.0

3 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.9.0

4 years ago

0.8.2

4 years ago

0.7.5

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago