Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

is-schema

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-schema

Constrain a variable to a schema

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

is-schema

Constrain a variable to a schema


var isSchema = require('is-schema')
  , val = 'hello world'
  , ret
;

ret = isSchema(val, {
    type: 'string'
  , length: {
      between: [5, 15]
  }
  , match: /^[a-zA-Z ]+$/
});

ret.valid;
// true
ret.value;
// 'hello world'

Installation

$ npm install is-schema

Dependencies

  • is-validation
  • fast-apply

API

is-schema uses is-validation to constrain the schema. All methods on is-validation's Chain are available through the schema.

isSchema(val, schema)

  • val - The variable to constrain to a schema
  • schema - The schema object describing what val should be. If schema is a string, it will be treated as the schema's type

The schema type may be one of the following:

  • string
  • number
  • integer
  • float
  • date
  • regExp
  • object

If a schema's property is an object, it will treat it as another schema for val's property:


isSchema({ foo: 5 }, {
    type: 'object'
  , foo: { // constrain `val`'s `foo` property to this schema
      type: number
    , greaterThan: 0
  }
}).valid;
// true

Limitations

  • The order in which the variable is validated / manipulated against the schema cannot be defined. Using the manipulation methods of is-validation may have unexpected results

Keywords

schema constrain

FAQs

Package last updated on 27 Jan 2014

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