rename vars; improved Ox.typeOf patch for Mobile Safari

This commit is contained in:
rolux 2012-05-25 13:00:40 +02:00
parent 2dbb61c103
commit 95bfdf9b4d

View file

@ -6,8 +6,8 @@ Ox.checkType <f> Throws a TypeError if a value is not of a given type
val <*> Any value
type <s|[s]> Type, or array of types
@*/
Ox.checkType = function(val, type) {
if (!Ox.contains(Ox.makeArray(type), Ox.typeOf(val))) {
Ox.checkType = function(value, type) {
if (!Ox.contains(Ox.makeArray(type), Ox.typeOf(value))) {
throw new TypeError();
}
};
@ -19,8 +19,8 @@ Ox.isArguments <f> Tests if a value is an arguments "array"
> Ox.isArguments((function() { return arguments; }()))
true
@*/
Ox.isArguments = function(val) {
return Ox.typeOf(val) == 'arguments';
Ox.isArguments = function(value) {
return Ox.typeOf(value) == 'arguments';
};
/*@
@ -34,8 +34,8 @@ Ox.isArray <f> Tests if a value is an array
> Ox.isArray({0: 0, length: 1})
false
@*/
Ox.isArray = function(val) {
return Ox.typeOf(val) == 'array';
Ox.isArray = function(value) {
return Ox.typeOf(value) == 'array';
};
/*@
@ -45,8 +45,8 @@ Ox.isBoolean <f> Tests if a value is boolean
> Ox.isBoolean(false)
true
@*/
Ox.isBoolean = function(val) {
return Ox.typeOf(val) == 'boolean';
Ox.isBoolean = function(value) {
return Ox.typeOf(value) == 'boolean';
};
/*@
@ -56,8 +56,8 @@ Ox.isDate <f> Tests if a value is a date
> Ox.isDate(new Date())
true
@*/
Ox.isDate = function(val) {
return Ox.typeOf(val) == 'date';
Ox.isDate = function(value) {
return Ox.typeOf(value) == 'date';
};
/*@
@ -67,8 +67,8 @@ Ox.isElement <f> Tests if a value is a DOM element
> Ox.isElement(document.createElement('a'))
true
@*/
Ox.isElement = function(val) {
return Ox.endsWith(Ox.typeOf(val), 'element');
Ox.isElement = function(value) {
return Ox.endsWith(Ox.typeOf(value), 'element');
};
/*@
@ -156,8 +156,8 @@ Ox.isFunction <f> Tests if a value is a function
> Ox.isFunction(/ /)
false
@*/
Ox.isFunction = function(val) {
return Ox.typeOf(val) == 'function';
Ox.isFunction = function(value) {
return Ox.typeOf(value) == 'function';
};
/*@
@ -171,8 +171,8 @@ Ox.isInfinity <f> Tests if a value is positive or negative Infinity
> Ox.isInfinity(NaN)
false
@*/
Ox.isInfinity = function(val) {
return Ox.typeOf(val) == 'number' && !isFinite(val) && !Ox.isNaN(val);
Ox.isInfinity = function(value) {
return Ox.typeOf(value) == 'number' && !isFinite(value) && !Ox.isNaN(value);
};
/*@
@ -184,8 +184,8 @@ Ox.isInt <f> Tests if a value is an integer
> Ox.isInt(0.5)
false
@*/
Ox.isInt = function(val) {
return val === Math.floor(val);
Ox.isInt = function(value) {
return value === Math.floor(value);
};
/*@
@ -195,8 +195,8 @@ Ox.isNaN <f> Tests if a value is NaN
> Ox.isNaN(NaN)
true
@*/
Ox.isNaN = function(val) {
return val !== val;
Ox.isNaN = function(value) {
return value !== value;
}
/*@
@ -206,8 +206,8 @@ Ox.isNull <f> Tests if a value is <code>null</code>
> Ox.isNull(null)
true
@*/
Ox.isNull = function(val) {
return Ox.typeOf(val) == 'null';
Ox.isNull = function(value) {
return Ox.typeOf(value) == 'null';
};
/*@
@ -223,8 +223,8 @@ Ox.isNumber <f> Tests if a value is a number
> Ox.isNumber(NaN)
true
@*/
Ox.isNumber = function(val) {
return Ox.typeOf(val) == 'number';
Ox.isNumber = function(value) {
return Ox.typeOf(value) == 'number';
};
/*@
@ -242,8 +242,8 @@ Ox.isObject <f> Tests if a value is a an object
> Ox.isObject(/ /)
false
@*/
Ox.isObject = function(val) {
return Ox.typeOf(val) == 'object';
Ox.isObject = function(value) {
return Ox.typeOf(value) == 'object';
};
/*@
@ -261,8 +261,8 @@ Ox.isPrimitive <f> Tests if a value is a primitive (boolean, number or string)
> Ox.isPrimitive({})
false
@*/
Ox.isPrimitive = function(val) {
var type = Ox.typeOf(val);
Ox.isPrimitive = function(value) {
var type = Ox.typeOf(value);
return type == 'boolean' || type == 'number' || type == 'string';
};
@ -273,8 +273,8 @@ Ox.isRegExp <f> Tests if a value is a regular expression
> Ox.isRegExp(/ /)
true
@*/
Ox.isRegExp = function(val) {
return Ox.typeOf(val) == 'regexp';
Ox.isRegExp = function(value) {
return Ox.typeOf(value) == 'regexp';
};
/*@
@ -284,8 +284,8 @@ Ox.isString <f> Tests if a value is a string
> Ox.isString('')
true
@*/
Ox.isString = function(val) {
return Ox.typeOf(val) == 'string';
Ox.isString = function(value) {
return Ox.typeOf(value) == 'string';
};
/*@
@ -295,8 +295,8 @@ Ox.isUndefined <f> Tests if a value is undefined
> Ox.isUndefined()
true
@*/
Ox.isUndefined = function(val) {
return Ox.typeOf(val) == 'undefined';
Ox.isUndefined = function(value) {
return Ox.typeOf(value) == 'undefined';
};
/*@
@ -334,9 +334,14 @@ Ox.typeOf <f> Returns the type of a value
> Ox.typeOf()
'undefined'
@*/
Ox.typeOf = function(val) {
// Mobile Safari doesn't like null or undefined here
return val === null ? 'null'
: val === void 0 ? 'undefined'
: Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
Ox.typeOf = function(value) {
return Object.prototype.toString.call(value).slice(8, -1).toLowerCase();
};
if (Ox.typeOf() != 'undefined') {
// Handle Mobile Safari
Ox.typeOf = function(value) {
return value === null ? 'null'
: value === void 0 ? 'undefined'
: Object.prototype.toString.call(value).slice(8, -1).toLowerCase();
};
}