(function(){
/**
* @alias JSCore
* JavaScript Core Utility Functions
*/
var JSCore = window.JSCore = (JSCore || {});
/**
* @alias JSCore.forEach
* Iterates through an Iterable. Nothing is done if the object is not iterable.
* @param {Object} value
* @param {Functipn} callback
* @return {Object} the value specified originally
*/
JSCore.forEach = function forEach(value, callback) {
if (typeof value.forEach == 'function')
value.forEach(callback);
else if (typeof value.length == 'number')
for (var i = 0, l = value.length; i < l; ++i)
callback(value[i]);
return value;
};
/**
* @alias JSCore.isArray
* Returns whether or not the value specified is an Array
* @param {Object} [value]
* @return {Boolean}
*/
JSCore.isArray = function isArray(value) {
return value instanceof Array;
};
/**
* @alias JSCore.isBoolean
* Returns whether or not the value specified is a Boolean (true or false)
* @param {Object} [value]
* @return {Boolean}
*/
JSCore.isBoolean = function isBoolean(value) {
return value === true || value === false;
};
/**
* @alias JSCore.isBoolean
* Returns whether or not the value specified is a Function
* @param {Object} [value]
* @return {Boolean}
*/
JSCore.isFunction = function isFunction(value) {
return value instanceof Function;
};
/**
* @alias JSCore.isInteger
* Returns whether or not the value specified is an integer
*
* @param {Object} [value]
* @return {Boolean}
*/
JSCore.isInteger = function isInteger(value) {
return Math.floor(value) == value;
};
/**
* @alias JSCore.isIterable
* Returns whether or not the value can be iterated using JSCore.forEach.
* The following is supported:
*
ArrayObject's that have a numerical length property and accessible elementsObject's that have a pre-defined forEach methodisIterable method, and their own forEach
* that also checks for implementations of the JSOOP.Generic.Iterable interface.
* For developers using JSOOP, it is preferable to use their methods
* @param {Object} [value]
* @return {Boolean}
*/
JSCore.isIterable = function isIterable(value) {
return value &&
(JSCore.isArray(value) || typeof value.length == 'number' || typeof value.forEach == 'function');
};
/**
* @alias JSCore.isObject
* Returns whether or not the value specified is an Object. Warning - This will return
* as false if the type is Array or null; object in this sense means a plain old
* javascript object, not necessarily anything that inherits of Object... because everything does.
*
* @param {Object} [value]
* @return {Boolean}
*/
JSCore.isObject = function isObject(value) {
return JSCore.typeOf(value) == 'object';
};
/**
* @alias JSCore.isNumber
* Returns whether or not the value specified is a number
*
* @param {Object} [value]
* @return {Boolean}
*/
JSCore.isNumber = function isNumber(value) {
return typeof value == 'number';
};
/**
* @alias JSCore.toArray
* Always returns an Array object, regardless of input.
* The following rules are used:
* value is of type Array: Returns a shallow clone of valuevalue is of type Object, but is iterable; that is, has a dynamically allocated
* length property, and accessible nodes via the bracket index bracket syntax: Returns the value
* transformed into an Arrayvalue is of type null or undefined: A blank array is returnedvalue is returnedtypeof function, which can return the following:
*