JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 30
  • Score
    100M100P100Q71833F
  • License MIT

Package Exports

  • macoolka-type-model
  • macoolka-type-model/lib/Module
  • macoolka-type-model/lib/Module/index.js
  • macoolka-type-model/lib/index.js
  • macoolka-type-model/lib/predicate
  • macoolka-type-model/lib/predicate.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (macoolka-type-model) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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)