From f1ccfa44f4372f55bd9027e010caf4055379a41e Mon Sep 17 00:00:00 2001 From: rolux Date: Wed, 30 May 2012 22:37:23 +0200 Subject: [PATCH] add Ox.isError, add tests --- source/Ox/js/Type.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/source/Ox/js/Type.js b/source/Ox/js/Type.js index aee84d20..927d084d 100644 --- a/source/Ox/js/Type.js +++ b/source/Ox/js/Type.js @@ -157,13 +157,24 @@ Ox.isEqual = function(a, b) { return ret; }; +/*@ +Ox.isError Tests if a value is an error + (value) -> 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 Tests if a value is a function (value) -> 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 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 Tests if a value is a regular expression (value) -> 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 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 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();