macoolka-type-model
`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
Last updated 6 months ago by fastspeeed .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install macoolka-type-model 
SYNC missed versions from official npm registry.

build status dependency status npm downloads

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)

Current Tags

  • 0.3.2                                ...           latest (6 months ago)

8 Versions

  • 0.3.2                                ...           6 months ago
  • 0.3.1                                ...           7 months ago
  • 0.3.0                                ...           a year ago
  • 0.2.4                                ...           a year ago
  • 0.2.3                                ...           a year ago
  • 0.2.2                                ...           a year ago
  • 0.2.1                                ...           a year ago
  • 0.2.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (6)
Dev Dependencies (12)

Copyright 2014 - 2016 © taobao.org |