Skip to content
Snippets Groups Projects
Commit 4e76d261 authored by Sebastian Listl's avatar Sebastian Listl :speech_balloon:
Browse files

Added function Utils.parseBoolean

parent 0a2e509e
No related branches found
No related tags found
No related merge requests found
......@@ -134,56 +134,72 @@ Utils.isEqual = function (pFirstObject, pSecondObject)
/**
* Checks if the given value is a function.
*
* @param {Object} pObject the value to check
* @param {Object} pValue the value to check
* @return {Boolean} true if the value is a function
*/
Utils.isFunction = function (pObject)
Utils.isFunction = function (pValue)
{
return typeof pObject === "function";
return typeof pValue === "function";
}
/**
* Checks if the given value is a string.
*
* @param {Object} pObject the value to check
* @param {Object} pValue the value to check
* @return {Boolean} true if the value is a string
*/
Utils.isString = function (pObject)
Utils.isString = function (pValue)
{
return typeof pObject === "string";
return typeof pValue === "string";
}
/**
* Checks if the given value is a number.
*
* @param {Object} pObject the value to check
* @param {Object} pValue the value to check
* @return {Boolean} true if the value is a number
*/
Utils.isNumber = function (pObject)
Utils.isNumber = function (pValue)
{
return typeof pObject === "number";
return typeof pValue === "number";
}
/**
* Checks if the given value is an object. Be careful, null is also considered "object".
*
* @param {Object} pObject the value to check
* @param {Object} pValue the value to check
* @return {Boolean} true if the value is an object
*/
Utils.isObject = function (pObject)
Utils.isObject = function (pValue)
{
return typeof pObject === "object";
return typeof pValue === "object";
}
/**
* Checks if the given value is a boolean.
*
* @param {Object} pObject the value to check
* @param {Object} pValue the value to check
* @return {Boolean} true if the value is a boolean
*/
Utils.isBoolean = function (pObject)
Utils.isBoolean = function (pValue)
{
return typeof pObject === "boolean";
return typeof pValue === "boolean";
}
/**
* Parses the given value to Boolean, this can be used to check for stringified Booleans. These rules apply:
* <ul>
* <li>If the value is either falsy, the string "false" or the string "0", false is returned</li>
* <li>If the valueOf method of the value returns a falsy value, false is returned
* (this is to make sure the function returns false for weird stuff like 'new Boolean(false)')</li>
* <li>Every other value results in true</li>
*
* @param {String|Object} pValue the value to parse
* @return {Boolean} a real boolean
*/
Utils.parseBoolean = function (pValue)
{
return !(!pValue || pValue === "0" || pValue === "false" || !(pValue.valueOf()));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment