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