Next Popular Module

    tcomb-doc

    0.5.2 • Public • Published

    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>"
        }
    }

    Install

    npm i tcomb-doc

    DownloadsWeekly Downloads

    11,363

    Version

    0.5.2

    License

    MIT

    Last publish

    Collaborators

    • gcanti