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

credible

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

credible

Unopinionated validation framework for node and the browser.

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

credible

Build Status

Credible is a library for validating objects in node.js or the browser. While it provides several validators out of the box, credible is very unopinionated; mostly, credible simply provides a framework for object validation.

Installation

Credible has one dependency: An A+ promise library, (i.e. bluebird or when.js)

Node.js

$ npm install credible --save

Browser

<script src="/bluebird.js"></script>
<script src="/credible.js"></script>

Example

var person = {
  firstName: '',
  lastName: 'Portes Chaikin'
  email: 'foo'
}

var credible = new Credible({
  firstName: {
    presence: true
  },
  lastName: {
    presence: true
  },
  email: {
    email: true
  }
});

credible.run(person)
  .catch(function(err) {
    console.log(err); // [ 'firstName is required', 'email must be a valid e-mail address' ]
  })

API

var validator = new Credible();

The most straightforward and "built to order" way to get started is by passing an object to the Credible constructor with the properties you'd like to validate and the rules you'd like to validate the property against.

validator.rule()

A variadic function.

validator
  .rule(properties, rule, options)
  .rule(properties, { rule1: options, rule2: options })
  .rule({ property: { rule1: options, rule2: options }, property2: { rule1: options, rule2: options } })
  .rule(fn)

All rules have if, unless, and catch options -- pass functions.

validator
  .if([properties], fn);
  .unless([properties], fn);
  .catch([properties], fn);

| Name | Description | Options | ------------- | ------------- | | length | | | presence | | | operator | | | alpha | | | alphaDash | | | alphaNumeric | | | alphaUnderscore | | | email | | | integer | | | natural | | | naturalNonZero | | | url | |

Keywords

FAQs

Package last updated on 26 Jan 2015

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