Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tcomb-validation

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcomb-validation

General purpose validation library for JavaScript

  • 3.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3M
decreased by-8.75%
Maintainers
1
Weekly downloads
 
Created

What is tcomb-validation?

tcomb-validation is a library for validating JavaScript values with static types. It provides a way to define types and validate data against those types, ensuring that your data conforms to the expected structure.

What are tcomb-validation's main functionalities?

Type Definitions

You can define types using tcomb-validation. In this example, a 'Person' type is defined with 'name' as a string and 'age' as a number.

const t = require('tcomb-validation');

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

const person = Person({ name: 'John Doe', age: 30 });

Validation

tcomb-validation allows you to validate data against defined types. In this example, the validation fails because 'age' is a string instead of a number.

const t = require('tcomb-validation');

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

const result = t.validate({ name: 'John Doe', age: '30' }, Person);
console.log(result.isValid()); // false

Custom Types

You can create custom types using refinements. In this example, a 'Positive' type is defined to ensure the number is greater than zero.

const t = require('tcomb-validation');

const Positive = t.refinement(t.Number, n => n > 0, 'Positive');

const result = t.validate(10, Positive);
console.log(result.isValid()); // true

Other packages similar to tcomb-validation

Keywords

FAQs

Package last updated on 16 Aug 2017

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