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
types.coffee
A small coffeescript library for checking types and throwing exceptions.
Installation
npm install check-types
Import the module using require
, referencing either
the raw coffeescript (src/types.coffee
, 1.8 kb), the
compiled javascript (build/types.js
, 2.8 kb) or
minified javascript (src/types.min.js
1.2 kb).
To call the library in a browser environment, use OneJS or Browserify.
Usage
types.coffee exports a number of different functions:
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.
Development
Dependencies
The build environment relies on Node.js, NPM, Jake,
CoffeeScript, CoffeeLint, Mocha, Chai and UglifyJS.
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/types.coffee
. You can run them
with the command npm test
or jake jstest
.