0.0.3 • Published 13 years ago
da v0.0.3
Defined Args
A small utility for grabing arguments of a specified type.
Inspired from tblobaum's rconsole's defined method
A simple implementation can be found in substack's defined module.
Usage
Node.js
var da = require('da')Browser
<script src="da.js"></script>Methods
In all methods, type, can be matched against the following built in types: null, undefined, boolean, array, function, date, regexp, number, string, and object. The param is not case sensitive.
first(type, …)
Returns the first argument of the specified type
da.first('string', 1, 2, 'a', 'b') // 'a'
da.first.number('a', 'b', 1, 2) // 1last(type, …)
Returns the last argument of the specified type
da.last('object', 1, null, 'a', {foo: 'bar'}, {}) // {foo: 'bar'}
da.last.boolean(1, 2, true, false) // falsenot(type, …)
Returns the first type that does not match the specified type
da.not('number', 1, 2, 'a', 3) // 'a'
da.not.array([1], [2, 3], undefined, [4]) // undefinedAliases
All top level methods, (first, last, not), have an alias to the built in types checked against.
method.nullmethod.stringmethod.undefinedmethod.numbermethod.functionmethod.booleanmethod.datemethod.regexpmethod.objectmethod.array
Install
With npm
npm install da