Global

Members


<constant> CB_BASE_NAME :string

Keeps the name of the CrossBase module.

Type:
  • string
Default Value:
  • CrossBase
Source:

<readonly> CB_CREDITS_DEFAULT :string

Default credits.

Type:
  • string
Source:

<constant> CB_NAME :string

Keeps the name of the script (the main script will use this name with the ".js" extension). Case sensitive.

Type:
  • string
Default Value:
  • CrossBrowdy
Source:

<constant> CB_OPTIONS :Object

Two-dimensional object defined by the user with the desired options for CrossBrowdy and its modules. The options supported are the ones used by the CB_Configuration object.


First-level indexes should belong to the module name (or to "CrossBrowdy", for general options) and second-level indexes should belong to the option name.


Example:


{
CrossBrowdy:
{
CB_console_ALLOW_ALERTS: false
},
CrossBase:
{
SLCANVAS_LOAD : true,
FLASHCANVAS_LOAD : true
}
}

Type:
  • Object
Default Value:
  • undefined
Source:

<readonly> CB_scriptPath :string

It will contain the CrossBrowdy path when it finally loads.

Type:
  • string
Default Value:
Source:

<constant> CB_this :Object

Keeps the CrossBrowdy "this" context.

Type:
  • Object
Source:

<constant> CB_VERSION :string

CrossBrowdy version.

Type:
  • string
Source:

Methods


CB_addCredits(credits) → {string}

Attaches the given credits to the default ones (to CB_CREDITS_DEFAULT).

Parameters:
Name Type Description
credits string

Path to the JS file.

Source:
Returns:

Returns the default credits after attaching the given ones.

Type
string

CB_baseToBase(number [, baseSymbolsOrigin] [, baseSymbolsDestiny] [, unsigned] [, minusSymbolOrigin] [, minusSymbolDestiny] [, prefixOrigin] [, prefixDestiny]) → {string}

Converts a given number which is already in a desired base into another chosen base.


Note: Uses CB_baseToInt and CB_intToBase internally.

Parameters:
Name Type Argument Default Description
number string

A string containing the number which is already in the desired base and that we want to convert into the another chosen base. Used as the "number" parameter for calling both CB_intToBase and CB_baseToInt functions internally.

baseSymbolsOrigin array | integer <optional>
CB_baseSymbols.66

Used as the "baseSymbols" parameter when calling the CB_baseToInt function internally.

baseSymbolsDestiny array | integer <optional>
CB_baseSymbols.66

Used as the "baseSymbols" parameter when calling the CB_intToBase function internally.

unsigned boolean <optional>
false

Determines whether to treat the input and output numbers as unsigned or not. Used as the "unsigned" parameter for calling both CB_intToBase and CB_baseToInt functions internally.

minusSymbolOrigin string <optional>
'-'|'0'

Used as the "minusSymbol" parameter when calling the CB_baseToInt function internally.

minusSymbolDestiny string <optional>
'-'|'0'

Used as the "minusSymbol" parameter when calling the CB_intToBase function internally.

prefixOrigin prefix <optional>
'0'|'0x'|''

Used as the "prefix" parameter when calling the CB_baseToInt function internally.

prefixDestiny prefix <optional>
'0'|'0x'|''

Used as the "prefix" parameter when calling the CB_intToBase function internally.

Source:
To Do:
  • Think about accepting a decimal symbol to separate decimals and support float numbers.
Returns:

Returns the returning value of the internal call to the CB_intToBase function.

Type
string

CB_baseToInt(number [, baseSymbols] [, unsigned] [, minusSymbol] [, prefix]) → {integer}

Converts a given number which is already in a desired base into an integer (decimal base).


Note: It can return wrong values when the value exceeds the maximum allowed by a number in the client's JavaScript engine. It can also depend on the "baseSymbols" used.

Parameters:
Name Type Argument Default Description
number string

A string containing the number which is already in the desired base and that we want to convert to an integer.

baseSymbols array | integer <optional>
CB_baseSymbols.66

Array with the desired symbols, using only one per index (their value will correspond to their index). The base (radix) will be the total number of indexes. It should be the base which is already being used by the given number. If an integer greater or equal than 2 is provided, it will try to use it as an index of the CB_baseSymbols object and use it if found or use it as a parameter to call the CB_baseSymbols.get function otherwise. If not provided or the integer is lower than 2, it will use base 66 (defined in the CB_baseSymbols._66 property of the CB_baseSymbols object). It is recommended not to exceed 4096 (or even lower, depending on the client, although some clients could support up to 63988 or even more). The properties of the CB_baseSymbols object or the CB_baseSymbols.get function can be used for this parameter.

unsigned boolean <optional>
false

Determines whether to treat the input and output numbers as unsigned or not.

minusSymbol string <optional>
'-'|'0'

Determines the minus symbol or string for the input, to mark negative numbers. If not provided, it will be '-' for bases equal or lower than 16 (hexadecimal) or '0' (zero character) otherwise. This parameter is ignored if the "unsigned" parameter is set to true.

prefix prefix <optional>
'0'|'0x'|''

Determines the prefix for the input. If not provided, it will be '0' (zero character) for base 8 (octal), '0x' for base 16 (hexadecimal) or nothing (empty string) for all the others. Use an empty string to avoid using anything.

Source:
To Do:
  • Think about allowing to return a string, for bigger numbers (to exceed the limit for integers). Internally, it would need to perform operations comparisons, multiplications with strings, etc.
  • Think about allowing to specify the base for the integer.
  • Think about accepting a decimal symbol to separate decimals and support float numbers.
Returns:

Returns the integer number in decimal base.

Type
integer

CB_br2nl(string) → {string}

Changes <br />'s, <br/>'s and <br>'s for new lines (\n) in a given string.

Parameters:
Name Type Description
string string

The string we want to modify.

Source:
Returns:

Returns the string with all the occurrences replaced or an empty string if the element given was not a string.

Type
string

CB_brToNl()

Alias for CB_br2nl.

Source:
See:

CB_combineArraysOrObjects( [arrayOrObjectA] [, arrayOrObjectB], avoidDuplicatedValuesInArray [, modifyArrayOrObjectA]) → {array|Object}

Returns a combined array or object from two arrays or objects. Using the following rules:


If they both are arrays (numeric indexes), it will keep all elements (attaching the elements of the second array after the elements of the first one).


Otherwise, if either of them is not an array (it should be an associative array which is an object in JavaScript), it will merge the elements (overwritting those whose index is the same and keeping the ones from the second array/object):

Parameters:
Name Type Argument Default Description
arrayOrObjectA array | Object | string | null | undefined <optional>
[]|{}

One of the arrays (numeric indexes) or associative arrays (object) that we want to combine. If a string is provided, it will try to convert it into a new object (the string should be a JSON-valid string). It can be optional if "arrayOrObjectB" is a valid value and neither null nor undefined. If not provided but the "arrayOrObjectB" is provided, it will be a new empty array if the "arrayOrObjectB" is an array or it will be an empty object otherwise.

arrayOrObjectB array | Object | string | null | undefined <optional>
[]|{}

One of the arrays (numeric indexes) or associative arrays (object) that we want to combine. If a string is provided, it will try to convert it into a new object (the string should be a JSON-valid string). It can be optional if "arrayOrObjectA" is a valid value and neither null nor undefined. If not provided but the "arrayOrObjectA" is provided, it will be a new empty array if the "arrayOrObjectA" is an array or it will be an empty object otherwise.

avoidDuplicatedValuesInArray boolean

Tells whether to avoid or allow items with duplicated values in the returned array or not. Only applies when both arrays to combine are numeric arrays.

modifyArrayOrObjectA boolean <optional>
false

Parameter that will be used in the case that CB_combineJSON or CB_combineArraysOrObjects is called. If set to true, it will modify the original "arrayOrObjectA" array or object.

Source:
Returns:
Type
array | Object

CB_combineAutomatically( [a] [, b] [, avoidDuplicatedValuesInArray] [, modifyArrayOrObjectA]) → {*}

Tries to combine two given values guessing the best way to do it and returns their combination. Using the following rules:


If both values are either undefined or null, returns null.


Otherwise, if both values are boolean, returns the AND operation for the two of them (a && b).


Otherwise, if either of the two is a string (not empty) and is not JSON valid, combines them as URL (GET) parameters using CB_combineURIParameters.


Otherwise, if either of them is JSON valid, combines them as JSON using CB_combineJSON (passing the received avoidDuplicatedValuesInArray value as a parameter).


Otherwise, combines them as arrays or objects using CB_combineArraysOrObjects (passing the received "avoidDuplicatedValuesInArray" value as a parameter).

Parameters:
Name Type Argument Default Description
a * <optional>
null|[]|{}

First value. It can be optional if "b" is a valid value, defined and not null.

b * <optional>
null|[]|{}

Second value. It can be optional if "a" is a valid value, defined and not null.

avoidDuplicatedValuesInArray boolean <optional>
false

Parameter that will be used in the case that CB_combineJSON or CB_combineArraysOrObjects is called.

modifyArrayOrObjectA boolean <optional>
false

Parameter that will be used in the case that CB_combineJSON or CB_combineArraysOrObjects is called. If set to true, it will modify the original "a" array or object.

Source:
Returns:
Type
*

CB_combineJSON()

Source:
See:

CB_combineURIParameters(parametersA, parametersB) → {string}

Combines two strings as URL (GET) parameters. If either "parametersA" or "parametersB" is not a string, internally it will use the native JSON.stringify method if available or otherwise it will use JSON 3 instead.

Parameters:
Name Type Description
parametersA string

String with the desired parameter or parameters. It can be optional if "parametersB" is a valid string. It will trim any "&" and "?" character at the beginning and at the end, and finally use "&" to concatenate the two strings (if needed).

parametersB string

String with the desired parameter or parameters. It can be optional if "parametersA" is a valid string. It will trim any "&" and "?" character at the beginning and at the end, and finally use "&" to concatenate the two strings (if needed).

Source:
Returns:

For example, if parametersA is "parameter1=value1&parameter2=value2" and parametersB is "parameter3=value3&what=ever" then it will return "parameter1=value1&parameter2=value2&parameter3=value3&what=ever".

Type
string

CB_combineURLParameters()

Source:
See:

CB_console(message)

Alias for the "console" function which fallbacks to a DOM element with "CB_console" id (its CSS "style" attribute will be modified if needed, which means that its "display" property will be set to "block" if it is "none" and its "visibility" property to "visible" regardless its previous value) or even to an alert when it is not available ("alert" will only be used as a fallback in the case that the CB_console_ALLOW_ALERTS parameter is set to true).

Parameters:
Name Type Description
message string

Message to display

Source:
To Do:
  • When "console" is not available and it gets polyfilled, allow more parameters (use "arguments").

CB_copyObject(element [, onlyOwn]) → {object}

Returns an object copied from the given one.

Parameters:
Name Type Argument Default Description
element object

The element whose properties and values we want to copy. It should be an object.

onlyOwn boolean <optional>
false

If the "element" given is not an object, this parameter will be ignored. Otherwise, if it is set to true, it will only have into account the properties which the object has as their own property and have not been inherited (using the Object.hasOwnProperty method).

Source:
Returns:

Returns an object copied from the given one. Returns an empty object if the given "element" was not an object.

Type
object

CB_countDecimalDigits()

Alias for CB_countDecimalPart.

Source:
See:

CB_countDecimalPart(number) → {integer}

Returns the number of decimals of the given number. It also works with numbers in exponential notation (as for example '1e-13' which would be 0.0000000000001).

Parameters:
Name Type Description
number integer | float | string

The number whose decimals we want to count. It can be a string.

Source:
Returns:

Returns zero in the case a non-valid number has been provided. Otherwise, it returns the number of decimals counted.

Type
integer

CB_countDecimals()

Alias for CB_countDecimalPart.

Source:
See:

CB_countIntegerDigits()

Alias for CB_countIntegerPart.

Source:
See:

CB_countIntegerPart(number) → {integer}

Returns the number of integer digits (the number of digits that belong to the integer part) of the given number. It also works with numbers in exponential notation (as for example '1e-13' which would be 0.0000000000001).

Parameters:
Name Type Description
number integer | float | string

The number whose integer digits (the digits that belong to the integer part) we want to count. It can be a string.

Source:
Returns:

Returns zero in the case a non-valid number has been provided. Otherwise, it returns the number of integer digits (the number of digits that belong to the integer part) counted.

Type
integer

CB_credits( [credits] [, html] [, showPrefix]) → {string}

Returns the credits with the desired format.

Parameters:
Name Type Argument Default Description
credits string <optional>
CB_CREDITS_DEFAULT

Desired credits to be shown.

html boolean <optional>
true

Strips all HTML tags (if any) when it is false.

showPrefix boolean <optional>
true

Defines whether to show the "[CB]" prefix for every line or not (it will remove all "[CB]" occurrences if it is false).

Source:
Returns:
Type
string

CB_forceString(element) → {string}

Returns back the given element if it is a string or an empty string otherwise.

Parameters:
Name Type Description
element *

The element that will be checked.

Source:
Returns:
Type
string

CB_forEach(array, callback [, thisArg] [, extendedDOM]) → {array|undefined}

Implementation of the Array.forEach method for browsers that do not support it natively.


Executes a function for each element of a given array.

Parameters:
Name Type Argument Default Description
array array

Desired array.

callback function

Function that will be executed for each element of the given array. Following the same rules as the native Array.forEach method, it will receive three arguments: currentValue, currentIndex and the array given.

thisArg * <optional>

Value that will be passed as "this" every time the function is called.

extendedDOM boolean <optional>
false

Defines whether the function is being called by a native function which was extended. Internal usage recommended only.

Source:
Returns:

If the "extendedDOM" parameter is set to false, returns the given "array" again. Otherwise, returns undefined.

Type
array | undefined

CB_getBase64StringObject() → {Object}

Returns the "Base64String" object (used by the base64-string library included in lz-string), if any. Useful for compressing/decompressing base64 code.

Source:
Returns:

Returns the "Base64String" object (used by the base64-string library included in lz-string) if available or null otherwise.

Type
Object

CB_getCookie(index) → {string|null}

Returns, from its index, a previous stored cookie.

Parameters:
Name Type Description
index string

The index whose value we want to retrieve.

Source:
Returns:

Returns null when the value cannot be found.

Type
string | null

CB_getDatum(index [, forceCookie] [, unescapeIndex]) → {string|null}

Gets, from its index, a previous value stored. It will try to get it using Web Storage API (localStorage). It can use localStorage as a fallback or cookies instead.

Parameters:
Name Type Argument Default Description
index string

The index whose value we want to retrieve.

forceCookie boolean <optional>
false

Forces to use cookies instead of Web Storage API (localStorage).

unescapeIndex boolean <optional>
false

Applies the unescape function to the value before returning it. Only applies when cookies are used.

Source:
Returns:

Returns null when the value cannot be found.

Type
string | null

CB_getJSONPropertyValue(JSONObject, property [, returnValueOnFail]) → {*}

Gets the value of a desired property of a given JSON object. Uses the CB_getValueIndex function internally.

Parameters:
Name Type Argument Description
JSONObject Object | string

The JSON object from which we want to get the value. If it is a string, it will try to parse it to create a real object from it. Used as the "object" parameter when calling the CB_getValueIndex function internally.

property string

The property whose value we want to retrieve. If not provided, the given object will be returned again. Used as the "index" parameter when calling the CB_getValueIndex function internally.

returnValueOnFail * <optional>

The value we want it to return in the case it cannot be parsed. If not provided, undefined will be returned. Used as the "returnValueOnFail" parameter when calling the CB_getValueIndex function internally.

Source:
Returns:

Returns the given "JSONObject" again (after trying to parse it if it was a string, if possible) if the "property" value was not given. Returns the value from the given object which belongs to the desired property or the value of "returnValueOnFail" otherwise if it cannot be found.

Type
*

CB_getLZStringObject() → {Object}

Returns the "LZString" object (used by the lz-string library), if any. Useful for compressing/decompressing strings.

Source:
Returns:

Returns the "LZString" object (used by the lz-string library) if available or null otherwise.

Type
Object

CB_getValueIndex(object, index [, returnValueOnFail]) → {*}

Gets the value from a given object which belongs to the desired index or returns the value of "returnValueOnFail" if it cannot be found.

Parameters:
Name Type Argument Description
object Object

The object from which we want to get the value.

index string

The index whose value we want to retrieve.

returnValueOnFail * <optional>

The value we want it to return in the case that the property cannot be found. If not provided, undefined will be returned.

Source:
Returns:

Returns the value from a given object which belongs to the desired index or the value of "returnValueOnFail" otherwise if it cannot be found.

Type
*

CB_getValuePath(object, path [, splitString]) → {*}

Returns the value of a desired path in an object or an empty string if it cannot be found.

Parameters:
Name Type Argument Default Description
object Object

The object where we want to find the path.

path string

The path that will be search in the given object to retrieve the value. It should use the string defined in the "splitString" parameter to separate items. If it is empty or not provided, it will just return the given "object" again.

splitString string <optional>
"."

The string that will be used to separate one item from another one. By default, it will be a dot (".") so, for example, a given "path" with a value of "hello.world" will indicate the "object.hello.world" path.

Source:
Returns:

Returns the value of a desired path in an object or an empty string if it cannot be found. If the "path" parameter is empty or not provided, it will just return the given "object" again.

Type
*

CB_includeJSFile(filepath [, callbackOk] [, callbackError] [, timeoutMs] [, asynchronously] [, fileId] [, fileRequires] [, notMandatory]) → {Object|null|false}

Includes a JavaScript file to the current document.

Parameters:
Name Type Argument Default Description
filepath string

Path to the JS file.

callbackOk CB_includeJSFile_CALLBACK <optional>

Callback for when the file is included successfully.

callbackError CB_includeJSFile_CALLBACK <optional>

Callback for when there is any error including the file or it cannot be included after the defined timeout.

timeoutMs integer <optional>
CB_Configuration.CrossBrowdy.CB_includeJSFile_TIMEOUT_MS_DEFAULT

Timeout in milliseconds to consider that the inclusion of the file has failed.

asynchronously boolean <optional>
true

Defines whether to load the file asynchronously or not.

fileId string <optional>

Internal usage recommended only.

fileRequires array <optional>

Internal usage recommended only.

notMandatory boolean <optional>
false

Internal usage recommended only.

Source:
Returns:

Returns null when the script file cannot be loaded yet as some required file has still not been loaded. Returns false when neither the 'HEAD' tag nor the document body can be found. Otherwise, returns an object whose two properties are 'scriptElement' (with the SCRIPT element just created) and 'timeoutFailure' (with the setTimeout ID created to check whether the file cannot be loaded after the given time).

Type
Object | null | false

CB_indexOf(array, searchElement [, fromIndex] [, extendedDOM]) → {integer}

Implementation of Array.indexOf method for arrays in browsers that do not support it natively.


Returns the first index of a given element that exists in an array (starting from a certain index if desired) or -1 if not found.

Parameters:
Name Type Argument Default Description
array array

Desired array.

searchElement *

Element we want to search. Note that it is type sensitive.

fromIndex integer <optional>
0

First index of the given array where the search will start.

extendedDOM boolean <optional>
false

Defines whether the function is being called by a native function which was extended. Internal usage recommended only.

Source:
Returns:
Type
integer

CB_init( [mainFunction] [, scriptPath] [, onErrorLoadingFile] [, showSplashScreen])

Starts CrossBrowdy.

Parameters:
Name Type Argument Default Description
mainFunction CB_init_CALLBACK <optional>

Callback for when CrossBrowdy is loaded successfully. Recommended.

scriptPath string <optional>
CB_scriptPathCalculate()

Path where the main script is located. If not provided (it is undefined or null), it will try to calculate it calling the CB_scriptPathCalculate function internally.

onErrorLoadingFile CB_includeRequiredFileErrorCallback <optional>

Function to call when any of the required files fails to load (because of an error or because its timeout was fired). It could be called more than once, for each file which failed loading. If a function is provided, it will be stored in the global 'CB_initOnErrorLoadingFile' variable.

showSplashScreen boolean <optional>
CB_Configuration.CrossBrowdy.SHOW_SPLASH_SCREEN_DEFAULT

Defines whether to show the splash screen or not.

Source:

CB_intToBase(number [, baseSymbols] [, unsigned] [, minusSymbol] [, prefix]) → {string}

Converts a given integer into a desired base.

Parameters:
Name Type Argument Default Description
number integer | string

The integer that we want to convert to the desired base. For bigger numbers (up to 999999999999999934464 or even lower, depending on the client and the "baseSymbols" used), it is recommended to use a string which will allow to accept a slightly bigger number (up to 999999999999999999999999 or lower, depending on the client and the "baseSymbols" used). Really big numbers will not be codified properly even when passed as a string due to the limitations of JavaScript engines and maximum number allowed to be stored in a variable.

baseSymbols array | integer <optional>
CB_baseSymbols.66

Array with the desired symbols, using only one per index (their value will correspond to their index). The base (radix) will be the total number of indexes. If an integer greater or equal than 2 is provided, it will try to use it as an index of the CB_baseSymbols object and use it if found or use it as a parameter to call the CB_baseSymbols.get function otherwise. If not provided or the integer is lower than 2, it will use base 66 (defined in the CB_baseSymbols._66 property of the CB_baseSymbols object). It is recommended not to exceed 4096 (or even lower, depending on the client, although some clients could support up to 63988 or even more). The properties of the CB_baseSymbols object or the CB_baseSymbols.get function can be used for this parameter.

unsigned boolean <optional>
false

Determines whether to treat the input and output numbers as unsigned or not.

minusSymbol string <optional>
'-'|'0'

Determines the minus symbol or string for the output, to mark negative numbers. If not provided, it will be '-' for bases equal or lower than 16 (hexadecimal) or '0' (zero character) otherwise. This parameter is ignored if the "unsigned" parameter is set to true.

prefix prefix <optional>
'0'|'0x'|''

Determines the prefix for the output. If not provided, it will be '0' (zero character) for base 8 (octal), '0x' for base 16 (hexadecimal) or nothing (empty string) for all the others. Use an empty string to avoid using anything.

Source:
To Do:
  • Think about allowing the "number" parameter to be a very long string, for bigger numbers (to exceed the limit for integers). Internally, it would need to perform operations comparisons, divisions, remainder calculation with strings, etc.
  • Think about allowing to specify the base for the integer (now it is 16 if it begins with "0x", 8 if it begins with "0" and it is not a string or 10 otherwise, and newer clients can support '0b' for binaries, '0o' for octals, ).
  • Think about accepting a decimal symbol to separate decimals and support float numbers.
Returns:

Returns an empty string in the case that the given number cannot be parsed as an integer. Otherwise, returns the given number in the desired base as a string.

Type
string

CB_isArray(element [, extendedDOM]) → {boolean}

Implementation of Array.isArray method for browsers that do not support it natively.


Returns whether a given element is an array or not.

Parameters:
Name Type Argument Default Description
element *

The element we want to check.

extendedDOM boolean <optional>
false

Defines whether the function is being called by a native function which was extended. Internal usage recommended only.

Source:
To Do:
  • Think about a parameter to check whether the given array is a typed array (for example, 'Uint8Array') or not.
Returns:
Type
boolean

CB_isEmail(email) → {boolean}

Tells whether a given email is valid or not. Not really precise.

Parameters:
Name Type Description
email string

Possible email that we want to validate.

Source:
Returns:
Type
boolean

CB_isFileLocal(filePath) → {boolean}

Tries to guess whether a given file path (absolute or relative) is a local address or not. It will be assumed as local if the path
uses the "file:" protocol or the current script is running locally and the path does not use the "http:", "https:" or "ftp:" protocols.

Parameters:
Name Type Description
filePath string

The file path we want to check.

Source:
Returns:

Returns whether the given file path is a local address or not.

Type
boolean

CB_isString(element) → {boolean}

Returns whether a given element is a string or not.

Parameters:
Name Type Description
element *

The element we want to check.

Source:
Returns:
Type
boolean

CB_lastIndexOf(array, searchElement [, fromIndex] [, extendedDOM]) → {integer}

Implementation of Array.lastIndexOf method for browsers that do not support it natively.


Returns the last index of a given element that exists in an array (starting from a certain index if desired) or -1 if not found.

Parameters:
Name Type Argument Default Description
array array

Desired array.

searchElement *

Element we want to search. Note that it is type sensitive.

fromIndex integer <optional>
array.length - 1

First index of the given array where the search will start.

extendedDOM boolean <optional>
false

Defines whether the function is being called by a native function which was extended. Internal usage recommended only.

Source:
To Do:
  • Implement the "fromIndex" in the polyfill.
Returns:
Type
integer

CB_ltrim(element [, undesiredStrings]) → {string|array}

Trims the left side of a given string or array of strings (modifying the given array), taking off the desired strings or otherwise trimming spaces, tabs ("\t"), new lines ("\n") and carriage returns ("\r"). Case sensitive.

Parameters:
Name Type Argument Default Description
element string | array

The element that will be trimmed. It should be either a string or an array of strings.

undesiredStrings string | array <optional>
[ " ", "\n", "\r", "\t" ]

String or an array with the strings that we want to trim off the given element.

Source:
To Do:
  • Accept a "recursive" parameter (boolean) to affect multiple levels (array of arrays of strings, etc.).
  • Consider accepting objects instead of arrays in the "element" parameter.
  • Think about optimizing (using a counter for the number of occurrences in the loop and trim all the occurrences when finished).
Returns:

Returns the given element again if it was an string, a number (it will be casted to a string) or an array of strings, trimmed if it has been possible. If it was another type, returns an empty string.

Type
string | array

CB_nl2br(string) → {string}

Changes new lines (\n) for <br />'s in a given string.

Parameters:
Name Type Description
string string

The string we want to modify.

Source:
Returns:

Returns the string with all the occurrences replaced or an empty string if the element given was not a string.

Type
string

CB_nlToBr()

Alias for CB_nl2br.

Source:
See:

CB_numberFormat(number [, decimals] [, stringify]) → {integer|float|string}

Returns the given number with the desired decimals and make it a string if we want to (so it will be able to have trailing zeros). Uses decimal numeral system only. It will perform ceiling round automatically if needed.

Parameters:
Name Type Argument Default Description
number integer | float | string

The number that we want to format. It can be a string.

decimals integer <optional>
2

The number of decimals we want to allow.

stringify boolean <optional>
false

Set to true if we want it to return a string (filled with trailing zeros to reach the desired number of decimals).

Source:
To Do:
  • Allow to define a minimum length for the integer part of the "number" parameter, so it will fill with leading zeros if needed (when "stringify" is set to true). Think about allowing to define a maximum too.
Returns:

Returns zero in the case a non-valid number has been provided.

Type
integer | float | string

CB_numberOfDecimalDigits()

Alias for CB_countDecimalPart.

Source:
See:

CB_numberOfDecimals()

Alias for CB_countDecimalPart.

Source:
See:

CB_numberOfIntegerDigits()

Alias for CB_countIntegerPart.

Source:
See:

CB_parseJSON(objectString [, reviver] [, returnValueOnFail] [, acceptUndefinedOrNull] [, onError]) → {*}

Tries to parse a given string to convert it into a JSON object. Internally it will use the native JSON.parse method or otherwise use JSON 3 instead.

Parameters:
Name Type Argument Default Description
objectString string

The JSON object we want to parse, in string format. First parameter when calling the JSON.parse method (or equivalent)

reviver function <optional>

Second parameter when calling the JSON.parse method (or equivalent).

returnValueOnFail * <optional>

The value we want it to return in the case it cannot be parsed. If not provided, undefined will be returned.

acceptUndefinedOrNull boolean <optional>
false

If it is set to true and the given objectString is undefined or null, an empty object ({}) will be used as the objectString.

onError function <optional>

Callback which will be called if it failed to be parsed (it will receive the "objectString" as the unique parameter).

Source:
Returns:

Returns the object parsed from the given string or the value of "returnValueOnFail" otherwise (which will be undefined if not provided).

Type
*

CB_parseString(element) → {string}

Returns back the given element as a string if it could be parsed or an empty string otherwise.

Parameters:
Name Type Description
element *

The element that will be checked.

Source:
Returns:
Type
string

CB_regularExpressionString(string [, allOccurrences] [, caseInsensitive]) → {RegExp}

Returns a desired regular expression (escaping the string) using the native JavaScript's RegExp from a given string.

Parameters:
Name Type Argument Default Description
string string

The string (not a regular expression) that we want to use (special characters will be escaped).

allOccurrences boolean <optional>
false

Defines whether we want the regular expression returned to match all occurrences of the given string or only first found.

caseInsensitive boolean <optional>
false

Defines whether we want the regular expression returned to be case insensitive or not.

Source:
Returns:

Returns the desired regular expression (escaping the string) using the native JavaScript's RegExp from a given string.

Type
RegExp

CB_renderString(str [, JSONObject] [, forceVanilla] [, depthLevelMax]) → {str}

Processes a given string as a template and returns it rendered (if possible) with the values of the given JSON object.
Tries to use Handlebars as the first choice but if is is not available it will just replace all occurrences with
vanilla JavaScript.

Parameters:
Name Type Argument Default Description
str string

The string we want to render.

JSONObject Object <optional>
CB_JSONData

The JSON object which contains the values. If not provided, it will try to use the global CB_JSONData object in the case it exists.

forceVanilla boolean <optional>
false

Forces vanilla JavaScript rendering instead of using Handlebars.

depthLevelMax integer <optional>
10

Maximum depth level allowed to read the object to render the string. Only applies when it is rendered by vanilla JavaScript. For performance purposes.

Source:
Returns:
Type
str

CB_replaceAll(stringOrArray, stringOrArrayFind [, stringReplace] [, caseInsensitive]) → {string|array}

Returns the string or array of strings with all the desired occurrences replaced. Calls itself recursively and calls the CB_regularExpressionString function internally.

Parameters:
Name Type Argument Default Description
stringOrArray string | array

An string or an array of strings whose content we want to replace. It can also be an array of arrays of strings (as many levels as you wish). If an array is given, it will not be modified and a copy from it will be generated and returned with the occurrences replaced.

stringOrArrayFind string | array

An string or an array of strings (not a regular expressions) that we want to find to be replaced (special characters will be escaped).

stringReplace string <optional>
""

The string that will replace "stringFind". If not provided, it will be replaced as an empty string (it will just remove the occurrences found).

caseInsensitive boolean <optional>
false

Defines whether we want to be case insensitive or not.

Source:
Returns:

Returns the "stringOrArray" given with occurrences replaced. If the "stringOrArray" given was neither a string nor an array, it will be returned without being modified.

Type
string | array

CB_rtrim(element [, undesiredStrings]) → {string|array}

Trims the right side of a given string or array of strings (modifying the given array), taking off the desired strings or otherwise trimming spaces, tabs ("\t"), new lines ("\n") and carriage returns ("\r"). Case sensitive.

Parameters:
Name Type Argument Default Description
element string | array

The element that will be trimmed. It should be either a string or an array of strings.

undesiredStrings string | array <optional>
[ " ", "\n", "\r", "\t" ]

String or an array with the strings that we want to trim off the given element.

Source:
To Do:
  • Accept a "recursive" parameter (boolean) to affect multiple levels (array of arrays of strings, etc.).
  • Consider accepting objects instead of arrays in the "element" parameter.
  • Think about optimizing (using a counter for the number of occurrences in the loop and trim all the occurrences when finished).
Returns:

Returns the given element again if it was an string, a number (it will be casted to a string) or an array of strings, trimmed if it has been possible. If it was another type, returns an empty string.

Type
string | array

CB_scriptPathCalculate() → {string}

Tries to calculate and returns the path where the script is located.

Source:
Returns:

If it cannot be calculated, it will returns the value of CB_Configuration[CB_NAME].SCRIPT_PATH_DEFAULT.

Type
string

CB_setCookie(index, value [, days] [, path]) → {boolean}

Stores a cookie.

Parameters:
Name Type Argument Description
index string | number

The index where the value given will be stored.

value string | number

The value we want to store. It should be a string or a number.

days integer <optional>

The number of days after which the cookie will expire. It belongs to the "expires=" parameter of the cookie. If not provided, the parameter will not be used at all.

path string <optional>

The path where the cookie will be stored. It belongs to the "path=" parameter of the cookie. If not provided, the parameter will not be used at all.

Source:
Returns:

Returns true if the value has been stored successfully (not totally reliable, it should be checked with CB_getCookie after a while).

Type
boolean

CB_setDatum(index, value [, days] [, path] [, forceCookie]) → {boolean}

Stores a value using Web Storage API (localStorage). It can use localStorage as a fallback or cookies instead.

Parameters:
Name Type Argument Default Description
index string | number

The index where the value given will be stored.

value string | number

The value we want to store. It should be a string or a number.

days integer <optional>

The number of days after which the cookie will expire (in the case that cookies are used). It belongs to the "expires=" parameter of the cookie. If not provided, the parameter will not be used at all.

path string <optional>

The path where the cookie will be stored (in the case that cookies are used). It belongs to the "path=" parameter of the cookie. If not provided, the parameter will not be used at all.

forceCookie boolean <optional>
false

Forces to use cookies instead of Web Storage API (localStorage).

Source:
Returns:

Returns true if the value has been stored successfully (not totally reliable, it should be checked with CB_getDatum after a while).

Type
boolean

CB_sizeof()

Alias for CB_sizeOf.

Source:
See:

CB_sizeOf(element [, onlyOwn]) → {integer}

Returns the size of an object or array.

Parameters:
Name Type Argument Default Description
element Object | array

The element whose size we want to know. It should be an object or an array.

onlyOwn boolean <optional>
false

If the "element" given is not an object, this parameter will be ignored. Otherwise, if it is set to true, it will only have into account the properties which the object has as their own property and have not been inherited (using the Object.hasOwnProperty method).

Source:
Returns:

If an object is provided, the size will be the number of its properties. Otherwise, if an array is given, the size will be the numbers of its indexes (Array.length property).

Type
integer

CB_stringifyJSON(objectOrValue [, replacer] [, space] [, returnValueOnFail] [, failIfUndefinedOrNull] [, onError]) → {string}

Tries to create a JSON valid string from a given JSON object or value. Internally it will use the native JSON.stringify method or otherwise use JSON 3 instead.

Parameters:
Name Type Argument Default Description
objectOrValue *

The object or value that we want to stringify. First parameter when calling the JSON.stringify method (or equivalent).

replacer function <optional>

Second parameter when calling the JSON.stringify method (or equivalent).

space string | integer <optional>

Third parameter when calling the JSON.stringify method (or equivalent).

returnValueOnFail * <optional>

The value we want it to return in the case it cannot be stringify. If not provided, undefined will be returned.

failIfUndefinedOrNull boolean <optional>
false

If it is set to true and the returning value is undefined or null, the value of "returnValueOnFail" will be returned.

onError function <optional>

Callback which will be called if it failed to be stringified (it will receive the "objectOrValue" as the unique parameter).

Source:
Returns:

Returns the object stringified from the given object or value if possible or the value of "returnValueOnFail" otherwise (which will be undefined if not provided). Avoids returning undefined or null if "failIfUndefinedOrNull" is set to true, returning the value of "returnValueOnFail" instead.

Type
string

CB_symmetricCall(callbackFunction, timeMs [, id]) → {number|null}

Calls the given function once through the native setTimeout function internally but having in mind the time taken when the function was called previously so it can be called multiple times and respect a symmetric interval between each call (simulates requestAnimationFrame).

Parameters:
Name Type Argument Default Description
callbackFunction CB_symmetricCall_CALLBACK

Function that will be called every time, receiving as the unique parameter the time (timestamp in milliseconds returned by the performance.now method, which could have been polyfilled automatically by CrossBrowdy) when it is called, being "this" the same "this" of the scope where it was called.

timeMs integer

Milliseconds between one call to the function and the next one. The accuracy will depend on many factors as the platform used, code performance, etc.

id string <optional>
callbackFunction.toString()

String that will identify this symmetric interval. Recommended to avoid possible problems.

Source:
Returns:

Returns a numeric identifier generated by an internal call to the native setTimeout function (can be cleared/cancelled with clearTimeout). Returns null if the given "callbackFunction" is not a valid function.

Type
number | null

CB_symmetricCallClear(id) → {boolean|null}

Clears the stored last time used by CB_symmetricCall for a given symmetric interval identifier.

Parameters:
Name Type Description
id string

String that identifies this symmetric interval.

Source:
Returns:

Returns null if the given "id" is not a valid string. Returns false if the stored time did not exist for the given "id" or it was cleared already. Returns true otherwise, after clearing it.

Type
boolean | null

CB_trim(element [, undesiredStrings]) → {string|array}

Trims a given string or array of strings (modifying the given array), taking off the desired strings or otherwise trimming spaces, tabs ("\t"), new lines ("\n") and carriage returns ("\r"). Case sensitive.

Parameters:
Name Type Argument Default Description
element string | array

The element that will be trimmed. It should be either a string or an array of strings.

undesiredStrings string | array <optional>
[ " ", "\n", "\r", "\t" ]

String or an array with the strings that we want to trim off the given element.

Source:
To Do:
  • Accept a "recursive" parameter (boolean) to affect multiple levels (array of arrays of strings, etc.).
  • Consider accepting objects instead of arrays in the "element" parameter.
Returns:

Returns the given element again if it was an string, a number (it will be casted to a string) or an array of strings, trimmed if it has been possible. If it was another type, returns an empty string.

Type
string | array

Type Definitions


CB_includeJSFile_CALLBACK(filepath, callbackOk, callbackError, timeoutMs, asynchronously)

Callback for when the file is included successfully or fails to load.

Parameters:
Name Type Description
filepath string

The 'filepath' parameter when CB_includeJSFile was called (if any).

callbackOk CB_includeJSFile_CALLBACK

The 'callbackOk' parameter when CB_includeJSFile was called (if any).

callbackError CB_includeJSFile_CALLBACK

The 'callbackError' parameter when CB_includeJSFile was called (if any).

timeoutMs integer

The 'timeoutMs' parameter when CB_includeJSFile was called (if any).

asynchronously boolean

The 'asynchronously' parameter when CB_includeJSFile was called (if any).

Source:

CB_includeRequiredFileErrorCallback(filepath, callbackOk, callbackError, timeoutMs, asynchronously, filesRequested, filesLoaded)

Callback for when the script is loaded successfully. Without parameters.

Parameters:
Name Type Description
filepath string

The 'filepath' parameter when CB_includeJSFile was called internally (if any).

callbackOk CB_includeJSFile_CALLBACK

The 'callbackOk' parameter when CB_includeJSFile was called internally (if any).

callbackError CB_includeJSFile_CALLBACK

The 'callbackError' parameter when CB_includeJSFile was called internally (if any).

timeoutMs integer

The 'timeoutMs' parameter when CB_includeJSFile was called internally (if any).

asynchronously boolean

The 'asynchronously' parameter when CB_includeJSFile was called (if any).

filesRequested object

Object whose indexes are all the filepaths of the script files requested so far and the value is true when the file is still loading (or to be loaded in the future), false if it was loaded successfully (the most likely) or null if it failed to load.

filesLoaded array

Numeric array whose values are the filepaths of the script files loaded successfully so far.

Source:

CB_init_CALLBACK()

Callback for when the script is loaded successfully. Without parameters.

Source:

CB_symmetricCall_CALLBACK(expectedCallingTime)

Callback that is called by CB_symmetricCall.

Parameters:
Name Type Description
expectedCallingTime integer

The timestamp in milliseconds that represents when the callback should have been called (it will be more or less accurate depending on many factors as the platform used, code performance, etc.).

Source: