0.1.0 • Published 10 years ago
implements v0.1.0
implements
implements is a utility module for checking an Object meets a given interface.
Example
var impl = require('implements');
var instance = [];
impl(instance, ['some', 'every']); // trueInstallation
Node
To install implements in a Node application use npm.
$ npm install implementsBrowser
No tests available for the browser but you may try using it via webpack.
$ webpack index.js implements.jsTest
To run tests use npm.
$ npm install
$ npm testDocumentation
Basic Usage
Interfaces are just a list of method names that implements will check for. Pass an Object and interface to implements like so.
var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter();
var interf = ['on', 'off', 'emit'];
impl(emitter, interf); // trueIf no interface is supplied then implements will supply return true.
impl(emitter); // true
impl(emitter, null); // truePrototypes
Interfaces can also be a constructor Function, implements will use the function's Prototype as the interface.
impl(emitter, EventEmitter); // trueAPI
implements(<instance>, interface_)
License
Copyright (c) 2014 Christopher Turner