JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q69822F
  • License ISC

Runtime type checking for variable and similar objects.

Package Exports

  • variable-type

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (variable-type) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

variable-type

A simple javascript(less then 1 kb) library, runtime type checking for variable and similar objects. Simplified from prop-types.

Ver Build Status Coverage Status

1. Usage

npm i --save variable-type

Here is an simple example. More you can see in test.js file.

import VT from 'variable-type'; // ES6
var VT = require('variable-type'); // ES5 with npm

// The only API `check`.
VT.check({
  a: true,
  b: 1,
  c: 'str',
  d: function() {},
  e: new Date(),
  f: '1',
  g: {
    h: {
      i: [
        '1',
        2,
        true,
        {
          j: function() {}
        }
      ]
    }
  }
}, VT.shape({
  a: VT.bool,
  b: VT.number,
  c: VT.string,
  d: VT.func,
  e: VT.instanceOf(Date),
  f: VT.oneOf([1, '1']),
  g: VT.shape({
    h: VT.oneOfType([
      VT.shape({
        i: VT.arrayOf(
          VT.oneOfType([
            VT.number,
            VT.string,
            VT.bool,
            VT.shape({
              j: VT.func
            })
          ])
        )
      })
    ])
  })
}); // Then will get true.

2. API & Types

The unique API is check(variable, type). And the library contains Types below:

  • VT.bool
  • VT.func
  • VT.number
  • VT.string
  • VT.object
  • VT.array
  • VT.any
  • VT.instanceOf
  • VT.oneOf
  • VT.oneOfType
  • VT.arrayOf
  • VT.shape

You can all the usage in the test cases file.

If more Types are needed, welcome to send a pull request, or put an issue to me.

3. Test

npm i

npm run test

License

ISC@hustcc.