Socket
Socket
Sign inDemoInstall

rttc

Package Overview
Dependencies
Maintainers
4
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rttc

Runtime type-checking for JavaScript.


Version published
Weekly downloads
111K
increased by5.28%
Maintainers
4
Weekly downloads
 
Created
Source

rttc

Runtime type-checking for JavaScript.

Installation

$ npm install rttc --save

Rules

General
  • null is never allowed.
  • NaN is never allowed.
  • Infinity is never allowed.
  • -Infinity is never allowed.

Legacy Usage

The usage of this module is changing, but backwards compatibility will be maintained up until the first major version bump (v1.0.0). See tests for more details.

rttc.rttc(expectations, inputValues, [options])

Validate and/or coerce a set of input values against a set of expectations (defined as input definitions.)

Two options may be provided:

  • coerce - before failing, attempt to coerce not-quite-right input values to their expected type.
  • base - if an input value is missing, fill in its place in the result to the "base type" (falsy value)
require('rttc').rttc({
  foo: {
    type: 'string',
    required: true
  },
  bar: {
    type: { baz: {name: 'string'} },
    required: false
  }
}, {
  foo: 'hi',
  bar: {
    baz: {
      name: 'Rick'
    }
  }
});
rttc.infer(value)

Infer the type/schema of the provided value.

require('rttc').infer(false);
// => 'boolean'
require('rttc').infer(0);
// => 'number'
require('rttc').infer({
  foo: 'bar'
});
// => { foo: 'string' }
require('rttc').infer({
  foo: 'whatever',
  bar: { baz: true }
});
// => { foo: 'string', bar: { baz: 'boolean' } }
require('rttc').infer([{
  foo: ['bar']
}]);
// => [{ foo: ['string'] }]
require('rttc').infer({
  user: {
    friends: [{
      name: 'Lenny',
      age: 77
    }]
});
// =>
/*
{
  user: {
    friends: [{
      name: 'Lenny',
      age: 77
    }]
}
*/
rttc.types
require('rttc').types;

// =>
/*

{ nan: { is: [Function: isNaN], to: [Function] },
  null: { is: [Function: isNull], to: [Function] },
  undefined:
   { is: [Function: isUndefined],
     to: [Function] },
  bool:
   { is: [Function: isBoolean],
     to: [Function],
     base: false },
  defined: { is: [Function], to: [Function] },
  int:
   { is: [Function],
     to: [Function],
     base: 0 },
  str:
   { is: [Function: isString],
     to: [Function],
     base: '' },
  obj: { is: [Function], to: [Function], base: {} },
  arr:
   { is: [Function: isArray],
     to: [Function],
     base: [] },
  date:
   { is: [Function: isDate],
     to: [Function],
     base: Tue Jan 13 2015 08:58:29 GMT-0800 (PST) },
  number:
   { is: [Function],
     to: [Function],
     base: 0 },
  url:
   { is: [Function: isString],
     to: [Function],
     base: '' },
  email:
   { is: [Function: isString],
     to: [Function],
     base: '' },
  string:
   { is: [Function: isString],
     to: [Function],
     base: '' },
  boolean:
   { is: [Function: isBoolean],
     to: [Function],
     base: false },
  integer:
   { is: [Function],
     to: [Function],
     base: 0 },
  float:
   { is: [Function],
     to: [Function],
     base: 0 } }
*/

Keywords

FAQs

Package last updated on 13 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