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

checkit

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

checkit

Simple validations for node and the browser.

  • 0.1.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
160K
increased by4.39%
Maintainers
1
Weekly downloads
 
Created

What is checkit?

Checkit is a validation library for JavaScript that allows you to define and enforce rules for your data. It is particularly useful for validating user input in web applications.

What are checkit's main functionalities?

Basic Validation

This feature allows you to define basic validation rules for your data. In this example, the 'name' field must be present and contain only alphabetic characters, while the 'age' field must be present, an integer, and at least 18.

const Checkit = require('checkit');

const rules = new Checkit({
  name: ['required', 'alpha'],
  age: ['required', 'integer', 'min:18']
});

rules.run({ name: 'John', age: 25 })
  .then(validated => console.log('Validated:', validated))
  .catch(err => console.error('Validation failed:', err));

Custom Validation

This feature allows you to define custom validation rules. In this example, a custom rule is added to Checkit's Validator prototype, which checks if the value of 'customField' is 'customValue'.

const Checkit = require('checkit');

Checkit.Validator.prototype.customRule = function(val) {
  if (val !== 'customValue') {
    throw new Error('Value must be customValue');
  }
};

const rules = new Checkit({
  customField: ['customRule']
});

rules.run({ customField: 'customValue' })
  .then(validated => console.log('Validated:', validated))
  .catch(err => console.error('Validation failed:', err));

Asynchronous Validation

This feature allows you to define asynchronous validation rules. In this example, an asynchronous rule is added to Checkit's Validator prototype, which checks if the value of 'asyncField' is 'asyncValue' after a delay.

const Checkit = require('checkit');

Checkit.Validator.prototype.asyncRule = function(val) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      if (val === 'asyncValue') {
        resolve();
      } else {
        reject(new Error('Value must be asyncValue'));
      }
    }, 1000);
  });
};

const rules = new Checkit({
  asyncField: ['asyncRule']
});

rules.run({ asyncField: 'asyncValue' })
  .then(validated => console.log('Validated:', validated))
  .catch(err => console.error('Validation failed:', err));

Other packages similar to checkit

Keywords

FAQs

Package last updated on 12 Jul 2013

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