macoolka-type-model
v0.3.11
Published
`macoolka-type-model` is a library for define model in TypeScript. It easily build a type contain field and method to your Application. It provide a generation model for type and validition
Downloads
95
Maintainers
Readme
Quick generate type in TypeScript and validition function
macoolka-type-model
is a library for define model in TypeScript.
It easily build a type contain field and method to your Application.
It provide a generation model for type and validition
Table of contents
Installation
To install the stable version:
npm install macoolka-type-model
Consuming macoolka-type-model
Most examples will use the following import syntax:
import { pipe } from 'fp-ts/lib/pipeable'
import { InputModule, ioBuild, typeBuild } from 'macoolka-type-model'
const userModule: InputModule.MModule = {
name: 'User',
interfaces: [{
name: 'User',
fields: [{
name: 'name',
required: true,
}, {
name: 'id',
id: true,
required: true,
}, {
name: 'age',
type: 'int',
}, {
name: 'female',
type: 'boolean'
}, {
name: 'city',
type: {
_kind: 'enum',
values: ['dalian', 'london', 'newyork', 'beijing'],
defaultValue: 'dalian',
},
required: true,
}]
}]
}
pipe(
userModule,
typeBuild({ isInput: true,showDesc:false }),
)
//input type conent
export interface User {
name: string
id: string
age?: number
female?: boolean
city?: 'dalian' | 'london' | 'newyork' | 'beijing'
}
pipe(
userModule,
typeBuild({showDesc:false}),
)
// type content
export interface User {
name: string
id: string
age?: number
female?: boolean
city: 'dalian' | 'london' | 'newyork' | 'beijing'
}
pipe(
userModule,
ioBuild({showDesc:false}),
)
//valid funtion
import * as t from 'macoolka-io'
export const User = t.intersection([
t.type({
name: t.string,
id: t.string,
city: t.withDefault(t.keyof({ dalian: '', london: '', newyork: '', beijing: '' }), 'dalian')
}),
t.partial({
age: t.int,
female: t.boolean
})
])
Documentation
License
The MIT License (MIT)