yui-lang.js revision 62e7a7d39cc0c6d25fec20964c26bc35b9fa116a
/**
* Provides the language utilites and extensions used by the library
* @class Lang
*/
/**
* Determines whether or not the provided object is an array.
* Testing typeof/instanceof/constructor of arrays across frame
* boundaries isn't possible in Safari unless you have a reference
* to the other frame to test against its Array prototype. To
* handle this case, we test well-known array properties instead.
* properties.
* @TODO can we kill this cross frame hack?
* @method isArray
* @param {any} o The object being testing
* @return Boolean
*/
L.isArray = function(o) {
if (o) {
//return L.isNumber(o.length) && L.isFunction(o.splice);
}
return false;
};
/**
* Determines whether or not the provided object is a boolean
* @method isBoolean
* @param {any} o The object being testing
* @return Boolean
*/
L.isBoolean = function(o) {
return typeof o === 'boolean';
};
/**
* Determines whether or not the provided object is a function
* @method isFunction
* @param {any} o The object being testing
* @return Boolean
*/
L.isFunction = function(o) {
return typeof o === 'function';
};
/**
* Determines whether or not the supplied object is a date instance
* @method isDate
* @return {boolean} true if it is a date
*/
L.isDate = function(o) {
return o instanceof Date;
};
/**
* Determines whether or not the provided object is null
* @method isNull
* @param {any} o The object being testing
* @return Boolean
*/
L.isNull = function(o) {
return o === null;
};
/**
* Determines whether or not the provided object is a legal number
* @method isNumber
* @param {any} o The object being testing
* @return Boolean
*/
L.isNumber = function(o) {
return typeof o === 'number' && isFinite(o);
};
/**
* Determines whether or not the provided object is of type object
* or function
* @method isObject
* @param {any} o The object being testing
* @param failfn {boolean} fail if the input is a function
* @return Boolean
*/
};
/**
* Determines whether or not the provided object is a string
* @method isString
* @param {any} o The object being testing
* @return Boolean
*/
L.isString = function(o) {
return typeof o === 'string';
};
/**
* Determines whether or not the provided object is undefined
* @method isUndefined
* @param {any} o The object being testing
* @return Boolean
*/
L.isUndefined = function(o) {
return typeof o === 'undefined';
};
/**
* Returns a string without any leading or trailing whitespace. If
* the input is not a string, the input will be returned untouched.
* @method trim
* @param s {string} the string to trim
* @return {string} the trimmed string
*/
L.trim = function(s){
try {
return s.replace(/^\s+|\s+$/g, "");
} catch(e) {
return s;
}
};
/**
* A convenience method for detecting a legitimate non-null value.
* including 0/false/''
* @method isValue
* @param o {any} the item to test
*/
L.isValue = function(o) {
// return (o || o === false || o === 0 || o === ''); // Infinity fails
};
}, "@VERSION@");