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