https://github.com/tur-nr/node-implements
Utility module for checking if a given object implements a method list or Prototype.
https://github.com/tur-nr/node-implements
Last synced: 4 months ago
JSON representation
Utility module for checking if a given object implements a method list or Prototype.
- Host: GitHub
- URL: https://github.com/tur-nr/node-implements
- Owner: tur-nr
- License: mit
- Created: 2014-10-09T17:34:13.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-09-02T00:43:19.000Z (almost 10 years ago)
- Last Synced: 2024-04-28T11:20:42.103Z (about 1 year ago)
- Language: JavaScript
- Size: 152 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# implements
`implements` is a utility module for checking an `Object` meets a given interface.
[](https://travis-ci.org/tur-nr/node-implements)
### Example
```js
var impl = require('implements');
var instance = [];impl(instance, ['some', 'every']); // true
```## Installation
### Node
To install `implements` in a Node application use npm.
```
$ npm install implements
```### Browser
No tests available for the browser but you may try using it via [webpack](https://github.com/webpack/webpack).
```
$ webpack index.js implements.js
```## Test
To run tests use npm.
```
$ npm install
$ npm test
```## Documentation
### Basic Usage
Interfaces are just a list of method names that `implements` will check for. Pass an `Object` and interface to `implements` like so.
```js
var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter();
var interf = ['on', 'off', 'emit'];impl(emitter, interf); // true
```If no interface is supplied then `implements` will supply return `true`.
```js
impl(emitter); // true
impl(emitter, null); // true
```### Prototypes
Interfaces can also be a constructor `Function`, `implements` will use the function's Prototype as the interface.
```js
impl(emitter, EventEmitter); // true
```## API
#### implements(*<instance>*, *[interface_]*)
## License
[MIT](LICENSE)
Copyright (c) 2014 [Christopher Turner](https://github.com/tur-nr)