New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tcomb-doc

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcomb-doc

Documentation tool for tcomb

  • 0.5.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 03 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc