Fork me on GitHub

Supplement.js

JavaScript
Extras

A small collection of utility functions to make working with JavaScript that much sweeter and more expressive.

Responsibly adds extensions to built in types.

Usage

Include the supplement.js source before any JavaScript in which you wish to use the extras.

Supplement.js requires an ECMAScript 5 compliant JavaScript environment. In older browsers you should include augment.js before supplement.js.

Methods

Array
Array.wrap
Wraps the parameter in an array, ensures that the return value is always an array.
Array.prototype.uniq
Returns a new array with all the duplicate elements removed.
Array.range
Returns a new array with elements from the start to the end params.
Array.prototype.detect
Returns the first item from the array for which the function evaluates to true.
Array.toArray
Converts an array–like object into an array.
Array.prototype.head
Returns the first element from an array.
Array.prototype.tail
Returns everything except the head of the array.
Array.prototype.compact
Returns a copy of the array with all undefined or null values removed.
Array.prototype.group
Returns an object where each key is the group name and its value is an array of elements from the array that fits in the group.
Array.prototype.reject
Returns a new array containing items from this array for which the function returns false.
Array.prototype.take
Returns the first n items from the array.
Array.prototype.drop
Drops the first n items from the array and returns the rest.
Array.prototype.pluck
Returns array of values for passed property or method name on each member.
Function
Function.prototype.singleUse
Returns a function which can only be called once.
Function.prototype.curry
Returns a function with one or more arguments already set.
Function.prototype.throttle
Returns a function that will only execute once every n amount of milliseconds.
Function.prototype.debounce
Returns a function that will only execute after it has stopped being called for n milliseconds.
Number
Number.prototype.times
Executes the supplied function n number of times.
Number.prototype.seconds
Returns the number of seconds in milliseconds.
Number.prototype.minutes
Returns the number of minutes in milliseconds.
Number.prototype.hours
Returns the number of hours in milliseconds.
Number.prototype.pad
Returns a string representation of the number with n zeros padding the number.
Object
Object.values
Returns all the enumerable values of an object.
Object.provide
Returns a property of an object which is nested arbitrarily deep within another object.
Object.typeOf
A more robust version of the native typeof command.