Socket
Socket
Sign inDemoInstall

tcomb

Package Overview
Dependencies
0
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tcomb

Type checking for JavaScript


Version published
Weekly downloads
1.1M
decreased by-29.71%
Maintainers
1
Created
Weekly downloads
 

Package description

What is tcomb?

The tcomb npm package is a library for Node.js and the browser which allows you to check the types of JavaScript values at runtime with a simple and concise syntax. It is useful for enforcing type safety, defining domain models, and creating composable and reusable type checkers.

What are tcomb's main functionalities?

Type Checking

This feature allows you to define a structure with specific types and create instances that adhere to those types.

const t = require('tcomb');
const Person = t.struct({ name: t.String, age: t.Number });
const person = Person({ name: 'Giulio', age: 43 });

Function Argument Validation

This feature enables you to validate function arguments to ensure they are of the expected type.

const t = require('tcomb');
function sum(a, b) {
  t.Number(a);
  t.Number(b);
  return a + b;
}
sum(1, 2);

Subtyping

This feature allows you to create subtypes based on existing types with additional constraints.

const t = require('tcomb');
const Positive = t.subtype(t.Number, n => n >= 0);
const positiveNumber = Positive(10);

Refinement

This feature is similar to subtyping but is specifically for refining types to a more specific subset.

const t = require('tcomb');
const Integer = t.refinement(t.Number, n => n % 1 === 0);
const integerNumber = Integer(42);

Enums

This feature allows you to define a set of constants and ensure values match one of those constants.

const t = require('tcomb');
const Role = t.enums({ Admin: 'Admin', User: 'User' });
const userRole = Role('User');

Other packages similar to tcomb

Readme

Source

tcomb is a library for Node.js and the browser which allows you to check the types of JavaScript values at runtime with a simple syntax. It's great for Domain Driven Design and for adding safety to your internal code.

Site and documentation

https://gcanti.github.io/tcomb

Features

  • write complex domain models in a breeze and with a small code footprint
  • easy debugging
  • instances are immutables by default
  • encodes/decodes domain models to/from JSON for free
  • type reflection at runtime

Contributors

License

The MIT License (MIT)

Keywords

FAQs

Last updated on 16 Feb 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc