add Ox.isError, add tests

This commit is contained in:
rolux 2012-05-30 22:37:23 +02:00
parent 91026a0c77
commit f1ccfa44f4

View file

@ -157,13 +157,24 @@ Ox.isEqual = function(a, b) {
return ret; return ret;
}; };
/*@
Ox.isError <f> Tests if a value is an error
(value) -> <b> True if the value is an error
value <*> Any value
> Ox.isError(new Error())
true
@*/
Ox.isError = function(value) {
return Ox.typeOf(value) == 'error';
};
/*@ /*@
Ox.isFunction <f> Tests if a value is a function Ox.isFunction <f> Tests if a value is a function
(value) -> <b> True if the value is a function (value) -> <b> True if the value is a function
value <*> Any value value <*> Any value
> Ox.isFunction(function() {}) > Ox.isFunction(function() {})
true true
> Ox.isFunction(/ /) > Ox.isFunction(new RegExp())
false false
@*/ @*/
Ox.isFunction = function(value) { Ox.isFunction = function(value) {
@ -262,10 +273,14 @@ Ox.isPrimitive <f> Tests if a value is a primitive (boolean, number or string)
value <*> Any value value <*> Any value
> Ox.isPrimitive(false) > Ox.isPrimitive(false)
true true
> Ox.isPrimitive(null)
true
> Ox.isPrimitive(0) > Ox.isPrimitive(0)
true true
> Ox.isPrimitive('') > Ox.isPrimitive('')
true true
> Ox.isPrimitive()
true
> Ox.isPrimitive([]) > Ox.isPrimitive([])
false false
> Ox.isPrimitive({}) > Ox.isPrimitive({})
@ -281,7 +296,7 @@ Ox.isPrimitive = function(value) {
Ox.isRegExp <f> Tests if a value is a regular expression Ox.isRegExp <f> Tests if a value is a regular expression
(value) -> <b> True if the value is a regular expression (value) -> <b> True if the value is a regular expression
value <*> Any value value <*> Any value
> Ox.isRegExp(/ /) > Ox.isRegExp(new RegExp())
true true
@*/ @*/
Ox.isRegExp = function(value) { Ox.isRegExp = function(value) {
@ -322,8 +337,12 @@ Ox.typeOf <f> Returns the type of a value
'boolean' 'boolean'
> Ox.typeOf(new Date()) > Ox.typeOf(new Date())
'date' 'date'
> Ox.typeOf(new Error())
'error'
> Ox.typeOf(function() {}) > Ox.typeOf(function() {})
'function' 'function'
> Ox.typeOf(window)
'global'
> Ox.typeOf(document.createElement('a')) > Ox.typeOf(document.createElement('a'))
"htmlanchorelement" "htmlanchorelement"
> Ox.typeOf(document.getElementsByTagName('a')) > Ox.typeOf(document.getElementsByTagName('a'))
@ -338,12 +357,16 @@ Ox.typeOf <f> Returns the type of a value
'number' 'number'
> Ox.typeOf({}) > Ox.typeOf({})
'object' 'object'
> Ox.typeOf(/ /) > Ox.typeOf(new RegExp())
'regexp' 'regexp'
> Ox.typeOf('') > Ox.typeOf('')
'string' 'string'
> Ox.typeOf() > Ox.typeOf()
'undefined' 'undefined'
> Ox.typeOf(Math)
'math'
> Ox.typeOf(JSON)
'json'
@*/ @*/
Ox.typeOf = function(value) { Ox.typeOf = function(value) {
return Object.prototype.toString.call(value).slice(8, -1).toLowerCase(); return Object.prototype.toString.call(value).slice(8, -1).toLowerCase();