jemima
v0.2.0Jemima
A naïve little (puddle) duck typing library for Node.js
Installation
Just install with npm install jemima
or add it to your
package.json
.
Usage
You can use Jemima with Node.js (JavaScript or CoffeeScript):
var jemima = require('jemima');
jemima = require 'jemima'
Jemima exposes a few functions to help duck-type:
jemima.hasProperty
This function tests to see whether an object has the specified property. You call it with an object (what we're testing) and a string (the property we're testing for); it will return a boolean value indicating whether the object has the property:
var obj = {foo: 123};
jemima.hasProperty(obj, 'foo'); // true
jemima.hasProperty(obj, 'bar'); // false
jemima.hasProperties
This function tests to see whether an object has the specified properties. You call it with an object (what we're testing) and an array of strings (the properties we're testing for); it will return a boolean value indicating whether the object has all of the properties:
var obj = {foo: 123, bar: 456};
jemima.hasProperties(obj, ['foo', 'bar']); // true
jemima.hasProperties(obj, ['foo', 'baz']); // false
jemima.hasMethod
This function tests to see whether an object has the specified
method – it's similar to hasProperty
but also tests that the
property is a function. You call it with an object (what we're
testing) and a string (the method we're testing for); it will
return a boolean value indicating whether the object has the
method:
var obj = {foo: function () {}, bar: 123};
jemima.hasMethod(obj, 'foo'); // true
jemima.hasMethod(obj, 'bar'); // false
jemima.hasMethods
This function tests to see whether an object has the specified
methods – it's similar to hasProperties
but also tests that
the properties are functions. You call it with an object (what
we're testing) and an array of strings (the methods we're
testing for); it will return a boolean value indicating whether
the object has all of the methods:
var obj = {foo: function () {}, bar: function () {}, baz: 123};
jemima.hasMethods(obj, ['foo', 'bar']); // true
jemima.hasMethods(obj, ['foo', 'baz']); // false
Development
In order to develop Jemima, you'll need to install the following npm modules globally like so:
npm install -g coffee-script
npm install -g jake
And then install development dependencies locally with:
npm install
Once you have these dependencies, you will be able to run the following commands:
jake build
: Build JavaScript from the CoffeeScript source.
jake lint
: Run CoffeeLint on the CoffeeScript source.
jake test
: Run all unit tests.
License
Dual licensed under the MIT or GPL Version 2 licenses.