JSPM

  • Created
  • Published
  • Downloads 6210371
  • Score
    100M100P100Q203796F
  • License MIT

a small library for checking types and throwing exceptions

Package Exports

  • check-types

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 (check-types) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

check-types.coffee

A small coffeescript library for checking types and throwing exceptions.

Build status

Installation

npm install check-types

Usage

Importing the module

JavaScript

var check = require('check-types');

CoffeeScript

check = require 'check-types'

Browser

To call the library in a browser environment, use OneJS or Browserify.

Calling the exported functions

A number of different functions are exported:

quacksLike (thing, duck)

Tests whether an object 'quacks like a duck'. Returns true if the first argument has all of the properties of the second, archetypal argument (the 'duck'). Returns false otherwise. If either argument is not an object, an exception is thrown.

isInstance (thing, prototype)

Returns true if an object is an instance of a prototype, false otherwise.

verifyInstance (thing, prototype, message)

Throws an exception if an object is not an instance of a prototype.

isObject (thing)

Returns true if something is a non-null, non-array object, false otherwise.

verifyObject (thing, message)

Throws an exception unless something is a non-null, non-array object.

isArray (thing)

Returns true something is an array, false otherwise.

verifyArray (thing, message)

Throws an exception unless something is an array.

isFunction (thing)

Returns true if something is function, false otherwise.

verifyFunction (thing, message)

Throws an exception unless something is function.

isUnemptyString (thing)

Returns true if something is a non-empty string, false otherwise.

verifyUnemptyString (thing, message)

Throws an exception unless something is a non-empty string.

isString (thing)

Returns true if something is a string, false otherwise.

verifyString (thing, message)

Throws an exception unless something is a string.

isNumber (thing)

Returns true if something is a number, false otherwise. In this instance, NaN is not considered a number.

verifyNumber (thing, message)

Throws an exception unless something is a number. In this instance, NaN is not considered a number.

Development

Dependencies

The build environment relies on Node.js, NPM, Jake, CoffeeScript, CoffeeLint, Mocha and Chai. Assuming that you already have Node.js and NPM set up, you just need to run npm install to install all of the dependencies as listed in package.json.

Unit tests

The unit tests are in test/check-types.coffee. You can run them with the command npm test or jake jstest.