包详细信息

tcomb-doc

gcanti52.6kMIT0.5.2

Documentation tool for tcomb

tcomb, documentation, tool

自述文件

Documentation tool for tcomb

API

toObject

Signature

toObject(types: TcombType | Array<TcombType>) => JSON blob / JavaScript object

Example

import t from 'tcomb'
import { toObject } from 'tcomb-doc'

const Person = t.struct({
  name: t.String,
  age: t.maybe(t.Number)
}, 'User')

console.log(JSON.stringify(toObject(Person), null, 2))

Output

{
  "kind": "struct",
  "name": "User",
  "required": true,
  "props": {
    "name": {
      "kind": "irreducible",
      "name": "String",
      "required": true
    },
    "age": {
      "kind": "irreducible",
      "name": "Number",
      "required": false
    }
  }
}

Output format

Irriducible

Source

t.String

Output

{
  "kind": "irreducible",
  "required": true,
  "name": "String",
  "predicate": "<function reference>"
}

Refinement

Source

const Password = t.refinement(t.String, (s) => s.length >= 6, 'Password')

Output

{
  "kind": "refinement",
  "required": true,
  "name": "Password",
  "type": {
    "kind": "irreducible",
    "name": "String",
    "required": true,
    "predicate": "<function reference>"
  },
  "predicate": "<function reference>"
}

Maybe

Source

const MaybeString = t.maybe(t.String)

Output

{
  "kind": "irreducible",
  "required": false,
  "name": "String",
  "predicate": "<function reference>"
}

Enum

Source

const Country = t.enums({
  IT: 'Italy',
  US: 'United States'
}, 'Country')

Output

{
  "kind": "enums",
  "required": false,
  "name": "Country",
  "map": {
    IT: 'Italy',
    US: 'United States'
  }
}

Struct

Source

const Person = t.struct({
  name: t.String,
  age: t.Number
}, 'Person')

Output

{
  "kind": "struct",
  "required": false,
  "name": "Person",
  "props": {
    "name": {
      "kind": "irreducible",
      "required": true,
      "name": "String",
      "predicate": "<function reference>"
    },
    ...
  }
}

List

Source

const Tags = t.list(t.String, 'Tags')

Output

{
  "kind": "list",
  "required": true,
  "name": "Tags",
  "type": {
    "kind": "irreducible",
    "name": "String",
    "required": true,
    "predicate": "<function reference>"
  }
}

Tuple

Source

const Tuple = t.tuple([t.String, t.Number], 'Tuple')

Output

{
  "kind": "tuple",
  "name": "Tuple",
  "required": true,
  "types": [
    {
      "kind": "irreducible",
      "required": true,
      "name": "String",
      "predicate": "<function reference>"
    },
    {
      "kind": "irreducible",
      "required": true,
      "name": "Number",
      "predicate": "<function reference>"
    }
  ]
}

Union

Source

const Union = t.union([t.String, t.Number], 'Union')

Output

{
  "kind": "union",
  "name": "Union",
  "required": true,
  "types": [
    {
      "kind": "irreducible",
      "required": true,
      "name": "String",
      "predicate": "<function reference>"
    },
    {
      "kind": "irreducible",
      "required": true,
      "name": "Number",
      "predicate": "<function reference>"
    }
  ],
  "dispatch": "<function reference>"
}

Dict

Source

const Dict = t.dict(t.String, t.Number, 'Dict')

Output

{
  "kind": "dict",
  "name": "Dict",
  "required": true,
  "domain": {
    "kind": "irreducible",
    "required": true,
    "name": "String",
    "predicate": "<function reference>"
    },
    "codomain": {
      "kind": "irreducible",
      "required": true,
      "name": "Number",
      "predicate": "<function reference>"
    }
}

更新日志

Changelog

Tags:

  • [New Feature]
  • [Bug Fix]
  • [Breaking Change]
  • [Documentation]
  • [Internal]
  • [Polish]
  • [Experimental]

Note: Gaps between patch versions are faulty/broken releases. Note: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.

v0.5.2

  • New Feature
    • add support for default props (tcomb v3.2)

v0.5.1

  • New Feature
    • support tcomb ^3.1.0, fix #6

v0.5.0

Warning. If you don't rely in your codebase on the property maybe(MyType)(undefined) === null this is not a breaking change for you.

  • Breaking Change
    • upgrade to tcomb v3.0.0

v0.4.0

  • Breaking Change
    • upgrade to tcomb v2.5.2, fix #3