UNPKG

98.8 kBHTMLView Raw
1<!DOCTYPE html>
2
3<html lang="en">
4<head>
5 <meta charset="utf-8">
6 <meta name="viewport" content="width=device-width">
7 <title>CrossBrowdy API documentation Source: CrossBase/general/CB_data.js</title>
8
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
13
14 <link type="text/css" rel="stylesheet" href="styles/site.cosmo.css">
15
16</head>
17
18<body style="min-width:800px; overflow-wrap:break-word; word-wrap:break-word; word-break:break-word; line-break:strict; hyphens:none; -webkit-hyphens:none; -moz-hyphens:none;">
19
20<div class="navbar navbar-default navbar-fixed-top ">
21<div class="container">
22 <div class="navbar-header">
23 <a class="navbar-brand" href="index.html">CrossBrowdy API documentation</a>
24 <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
25 <span class="icon-bar"></span>
26 <span class="icon-bar"></span>
27 <span class="icon-bar"></span>
28 </button>
29 </div>
30 <div class="navbar-collapse collapse" id="topNavigation">
31 <ul class="nav navbar-nav">
32
33 <li class="dropdown">
34 <a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b class="caret"></b></a>
35 <ul class="dropdown-menu inline">
36 <li><a href="CB_Arrays.html">CB_Arrays</a></li><li><a href="CB_AudioDetector.html">CB_AudioDetector</a></li><li><a href="CB_baseSymbols.html">CB_baseSymbols</a></li><li><a href="CB_Client.html">CB_Client</a></li><li><a href="CB_Collisions.html">CB_Collisions</a></li><li><a href="CB_Configuration.html">CB_Configuration</a></li><li><a href="CB_Configuration.CrossBase.html">CB_Configuration.CrossBase</a></li><li><a href="CB_Configuration.CrossBrowdy.html">CB_Configuration.CrossBrowdy</a></li><li><a href="CB_Controllers.html">CB_Controllers</a></li><li><a href="CB_Controllers_Proprietary.html">CB_Controllers_Proprietary</a></li><li><a href="CB_Controllers_Proprietary.WII.html">CB_Controllers_Proprietary.WII</a></li><li><a href="CB_Controllers_Proprietary.WII_U.html">CB_Controllers_Proprietary.WII_U</a></li><li><a href="CB_Device.html">CB_Device</a></li><li><a href="CB_Device.AmbientLight.html">CB_Device.AmbientLight</a></li><li><a href="CB_Device.Battery.html">CB_Device.Battery</a></li><li><a href="CB_Device.Location.html">CB_Device.Location</a></li><li><a href="CB_Device.Motion.html">CB_Device.Motion</a></li><li><a href="CB_Device.Orientation.html">CB_Device.Orientation</a></li><li><a href="CB_Device.Proximity.html">CB_Device.Proximity</a></li><li><a href="CB_Device.Vibration.html">CB_Device.Vibration</a></li><li><a href="CB_Elements.html">CB_Elements</a></li><li><a href="CB_Events.html">CB_Events</a></li><li><a href="CB_Keyboard.html">CB_Keyboard</a></li><li><a href="CB_Keyboard.chars.html">CB_Keyboard.chars</a></li><li><a href="CB_Keyboard.extended.html">CB_Keyboard.extended</a></li><li><a href="CB_Keyboard.keys.html">CB_Keyboard.keys</a></li><li><a href="CB_Modules.html">CB_Modules</a></li><li><a href="CB_Mouse.html">CB_Mouse</a></li><li><a href="CB_Mouse.CursorImage.html">CB_Mouse.CursorImage</a></li><li><a href="CB_Net.html">CB_Net</a></li><li><a href="CB_Net.Fetch.html">CB_Net.Fetch</a></li><li><a href="CB_Net.REST.html">CB_Net.REST</a></li><li><a href="CB_Net.Sockets.html">CB_Net.Sockets</a></li><li><a href="CB_Net.Sockets.SockJS.html">CB_Net.Sockets.SockJS</a></li><li><a href="CB_Net.XHR.html">CB_Net.XHR</a></li><li><a href="CB_Pointer.html">CB_Pointer</a></li><li><a href="CB_Screen.html">CB_Screen</a></li><li><a href="CB_Speaker.html">CB_Speaker</a></li><li><a href="CB_Touch.html">CB_Touch</a></li>
37 </ul>
38 </li>
39
40 <li class="dropdown">
41 <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
42 <ul class="dropdown-menu inline">
43 <li><a href="CB_AudioFile.html">CB_AudioFile</a></li><li><a href="CB_AudioFile_API.AAPI.html">CB_AudioFile_API.AAPI</a></li><li><a href="CB_AudioFile_API.ACMP.html">CB_AudioFile_API.ACMP</a></li><li><a href="CB_AudioFile_API.SM2.html">CB_AudioFile_API.SM2</a></li><li><a href="CB_AudioFile_API.WAAPI.html">CB_AudioFile_API.WAAPI</a></li><li><a href="CB_AudioFileCache.html">CB_AudioFileCache</a></li><li><a href="CB_AudioFileSprites.html">CB_AudioFileSprites</a></li><li><a href="CB_AudioFileSpritesPool.html">CB_AudioFileSpritesPool</a></li><li><a href="CB_Canvas.html">CB_Canvas</a></li><li><a href="CB_GraphicSprites.html">CB_GraphicSprites</a></li><li><a href="CB_GraphicSpritesScene.html">CB_GraphicSpritesScene</a></li>
44 </ul>
45 </li>
46
47 <li class="dropdown">
48 <a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
49 <ul class="dropdown-menu inline">
50 <li><a href="global.html#CB_addCredits">CB_addCredits</a></li><li><a href="global.html#CB_BASE_NAME">CB_BASE_NAME</a></li><li><a href="global.html#CB_baseToBase">CB_baseToBase</a></li><li><a href="global.html#CB_baseToInt">CB_baseToInt</a></li><li><a href="global.html#CB_br2nl">CB_br2nl</a></li><li><a href="global.html#CB_brToNl">CB_brToNl</a></li><li><a href="global.html#CB_combineArraysOrObjects">CB_combineArraysOrObjects</a></li><li><a href="global.html#CB_combineAutomatically">CB_combineAutomatically</a></li><li><a href="global.html#CB_combineJSON">CB_combineJSON</a></li><li><a href="global.html#CB_combineURIParameters">CB_combineURIParameters</a></li><li><a href="global.html#CB_combineURLParameters">CB_combineURLParameters</a></li><li><a href="global.html#CB_console">CB_console</a></li><li><a href="global.html#CB_copyObject">CB_copyObject</a></li><li><a href="global.html#CB_countDecimalDigits">CB_countDecimalDigits</a></li><li><a href="global.html#CB_countDecimalPart">CB_countDecimalPart</a></li><li><a href="global.html#CB_countDecimals">CB_countDecimals</a></li><li><a href="global.html#CB_countIntegerDigits">CB_countIntegerDigits</a></li><li><a href="global.html#CB_countIntegerPart">CB_countIntegerPart</a></li><li><a href="global.html#CB_credits">CB_credits</a></li><li><a href="global.html#CB_CREDITS_DEFAULT">CB_CREDITS_DEFAULT</a></li><li><a href="global.html#CB_forceString">CB_forceString</a></li><li><a href="global.html#CB_forEach">CB_forEach</a></li><li><a href="global.html#CB_getBase64StringObject">CB_getBase64StringObject</a></li><li><a href="global.html#CB_getCookie">CB_getCookie</a></li><li><a href="global.html#CB_getDatum">CB_getDatum</a></li><li><a href="global.html#CB_getJSONPropertyValue">CB_getJSONPropertyValue</a></li><li><a href="global.html#CB_getLZStringObject">CB_getLZStringObject</a></li><li><a href="global.html#CB_getValueIndex">CB_getValueIndex</a></li><li><a href="global.html#CB_getValuePath">CB_getValuePath</a></li><li><a href="global.html#CB_includeJSFile">CB_includeJSFile</a></li><li><a href="global.html#CB_indexOf">CB_indexOf</a></li><li><a href="global.html#CB_init">CB_init</a></li><li><a href="global.html#CB_intToBase">CB_intToBase</a></li><li><a href="global.html#CB_isArray">CB_isArray</a></li><li><a href="global.html#CB_isEmail">CB_isEmail</a></li><li><a href="global.html#CB_isFileLocal">CB_isFileLocal</a></li><li><a href="global.html#CB_isString">CB_isString</a></li><li><a href="global.html#CB_lastIndexOf">CB_lastIndexOf</a></li><li><a href="global.html#CB_ltrim">CB_ltrim</a></li><li><a href="global.html#CB_NAME">CB_NAME</a></li><li><a href="global.html#CB_nl2br">CB_nl2br</a></li><li><a href="global.html#CB_nlToBr">CB_nlToBr</a></li><li><a href="global.html#CB_numberFormat">CB_numberFormat</a></li><li><a href="global.html#CB_numberOfDecimalDigits">CB_numberOfDecimalDigits</a></li><li><a href="global.html#CB_numberOfDecimals">CB_numberOfDecimals</a></li><li><a href="global.html#CB_numberOfIntegerDigits">CB_numberOfIntegerDigits</a></li><li><a href="global.html#CB_OPTIONS">CB_OPTIONS</a></li><li><a href="global.html#CB_parseJSON">CB_parseJSON</a></li><li><a href="global.html#CB_parseString">CB_parseString</a></li><li><a href="global.html#CB_regularExpressionString">CB_regularExpressionString</a></li><li><a href="global.html#CB_renderString">CB_renderString</a></li><li><a href="global.html#CB_replaceAll">CB_replaceAll</a></li><li><a href="global.html#CB_rtrim">CB_rtrim</a></li><li><a href="global.html#CB_scriptPath">CB_scriptPath</a></li><li><a href="global.html#CB_scriptPathCalculate">CB_scriptPathCalculate</a></li><li><a href="global.html#CB_setCookie">CB_setCookie</a></li><li><a href="global.html#CB_setDatum">CB_setDatum</a></li><li><a href="global.html#CB_sizeof">CB_sizeof</a></li><li><a href="global.html#CB_sizeOf">CB_sizeOf</a></li><li><a href="global.html#CB_stringifyJSON">CB_stringifyJSON</a></li><li><a href="global.html#CB_symmetricCall">CB_symmetricCall</a></li><li><a href="global.html#CB_symmetricCallClear">CB_symmetricCallClear</a></li><li><a href="global.html#CB_this">CB_this</a></li><li><a href="global.html#CB_trim">CB_trim</a></li><li><a href="global.html#CB_VERSION">CB_VERSION</a></li>
51 </ul>
52 </li>
53
54 </ul>
55
56 <div class="col-sm-3 col-md-3">
57 <form class="navbar-form" role="search">
58 <div class="input-group">
59 <input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
60 <div class="input-group-btn">
61 <button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
62 </div>
63 </div>
64 </form>
65 </div>
66
67 </div>
68
69</div>
70</div>
71
72
73<div class="container" id="toc-content" style="width:100%;">
74<div class="row" style="width:100%;">
75
76
77 <div class="col-md-12">
78
79 <div id="main">
80
81
82 <h1 class="page-title">Source: CrossBase/general/CB_data.js</h1>
83
84<section>
85 <article>
86 <pre
87 class="sunlight-highlight-javascript linenums">/**
88 * @file Data and related management.
89 * @author Joan Alba Maldonado &lt;workindalian@gmail.com>
90 * @license Creative Commons Attribution 4.0 International. See more at {@link https://crossbrowdy.com/about#what_is_the_crossbrowdy_copyright_and_license}.
91 * @todo A function equivalent to htmlentities/htmlspecialchars (as in PHP).
92 */
93
94
95//If we want to extend the DOM, we do it:
96if (CB_Configuration[CB_BASE_NAME].EXTEND_DOM)
97{
98 try
99 {
100 if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(searchElement, fromIndex) { CB_indexOf(this, searchElement, fromIndex, true); } }
101 if (!Array.prototype.lastIndexOf) { Array.prototype.lastIndexOf = function(searchElement, fromIndex) { CB_lastIndexOf(this, searchElement, fromIndex, true); } }
102 if (!Array.isArray) { Array.isArray = function() { return CB_isArray(this, true); } } //isArray is a method which is not in the prototype.
103 //if (!Array.prototype.isArray) { Array.prototype.isArray = function() { return CB_isArray(this, true); } }
104 if (!Array.prototype.forEach) { Array.prototype.forEach = function(callback, thisArg) { CB_forEach(this, callback, thisArg, true); } }
105 if (!NodeList.prototype.forEach) { NodeList.prototype.forEach = Array.prototype.forEach; }
106 if (!HTMLCollection.prototype.forEach) { HTMLCollection.prototype.forEach = Array.prototype.forEach; }
107 } catch(E) {}
108}
109
110
111/**
112 * Implementation of [Array.lastIndexOf]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf} method for browsers that do not support it natively.
113 &lt;br>
114 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.
115 * @function
116 * @param {array} array - Desired array.
117 * @param {*} searchElement - Element we want to search. Note that it is type sensitive.
118 * @param {integer} [fromIndex=array.length - 1] - First index of the given array where the search will start.
119 * @param {boolean} [extendedDOM=false] - Defines whether the function is being called by a native function which was extended. Internal usage recommended only.
120 * @returns {integer}
121 * @todo Implement the "fromIndex" in the polyfill.
122 */
123//* Polyfill source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf
124function CB_lastIndexOf(array, searchElement, fromIndex, extendedDOM)
125{
126 'use strict';
127 if (!extendedDOM)
128 {
129 if (array &amp;&amp; array.lastIndexOf) { return array.lastIndexOf.call(array, searchElement, fromIndex || array.length); } //It can be a string.
130 if (Array.prototype.lastIndexOf) { return Array.prototype.lastIndexOf.call(array, searchElement, fromIndex || array.length); }
131 }
132
133 if (typeof(array) === "undefined" || array === null) { throw new TypeError(); }
134
135 var n, k,
136 t = Object(array),
137 len = t.length >>> 0;
138 if (len === 0) { return -1; }
139
140 n = len - 1;
141 if (arguments.length > 2 &amp;&amp; typeof(arguments[2]) !== "undefined" &amp;&amp; arguments[2] !== null &amp;&amp; !isNaN(arguments[2]))
142 {
143 n = Number(arguments[2]);
144 if (n != n) { n = 0; }
145 //if (n != n) { n = len - 1; }
146 else if (n != 0 &amp;&amp; n != (1 / 0) &amp;&amp; n != -(1 / 0))
147 {
148 n = (n > 0 || -1) * Math.floor(Math.abs(n));
149 }
150 }
151
152 for (k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); k >= 0; k--)
153 {
154 if (k in t &amp;&amp; t[k] === searchElement) { return k; }
155 }
156
157 return -1;
158}
159
160
161/**
162 * Implementation of [Array.indexOf]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf} method for arrays in browsers that do not support it natively.
163 &lt;br>
164 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.
165 * @function
166 * @param {array} array - Desired array.
167 * @param {*} searchElement - Element we want to search. Note that it is type sensitive.
168 * @param {integer} [fromIndex=0] - First index of the given array where the search will start.
169 * @param {boolean} [extendedDOM=false] - Defines whether the function is being called by a native function which was extended. Internal usage recommended only.
170 * @returns {integer}
171 */
172//* Polyfill source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
173function CB_indexOf(array, searchElement, fromIndex, extendedDOM)
174{
175 if (!extendedDOM)
176 {
177 if (array &amp;&amp; array.indexOf) { return array.indexOf.call(array, searchElement, fromIndex); } //It can be a string.
178 if (Array.prototype.indexOf) { return Array.prototype.indexOf.call(array, searchElement, fromIndex); }
179 }
180
181 if (typeof(array) === "undefined" || array === null)
182 {
183 throw new TypeError( '"array" is null or not defined' );
184 }
185
186 var length = array.length >>> 0; // Hack to convert object.length to a UInt32
187
188 fromIndex = +fromIndex || 0;
189
190 if (Math.abs(fromIndex) === Infinity) { fromIndex = 0; }
191
192 if (fromIndex &lt; 0)
193 {
194 fromIndex += length;
195 if (fromIndex &lt; 0) { fromIndex = 0; }
196 }
197
198 for (;fromIndex &lt; length; fromIndex++)
199 {
200 if (array[fromIndex] === searchElement)
201 {
202 return fromIndex;
203 }
204 }
205
206 return -1;
207}
208
209
210/**
211 * Implementation of the [Array.forEach]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach} method for browsers that do not support it natively.
212 &lt;br>
213 Executes a function for each element of a given array.
214 * @function
215 * @param {array} array - Desired array.
216 * @param {function} callback - Function that will be executed for each element of the given array. Following the same rules as the native [Array.forEach]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach} method, it will receive three arguments: currentValue, currentIndex and the array given.
217 * @param {*} [thisArg] - Value that will be passed as "this" every time the function is called.
218 * @param {boolean} [extendedDOM=false] - Defines whether the function is being called by a native function which was extended. Internal usage recommended only.
219 * @returns {array|undefined} If the "extendedDOM" parameter is set to false, returns the given "array" again. Otherwise, returns undefined.
220 */
221//* Polyfill source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
222function CB_forEach(array, callback, thisArg, extendedDOM)
223{
224 "use strict";
225
226 if (!extendedDOM)
227 {
228 if (array.forEach) { array.forEach.call(array, callback, thisArg); return array; }
229 else if (Array.prototype.forEach) { Array.prototype.forEach.call(array, callback, thisArg); return array; }
230 }
231
232 if (array === void 0 || array === null) { throw new TypeError(); }
233 if (typeof callback !== "function") { throw new TypeError(); }
234
235 var t = Object(array);
236 var len = t.length >>> 0;
237
238 //thisArg = arguments.length >= 2 ? arguments[1] : void 0;
239 for (var i = 0; i &lt; len; i++)
240 {
241 if (i in t) { callback.call(thisArg, t[i], i, t); }
242 }
243
244 return extendedDOM ? undefined : array;
245}
246
247
248/**
249 * Implementation of [Array.isArray]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray} method for browsers that do not support it natively.
250 &lt;br>
251 Returns whether a given element is an array or not.
252 * @function
253 * @param {*} element - The element we want to check.
254 * @param {boolean} [extendedDOM=false] - Defines whether the function is being called by a native function which was extended. Internal usage recommended only.
255 * @returns {boolean}
256 * @todo Think about a parameter to check whether the given array is a typed array (for example, 'Uint8Array') or not.
257 */
258function CB_isArray(element, extendedDOM)
259{
260 if (typeof(element) === "undefined" || element === null) { return false; }
261 var isArray = false;
262 if (Array)
263 {
264 if (Array.isArray &amp;&amp; !extendedDOM)
265 {
266 isArray = Array.isArray(element);
267 }
268 else
269 {
270 isArray = element instanceof Array;
271 if (!isArray) //It could still be an Array from another frame.
272 {
273 isArray = (Object.prototype.toString.call(element) === '[object Array]');
274 }
275 }
276 }
277 return isArray;
278}
279
280
281/**
282 * Alias for {@link CB_sizeOf}.
283 * @function CB_sizeof
284 * @see {@link CB_sizeOf}
285 */
286/**
287 * Returns the size of an object or array.
288 * @function
289 * @param {Object|array} element - The element whose size we want to know. It should be an object or an array.
290 * @param {boolean} [onlyOwn=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]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty} method).
291 * @returns {integer} 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]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length} property).
292 */
293function CB_sizeOf(object, onlyOwn)
294{
295 var size = 0;
296 if (CB_isArray(object) &amp;&amp; typeof(object.length) !== "undefined" &amp;&amp; object.length !== null &amp;&amp; !isNaN(object.length) &amp;&amp; object.length > 0) { return object.length; }
297 for (var key in object)
298 {
299 if (!onlyOwn || object.hasOwnProperty(key)) { size++; }
300 }
301 return size;
302}
303var CB_sizeof = CB_sizeOf; //Alias for the function.
304
305
306/**
307 * Returns whether a given element is a string or not.
308 * @function
309 * @param {*} element - The element we want to check.
310 * @returns {boolean}
311 */
312function CB_isString(element)
313{
314 return (typeof(element) === "string" || element instanceof String);
315}
316
317
318/**
319 * Returns back the given element if it is a string or an empty string otherwise.
320 * @function
321 * @param {*} element - The element that will be checked.
322 * @returns {string}
323 */
324function CB_forceString(element)
325{
326 if (!CB_isString(element)) { return ""; }
327 else { return element; }
328}
329
330
331/**
332 * Returns back the given element as a string if it could be parsed or an empty string otherwise.
333 * @function
334 * @param {*} element - The element that will be checked.
335 * @returns {string}
336 */
337function CB_parseString(element)
338{
339 if (typeof(element) === "undefined" || element === null || element === true || element === false || !CB_isString(element) &amp;&amp; isNaN(element)) { return ""; }
340 else { return element + ""; }
341}
342
343
344/**
345 * 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.
346 * @function
347 * @param {string|array} element - The element that will be trimmed. It should be either a string or an array of strings.
348 * @param {string|array} [undesiredStrings=[ " ", "\n", "\r", "\t" ]] - String or an array with the strings that we want to trim off the given element.
349 * @returns {string|array} 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.
350 * @todo Accept a "recursive" parameter (boolean) to affect multiple levels (array of arrays of strings, etc.).
351 * @todo Consider accepting objects instead of arrays in the "element" parameter.
352 */
353function CB_trim(element, undesiredStrings)
354{
355 if (CB_isArray(element))
356 {
357 for (var x = 0, elementLength = element.length; x &lt; elementLength; x++)
358 {
359 element[x] = CB_trim(element[x], undesiredStrings);
360 }
361 return element;
362 }
363 //else if (typeof(element) !== "undefined" &amp;&amp; element !== null &amp;&amp; !isNaN(element)) { return element; }
364 else if (typeof(element) === "undefined" || element === null) { return ""; }
365 else if (element === true || element === false) { return ""; }
366 else if (!isNaN(element)) { element = element + ""; }
367 else if (!CB_isString(element)) { return ""; }
368 else if (typeof(element.trim) === "function")
369 {
370 //Only calls the native function when the "undesiredStringFound" parameter is the default one (it will not just trim blank spaces but also "\r", "\n"...):
371 if (!CB_isArray(undesiredStrings) &amp;&amp; !CB_isString(undesiredStrings))
372 {
373 return element.trim();
374 }
375 }
376 //return element.replace(/^\s+|\s+$/g, "");
377
378 element = CB_rtrim(element, undesiredStrings);
379 element = CB_ltrim(element, undesiredStrings);
380
381 return element;
382}
383
384
385/**
386 * 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.
387 * @function
388 * @param {string|array} element - The element that will be trimmed. It should be either a string or an array of strings.
389 * @param {string|array} [undesiredStrings=[ " ", "\n", "\r", "\t" ]] - String or an array with the strings that we want to trim off the given element.
390 * @returns {string|array} 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.
391 * @todo Accept a "recursive" parameter (boolean) to affect multiple levels (array of arrays of strings, etc.).
392 * @todo Consider accepting objects instead of arrays in the "element" parameter.
393 * @todo Think about optimizing (using a counter for the number of occurrences in the loop and trim all the occurrences when finished).
394 */
395function CB_rtrim(element, undesiredStrings)
396{
397 if (CB_isArray(element))
398 {
399 for (var x = 0, elementLength = element.length; x &lt; elementLength; x++)
400 {
401 element[x] = CB_rtrim(element[x], undesiredStrings);
402 }
403 return element;
404 }
405 //else if (typeof(element) !== "undefined" &amp;&amp; element !== null &amp;&amp; !isNaN(element)) { return element; }
406 else if (typeof(element) === "undefined" || element === null) { return ""; }
407 else if (element === true || element === false) { return ""; }
408 else if (!isNaN(element)) { element = element + ""; }
409 else if (!CB_isString(element)) { return ""; }
410
411 if (CB_isString(undesiredStrings)) { undesiredStrings = [ undesiredStrings ]; }
412 else if (!CB_isArray(undesiredStrings))
413 {
414 undesiredStrings = [ " ", "\n", "\r", "\t" ];
415 //Only calls the native function when the "undesiredStringFound" parameter is the default one (it will not just trim blank spaces but also "\r", "\n"...):
416 if (typeof(element.trimEnd) === "function") { return element.trimEnd(); }
417 }
418
419 //Loops through the undesired strings:
420 var undesiredStringsLength = undesiredStrings.length;
421 var undesiredStringFound = false;
422 for (var x = 0; x &lt; undesiredStringsLength; x++)
423 {
424 //Trims undesired string at the end:
425 while (element.substring(element.length - undesiredStrings[x].length, element.length) === undesiredStrings[x])
426 {
427 element = element.substring(0, element.length - undesiredStrings[x].length);
428 undesiredStringFound = true;
429 }
430 //If an undesired string has been found, we are looking for more than one undesired strings and the loop is at the end, starts the loop again:
431 if (undesiredStringFound &amp;&amp; undesiredStringsLength > 1 &amp;&amp; x + 1 === undesiredStringsLength) { undesiredStringFound = false; x = -1; }
432 }
433
434 return element;
435}
436
437
438/**
439 * 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.
440 * @function
441 * @param {string|array} element - The element that will be trimmed. It should be either a string or an array of strings.
442 * @param {string|array} [undesiredStrings=[ " ", "\n", "\r", "\t" ]] - String or an array with the strings that we want to trim off the given element.
443 * @returns {string|array} 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.
444 * @todo Accept a "recursive" parameter (boolean) to affect multiple levels (array of arrays of strings, etc.).
445 * @todo Consider accepting objects instead of arrays in the "element" parameter.
446 * @todo Think about optimizing (using a counter for the number of occurrences in the loop and trim all the occurrences when finished).
447 */
448function CB_ltrim(element, undesiredStrings)
449{
450 if (CB_isArray(element))
451 {
452 for (var x = 0, elementLength = element.length; x &lt; elementLength; x++)
453 {
454 element[x] = CB_ltrim(element[x], undesiredStrings);
455 }
456 return element;
457 }
458 //else if (typeof(element) !== "undefined" &amp;&amp; element !== null &amp;&amp; !isNaN(element)) { return element; }
459 else if (typeof(element) === "undefined" || element === null) { return ""; }
460 else if (element === true || element === false) { return ""; }
461 else if (!isNaN(element)) { element = element + ""; }
462 else if (!CB_isString(element)) { return ""; }
463
464 if (CB_isString(undesiredStrings)) { undesiredStrings = [ undesiredStrings ]; }
465 else if (!CB_isArray(undesiredStrings))
466 {
467 undesiredStrings = [ " ", "\n", "\r", "\t" ];
468 //Only calls the native function when the "undesiredStringFound" parameter is the default one (it will not just trim blank spaces but also "\r", "\n"...):
469 if (typeof(element.trimStart) === "function") { return element.trimStart(); }
470 }
471
472 //Loops through the undesired strings:
473 var undesiredStringsLength = undesiredStrings.length;
474 var undesiredStringFound = false;
475 for (var x = 0; x &lt; undesiredStringsLength; x++)
476 {
477 //Trims undesired string at the beginning:
478 while (element.substring(0, undesiredStrings[x].length) === undesiredStrings[x])
479 {
480 element = element.substring(undesiredStrings[x].length, element.length);
481 undesiredStringFound = true;
482 }
483 //If an undesired string has been found, we are looking for more than one undesired strings and the loop is at the end, starts the loop again:
484 if (undesiredStringFound &amp;&amp; undesiredStringsLength > 1 &amp;&amp; x + 1 === undesiredStringsLength) { undesiredStringFound = false; x = -1; }
485 }
486
487 return element;
488}
489
490
491/**
492 * Alias for {@link CB_nl2br}.
493 * @function CB_nlToBr
494 * @see {@link CB_nl2br}
495 */
496/**
497 * Changes new lines (\n) for &amp;lt;br /&amp;gt;'s in a given string.
498 * @function
499 * @param {string} string - The string we want to modify.
500 * @returns {string} Returns the string with all the occurrences replaced or an empty string if the element given was not a string.
501 */
502function CB_nl2br(string)
503{
504 //If it is not a string, uses an empty string instead:
505 if (!CB_isString(string)) { string = ""; }
506
507 //Parses the variable to string type:
508 string = string.toString();
509
510 string = string.replace(/\n/gi, "&lt;br />");
511
512 return string;
513}
514var CB_nlToBr = CB_nl2br; //Alias for the function.
515
516
517/**
518 * Alias for {@link CB_br2nl}.
519 * @function CB_brToNl
520 * @see {@link CB_br2nl}
521 */
522/**
523 * Changes &amp;lt;br /&amp;gt;'s, &amp;lt;br/&amp;gt;'s and &amp;lt;br&amp;gt;'s for new lines (\n) in a given string.
524 * @function
525 * @param {string} string - The string we want to modify.
526 * @returns {string} Returns the string with all the occurrences replaced or an empty string if the element given was not a string.
527 */
528function CB_br2nl(string)
529{
530 //If it is not a string, uses an empty string instead:
531 if (!CB_isString(string)) { string = ""; }
532
533 //Parses the variable to string type:
534 string = string.toString();
535
536 string = string.replace(/&lt;br \/>/gi, "\n");
537 string = string.replace(/&lt;br\/>/gi, "\n");
538 string = string.replace(/&lt;br>/gi, "\n");
539
540 return string;
541}
542var CB_brToNl = CB_br2nl; //Alias for the function.
543
544
545/**
546 * 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
547 uses the "file:" protocol or the current script is running locally and the path does not use the "http:", "https:" or "ftp:" protocols.
548 * @function
549 * @param {string} filePath - The file path we want to check.
550 * @returns {boolean} Returns whether the given file path is a local address or not.
551 */
552function CB_isFileLocal(filePath)
553{
554 var isFileLocal = false;
555
556 filePath = CB_trim(filePath);
557
558 if (filePath !== "")
559 {
560 if (filePath.substring(0, 5) === "file:" || CB_Client.isRunningLocally() &amp;&amp; filePath.substring(0, 5) !== "http:" &amp;&amp; filePath.substring(0, 6) !== "https:" &amp;&amp; filePath.substring(0, 4) !== "ftp:")
561 {
562 isFileLocal = true;
563 }
564 }
565
566 return isFileLocal;
567}
568
569
570/**
571 * Processes a given string as a template and returns it rendered (if possible) with the values of the given JSON object.
572 Tries to use [Handlebars]{@link https://handlebarsjs.com/} as the first choice but if is is not available it will just replace all occurrences with
573 vanilla JavaScript.
574 * @function
575 * @param {string} str - The string we want to render.
576 * @param {Object} [JSONObject=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.
577 * @param {boolean} [forceVanilla=false] - Forces vanilla JavaScript rendering instead of using [Handlebars]{@link https://handlebarsjs.com/}.
578 * @param {integer} [depthLevelMax=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.
579 * @returns {str}
580 */
581function CB_renderString(string, JSONObject, forceVanilla, depthLevelMax)
582{
583 string = CB_trim(string);
584
585 //If a JSON object is not given, uses the default one (if any):
586 if (typeof(JSONObject) === "undefined" || JSONObject === null)
587 {
588 if (typeof(CB_JSONData) !== "undefined" &amp;&amp; CB_JSONData !== null) { JSONObject = CB_JSONData; }
589 }
590
591 //If we do not want vanilla JavaScript rendering and Handlebars is present, uses it:
592 if (!forceVanilla &amp;&amp; typeof(Handlebars) !== "undefined" &amp;&amp; Handlebars !== null &amp;&amp; typeof(Handlebars.compile) === "function")
593 {
594 //Returns the template rendered:
595 return Handlebars.compile(string)(JSONObject); //Using Handlebars.
596 }
597 //...otherwise, just replaces all occurrences in the given string:
598 else
599 {
600 return CB_renderStringRecursively(string, JSONObject, false, depthLevelMax);
601 }
602}
603
604
605//Renders a given string recursively with the given object and the given max level:
606function CB_renderStringRecursively(string, desiredObject, avoidRecursive, depthLevelMax, levelCurrent, pathCurrent)
607{
608 if (typeof(desiredObject) === "undefined" || desiredObject === null) { return string; }
609 if (typeof(depthLevelMax) === "undefined" || depthLevelMax === null || isNaN(depthLevelMax)) { depthLevelMax = 10; }
610 if (typeof(levelCurrent) === "undefined" || levelCurrent === null || isNaN(levelCurrent)) { levelCurrent = 0; }
611 if (typeof(pathCurrent) === "undefined" || pathCurrent === null) { pathCurrent = ""; }
612 if (pathCurrent.substring(0, 1) === ".") { pathCurrent = pathCurrent.substring(1); }
613
614 for (var property in desiredObject)
615 {
616 if (CB_sizeof(desiredObject[property]) === 0 || CB_isString(desiredObject[property]))
617 {
618 string = string.replace(CB_regularExpressionString("{{" + pathCurrent + (pathCurrent === "" ? "" : ".") + property + "}}", true, false), desiredObject[property]);
619 }
620 else if (!avoidRecursive &amp;&amp; levelCurrent &lt; depthLevelMax)
621 {
622 string = CB_renderStringRecursively(string, desiredObject[property], avoidRecursive, depthLevelMax, ++levelCurrent, pathCurrent + "." + property);
623 string = string.replace(CB_regularExpressionString("{{" + pathCurrent + (pathCurrent === "" ? "" : ".") + property + "}}", true, false), ""); //In the case is has not been found, clears it.
624 }
625 }
626
627 return string;
628}
629
630
631/**
632 * Tells whether a given email is valid or not. Not really precise.
633 * @function
634 * @param {string} email - Possible email that we want to validate.
635 * @returns {boolean}
636 */
637//* Source: steve @ http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
638function CB_isEmail(email)
639{
640 return (CB_isString(email) &amp;&amp; email.indexOf("..") === -1 &amp;&amp; /^((([a-z]|\d|[!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(email));
641}
642
643
644/**
645 * 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.
646 * @function
647 * @param {integer|float|string} number - The number that we want to format. It can be a string.
648 * @param {integer} [decimals=2] - The number of decimals we want to allow.
649 * @param {boolean} [stringify=false] - Set to true if we want it to return a string (filled with trailing zeros to reach the desired number of decimals).
650 * @returns {integer|float|string} Returns zero in the case a non-valid number has been provided.
651 * @todo 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.
652 */
653function CB_numberFormat(number, decimals, stringify)
654{
655 number = parseFloat(number);
656 if (isNaN(number)) { return 0; }
657 decimals = parseInt(decimals);
658 if (isNaN(decimals) || decimals &lt; 0) { decimals = 2; }
659 number *= Math.pow(10, decimals);
660 number = parseInt(number + 0.5); //Ceil round.
661 number /= Math.pow(10, decimals);
662 if (stringify)
663 {
664 number = number + "";
665
666 //if (number.indexOf(".") === -1) { number += ".00"; }
667 //else if (number.substring(number.indexOf(".") + 1).length === 1) { number += "0"; }
668
669 if (decimals >= 1 &amp;&amp; number.indexOf(".") === -1) { number += "."; }
670 while (number.substring(number.indexOf(".") + 1).length &lt; decimals)
671 {
672 number += "0";
673 }
674 }
675 return number;
676}
677
678
679/**
680 * Alias for {@link CB_countDecimalPart}.
681 * @function CB_countDecimals
682 * @see {@link CB_countDecimalPart}
683 */
684/**
685 * Alias for {@link CB_countDecimalPart}.
686 * @function CB_countDecimalDigits
687 * @see {@link CB_countDecimalPart}
688 */
689/**
690 * Alias for {@link CB_countDecimalPart}.
691 * @function CB_numberOfDecimals
692 * @see {@link CB_countDecimalPart}
693 */
694/**
695 * Alias for {@link CB_countDecimalPart}.
696 * @function CB_numberOfDecimalDigits
697 * @see {@link CB_countDecimalPart}
698 */
699/**
700 * 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).
701 * @function
702 * @param {integer|float|string} number - The number whose decimals we want to count. It can be a string.
703 * @returns {integer} Returns zero in the case a non-valid number has been provided. Otherwise, it returns the number of decimals counted.
704 */
705var CB_countDecimalPart = CB_countDecimalDigits = CB_countDecimals = CB_numberOfDecimals = CB_numberOfDecimalDigits = function(number)
706{
707 number = parseFloat(number);
708 if (isNaN(number)) { return 0; }
709 number = Math.abs(number);
710 if (number % 1 === 0) { return 0; }
711
712 //First it tries "fastest" way (it does not work for numbers in exponential notation):
713 var decimals = (number + "").split(".");
714 decimals = (typeof(decimals[1]) !== "undefined") ? decimals[1].length : 0;
715 if (decimals > 0) { return decimals; }
716
717 //For float numbers that are represented in exponential notation (like '1e-13', for example):
718 decimals = 0;
719 var numberMultiplied = 0;
720 while ((numberMultiplied = number * Math.pow(10, ++decimals)) % 1 !== 0);
721 return decimals;
722}
723
724
725/**
726 * Alias for {@link CB_countIntegerPart}.
727 * @function CB_numberOfIntegerDigits
728 * @see {@link CB_countIntegerPart}
729 */
730 /**
731 * Alias for {@link CB_countIntegerPart}.
732 * @function CB_countIntegerDigits
733 * @see {@link CB_countIntegerPart}
734 */
735/**
736 * 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).
737 * @function
738 * @param {integer|float|string} number - The number whose integer digits (the digits that belong to the integer part) we want to count. It can be a string.
739 * @returns {integer} 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.
740 */
741var CB_countIntegerPart = CB_countIntegerDigits = CB_numberOfIntegerDigits = function(number)
742{
743 number = parseFloat(number);
744 if (isNaN(number)) { return 0; }
745 number = Math.abs(number);
746 if (number &lt; 1) { return 0; }
747
748 //First it tries "fastest" way (it does not work for numbers in exponential notation):
749 var integers = (number + "").split(".");
750 integers = (typeof(integers[1]) !== "undefined") ? integers[0].length : 0;
751 if (integers > 0) { return integers; }
752
753 //For float numbers that are represented in exponential notation (like '1e-13', for example):
754 integers = 0;
755 var numberMultiplied = 0;
756 while ((numberMultiplied = number / Math.pow(10, ++integers)) > 1);
757 return integers;
758}
759
760
761
762/**
763 * Returns the value of a desired path in an object or an empty string if it cannot be found.
764 * @function
765 * @param {Object} object - The object where we want to find the path.
766 * @param {string} path - 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.
767 * @param {string} [splitString="."] - 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.
768 * @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.
769 */
770function CB_getValuePath(object, path, splitString)
771{
772 if (CB_sizeof(object) === 0 || CB_isString(object)) { return ""; }
773
774 path = CB_trim(path);
775 if (path === "") { return object; }
776
777 if (!CB_isString(splitString) || splitString.length &lt; 1) { splitString = "."; }
778 var indexes = path.split(splitString);
779 var indexesLength = indexes.length;
780 var index;
781 var value = object;
782 for (var x = 0; x &lt; indexesLength; x++)
783 {
784 index = CB_trim(indexes[x]);
785 value = CB_getValueIndex(value, index, "");
786 if (CB_sizeof(value) === 0 || CB_isString(value)) { break; }
787 }
788
789 return (x + 1 === indexesLength) ? value : "";
790}
791
792
793var CB_setDatumDateObject = new Date();
794/**
795 * Stores a value using [Web Storage API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API} ([localStorage]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage}). It can use [localStorage]{@link https://github.com/mortzdk/localStorage} as a fallback or cookies instead.
796 * @function
797 * @param {string|number} index - The index where the value given will be stored.
798 * @param {string|number} value - The value we want to store. It should be a string or a number.
799 * @param {integer} [days] - 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.
800 * @param {string} [path] - 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.
801 * @param {boolean} [forceCookie=false] - Forces to use cookies instead of [Web Storage API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API} ([localStorage]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage}).
802 * @returns {boolean} Returns true if the value has been stored successfully (not totally reliable, it should be checked with {@link CB_getDatum} after a while).
803 */
804function CB_setDatum(index, value, days, path, forceCookie)
805{
806 index += "";
807 value += "";
808
809 if (!forceCookie &amp;&amp; window.localStorage &amp;&amp; window.localStorage.setItem)
810 {
811 try
812 {
813 localStorage.setItem(index, value);
814 return true;
815 } catch(E) { }
816 }
817
818 if (typeof(document.cookie) !== "undefined" &amp;&amp; document.cookie !== null)
819 {
820 try
821 {
822 path = CB_trim(path);
823 if (path !== "") { path = ";path=" + escape(path); }
824
825 var expires = "";
826 if (typeof(days) !== "undefined" &amp;&amp; days !== null &amp;&amp; !isNaN(days) &amp;&amp; days >= 0 &amp;&amp; days &lt;= 365)
827 {
828 CB_setDatumDateObject.setTime(CB_setDatumDateObject.getTime() + (days * 24 * 60 * 60 * 1000));
829 expires = ";expires=" + CB_setDatumDateObject.toUTCString();
830 }
831
832 document.cookie = escape(index) + "=" + escape(value) + expires + path;
833 return true;
834 } catch(E) { }
835 }
836
837 return false;
838}
839
840
841/**
842 * Stores a cookie.
843 * @function
844 * @param {string|number} index - The index where the value given will be stored.
845 * @param {string|number} value - The value we want to store. It should be a string or a number.
846 * @param {integer} [days] - 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.
847 * @param {string} [path] - 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.
848 * @returns {boolean} Returns true if the value has been stored successfully (not totally reliable, it should be checked with {@link CB_getCookie} after a while).
849 */
850function CB_setCookie(index, value, days, path)
851{
852 return CB_setDatum(index, value, days, path, true);
853}
854
855
856/**
857 * Gets, from its index, a previous value stored. It will try to get it using [Web Storage API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API} ([localStorage]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage}). It can use [localStorage]{@link https://github.com/mortzdk/localStorage} as a fallback or cookies instead.
858 * @function
859 * @param {string} index - The index whose value we want to retrieve.
860 * @param {boolean} [forceCookie=false] - Forces to use cookies instead of [Web Storage API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API} ([localStorage]{@link https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage}).
861 * @param {boolean} [unescapeIndex=false] - Applies the unescape function to the value before returning it. Only applies when cookies are used.
862 * @returns {string|null} Returns null when the value cannot be found.
863 */
864function CB_getDatum(index, forceCookie, unescapeIndex)
865{
866 var itemFound = null;
867
868 if (window.localStorage &amp;&amp; window.localStorage.getItem &amp;&amp; !forceCookie)
869 {
870 itemFound = localStorage.getItem(index);
871 }
872
873 if (itemFound === null &amp;&amp; typeof(document.cookie) !== "undefined" &amp;&amp; document.cookie !== null)
874 {
875 index += "=";
876 if (unescapeIndex) { index = unescape(index); }
877 var cookies = document.cookie.split(";");
878 var cookies_length = cookies.length;
879 for (var x = 0; x &lt; cookies_length; x++)
880 {
881 if (cookies[x].indexOf(index) !== -1) { return unescape(cookies[x].substring(cookies[x].indexOf(index) + index.length, cookies[x].length)); }
882 }
883 }
884
885 return itemFound;
886}
887
888
889/**
890 * Returns, from its index, a previous stored cookie.
891 * @function
892 * @param {string} index - The index whose value we want to retrieve.
893 * @returns {string|null} Returns null when the value cannot be found.
894 */
895function CB_getCookie(index)
896{
897 return CB_getDatum(index, true);
898}
899
900
901/**
902 * Gets the value from a given object which belongs to the desired index or returns the value of "returnValueOnFail" if it cannot be found.
903 * @function
904 * @param {Object} object - The object from which we want to get the value.
905 * @param {string} index - The index whose value we want to retrieve.
906 * @param {*} [returnValueOnFail=undefined] - The value we want it to return in the case that the property cannot be found. If not provided, undefined will be returned.
907 * @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.
908 */
909function CB_getValueIndex(object, index, returnValueOnFail)
910{
911 if (typeof(object) !== "undefined" &amp;&amp; object !== null &amp;&amp; typeof(object[index]) !== "undefined" &amp;&amp; object[index] !== null) { return object[index]; }
912 else { return returnValueOnFail; }
913}
914
915
916/**
917 * Returns an object copied from the given one.
918 * @function
919 * @param {object} element - The element whose properties and values we want to copy. It should be an object.
920 * @param {boolean} [onlyOwn=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]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty} method).
921 * @returns {object} Returns an object copied from the given one. Returns an empty object if the given "element" was not an object.
922 */
923function CB_copyObject(object, onlyOwn)
924{
925 if (typeof(object) !== "object" || object === null) { return {}; }
926 var newObject = {};
927 for (var key in object)
928 {
929 if (!onlyOwn || object.hasOwnProperty(key)) { newObject[key] = object[key]; }
930 }
931 return newObject;
932}
933
934
935/**
936 * Gets the value of a desired property of a given JSON object. Uses the {@link CB_getValueIndex} function internally.
937 * @function
938 * @param {Object|string} JSONObject - 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 {@link CB_getValueIndex} function internally.
939 * @param {string} property - 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 {@link CB_getValueIndex} function internally.
940 * @param {*} [returnValueOnFail] - 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 {@link CB_getValueIndex} function internally.
941 * @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.
942 */
943function CB_getJSONPropertyValue(JSONObject, property, returnValueOnFail)
944{
945 if (CB_isString(JSONObject)) { JSONObject = CB_parseJSON(JSONObject, undefined, null); } //If a string is received, tries to parse it as a JSON object.
946
947 if (typeof(property) === "undefined" || property === null) { return JSONObject; }
948
949 return CB_getValueIndex(JSONObject, property, returnValueOnFail);
950
951 /*
952 if (typeof(JSONObject) === "undefined" || JSONObject === null)
953 {
954 //if (!property || returnObjectOnFail) { return JSONObject; }
955 return returnValueOnFail;
956 }
957 //else if (property &amp;&amp; typeof(JSONObject[property]) !== "undefined" &amp;&amp; JSONObject[property] !== null) { return JSONObject[property]; }
958 //else if (!property || returnObjectOnFail) { return JSONObject; }
959 else if (typeof(JSONObject[property]) !== "undefined" &amp;&amp; JSONObject[property] !== null) { return JSONObject[property]; }
960 else { return returnValueOnFail; }
961 */
962}
963
964
965/**
966 * Tries to parse a given string to convert it into a JSON object. Internally it will use the native [JSON.parse]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse} method or otherwise use [JSON 3]{@link https://bestiejs.github.io/json3/} instead.
967 * @function
968 * @param {string} objectString - The JSON object we want to parse, in string format. First parameter when calling the [JSON.parse]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse} method (or equivalent)
969 * @param {function} [reviver] - Second parameter when calling the [JSON.parse]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse} method (or equivalent).
970 * @param {*} [returnValueOnFail] - The value we want it to return in the case it cannot be parsed. If not provided, undefined will be returned.
971 * @param {boolean} [acceptUndefinedOrNull=false] - If it is set to true and the given objectString is undefined or null, an empty object ({}) will be used as the objectString.
972 * @param {function} [onError] - Callback which will be called if it failed to be parsed (it will receive the "objectString" as the unique parameter).
973 * @returns {*} Returns the object parsed from the given string or the value of "returnValueOnFail" otherwise (which will be undefined if not provided).
974 */
975function CB_parseJSON(objectString, reviver, returnValueOnFail, acceptUndefinedOrNull, onError)
976{
977 if (typeof(objectString) === "undefined" || objectString === null)
978 {
979 if (acceptUndefinedOrNull) { objectString = '{}'; }
980 }
981
982 objectString = objectString + "";
983 try { return JSON.parse(objectString, reviver); }
984 catch(E)
985 {
986 if (typeof(onError) === "function") { onError(objectString); }
987 return returnValueOnFail;
988 }
989}
990
991
992/**
993 * Tries to create a JSON valid string from a given JSON object or value. Internally it will use the native [JSON.stringify]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify} method or otherwise use [JSON 3]{@link https://bestiejs.github.io/json3/} instead.
994 * @function
995 * @param {*} objectOrValue - The object or value that we want to stringify. First parameter when calling the [JSON.stringify]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify} method (or equivalent).
996 * @param {function} [replacer] - Second parameter when calling the [JSON.stringify]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify} method (or equivalent).
997 * @param {string|integer} [space] - Third parameter when calling the [JSON.stringify]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify} method (or equivalent).
998 * @param {*} [returnValueOnFail] - The value we want it to return in the case it cannot be stringify. If not provided, undefined will be returned.
999 * @param {boolean} [failIfUndefinedOrNull=false] - If it is set to true and the returning value is undefined or null, the value of "returnValueOnFail" will be returned.
1000 * @param {function} [onError] - Callback which will be called if it failed to be stringified (it will receive the "objectOrValue" as the unique parameter).
1001 * @returns {string} 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.
1002 */
1003function CB_stringifyJSON(objectOrValue, replacer, space, returnValueOnFail, failIfUndefinedOrNull, onError)
1004{
1005 try
1006 {
1007 var valueReturned = JSON.stringify(objectOrValue, replacer, space);
1008 if (failIfUndefinedOrNull &amp;&amp; (typeof(valueReturned) === "undefined" || valueReturned === null || valueReturned === "null")) { return returnValueOnFail; }
1009 return valueReturned;
1010 }
1011 catch(E)
1012 {
1013 if (typeof(onError) === "function") { onError(objectOrValue); }
1014 return returnValueOnFail;
1015 }
1016}
1017
1018
1019/**
1020 * Tries to combine two given values guessing the best way to do it and returns their combination. Using the following rules:
1021 &lt;br />
1022 If both values are either undefined or null, returns null.
1023 &lt;br />
1024 Otherwise, if both values are boolean, returns the AND operation for the two of them (a &amp;&amp; b).
1025 &lt;br />
1026 Otherwise, if either of the two is a string (not empty) and is not JSON valid, combines them as URL (GET) parameters using {@link CB_combineURIParameters}.
1027 &lt;br />
1028 Otherwise, if either of them is JSON valid, combines them as JSON using {@link CB_combineJSON} (passing the received avoidDuplicatedValuesInArray value as a parameter).
1029 &lt;br />
1030 Otherwise, combines them as arrays or objects using {@link CB_combineArraysOrObjects} (passing the received "avoidDuplicatedValuesInArray" value as a parameter).
1031 * @function
1032 * @param {*} [a=null|[]|{}] - First value. It can be optional if "b" is a valid value, defined and not null.
1033 * @param {*} [b=null|[]|{}] - Second value. It can be optional if "a" is a valid value, defined and not null.
1034 * @param {boolean} [avoidDuplicatedValuesInArray=false] - Parameter that will be used in the case that {@link CB_combineJSON} or {@link CB_combineArraysOrObjects} is called.
1035 * @param {boolean} [modifyArrayOrObjectA=false] - Parameter that will be used in the case that {@link CB_combineJSON} or {@link CB_combineArraysOrObjects} is called. If set to true, it will modify the original "a" array or object.
1036 * @returns {*}
1037 */
1038function CB_combineAutomatically(a, b, avoidDuplicatedValuesInArray, modifyArrayOrObjectA)
1039{
1040 if ((typeof(a) === "undefined" || a === null) &amp;&amp; (typeof(b) === "undefined" || b === null)) { return null; }
1041 else if ((a === true || a === false) &amp;&amp; (b === true || b === false)) { return a &amp;&amp; b; }
1042
1043 var aJSON = CB_parseJSON(a, undefined, null);
1044 var bJSON = CB_parseJSON(b, undefined, null);
1045
1046 //If either of the two is a string (not empty) and is not JSON valid, combines them as URL (GET) parameters:
1047 if (CB_isString(a) &amp;&amp; CB_trim(a) !== "" &amp;&amp; aJSON === null || CB_isString(b) &amp;&amp; CB_trim(b) !== "" &amp;&amp; bJSON === null) { return CB_combineURIParameters(a, b); }
1048 //...otherwise, if either of them is JSON valid, combines them as JSON:
1049 else if (typeof(aJSON) !== "undefined" &amp;&amp; aJSON !== null &amp;&amp; aJSON !== true &amp;&amp; aJSON !== false || typeof(bJSON) !== "undefined" &amp;&amp; bJSON !== null &amp;&amp; bJSON !== true &amp;&amp; bJSON !== false) { return CB_combineJSON(a, b, avoidDuplicatedValuesInArray, modifyArrayOrObjectA); }
1050 //...otherwise, combines them as associative arrays or objects:
1051 else { return CB_combineArraysOrObjects(a, b, avoidDuplicatedValuesInArray, modifyArrayOrObjectA); }
1052}
1053
1054
1055/**
1056 * Alias for {@link CB_combineURIParameters}.
1057 * @function CB_combineURLParameters
1058 * @see {@link CB_combineURIParameters}
1059 */
1060/**
1061 * Combines two strings as URL (GET) parameters. If either "parametersA" or "parametersB" is not a string, internally it will use the native [JSON.stringify]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify} method if available or otherwise it will use [JSON 3]{@link https://bestiejs.github.io/json3/} instead.
1062 * @function
1063 * @param {string} parametersA - String with the desired parameter or parameters. It can be optional if "parametersB" is a valid string. It will trim any "&amp;" and "?" character at the beginning and at the end, and finally use "&amp;" to concatenate the two strings (if needed).
1064 * @param {string} parametersB - String with the desired parameter or parameters. It can be optional if "parametersA" is a valid string. It will trim any "&amp;" and "?" character at the beginning and at the end, and finally use "&amp;" to concatenate the two strings (if needed).
1065 * @returns {string} For example, if parametersA is "parameter1=value1&amp;amp;parameter2=value2" and parametersB is "parameter3=value3&amp;amp;what=ever" then it will return "parameter1=value1&amp;amp;parameter2=value2&amp;amp;parameter3=value3&amp;amp;what=ever".
1066 */
1067function CB_combineURIParameters(parametersA, parametersB)
1068{
1069 if (typeof(parametersA) === "undefined" || parametersA === null) { parametersA = ""; }
1070 if (typeof(parametersB) === "undefined" || parametersB === null) { parametersB = ""; }
1071 if (!CB_isString(parametersA)) { parametersA = JSON.stringify(parametersA); if (!CB_isString(parametersA)) { parametersA = ""; } }
1072 if (!CB_isString(parametersB)) { parametersB = JSON.stringify(parametersB); if (!CB_isString(parametersB)) { parametersB = ""; } }
1073 if (parametersA !== "") { parametersA = CB_trim(CB_trim(parametersA), ["&amp;", "?"]); }
1074 if (parametersB !== "") { parametersB = CB_trim(CB_trim(parametersB), ["&amp;", "?"]); }
1075 return CB_trim(parametersA + "&amp;" + parametersB, "&amp;");
1076}
1077var CB_combineURLParameters = CB_combineURIParameters; //Alias for the function.
1078
1079
1080/**
1081 * Returns a combined array or object from two arrays or objects. Using the following rules:
1082 &lt;br />
1083 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).
1084 &lt;br />
1085 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):
1086 * @function
1087 * @param {array|Object|string|null|undefined} [arrayOrObjectA=[]|{}] - 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.
1088 * @param {array|Object|string|null|undefined} [arrayOrObjectB=[]|{}] - 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.
1089 * @param {boolean} avoidDuplicatedValuesInArray - 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.
1090 * @param {boolean} [modifyArrayOrObjectA=false] - Parameter that will be used in the case that {@link CB_combineJSON} or {@link CB_combineArraysOrObjects} is called. If set to true, it will modify the original "arrayOrObjectA" array or object.
1091 * @returns {array|Object}
1092 */
1093function CB_combineArraysOrObjects(arrayOrObjectA, arrayOrObjectB, avoidDuplicatedValuesInArray, modifyArrayOrObjectA)
1094{
1095 if (typeof(arrayOrObjectA) === "undefined" || arrayOrObjectA === null || arrayOrObjectA === true || arrayOrObjectA === false)
1096 {
1097 arrayOrObjectA = CB_isArray(arrayOrObjectB) ? [] : {};
1098 }
1099 if (typeof(arrayOrObjectB) === "undefined" || arrayOrObjectB === null || arrayOrObjectB === true || arrayOrObjectB === false)
1100 {
1101 arrayOrObjectB = CB_isArray(arrayOrObjectA) ? [] : {};
1102 }
1103
1104 if (CB_isString(arrayOrObjectA))
1105 {
1106 arrayOrObjectA = CB_parseJSON(arrayOrObjectA, undefined, null);
1107 if (arrayOrObjectA === null) { arrayOrObjectA = CB_isArray(arrayOrObjectB) ? [] : {}; }
1108 }
1109
1110 if (CB_isString(arrayOrObjectB))
1111 {
1112 arrayOrObjectB = CB_parseJSON(arrayOrObjectB, undefined, null);
1113 if (arrayOrObjectB === null) { arrayOrObjectB = CB_isArray(arrayOrObjectA) ? [] : {}; }
1114 }
1115
1116 var mergedObjectOrArray;
1117
1118 //If they both are arrays, it will keep all elements (attaching the elements of the second array after the elements of the first one):
1119 if (CB_isArray(arrayOrObjectA) &amp;&amp; CB_isArray(arrayOrObjectB))
1120 {
1121 if (modifyArrayOrObjectA)
1122 {
1123 mergedObjectOrArray = arrayOrObjectA;
1124 if (!avoidDuplicatedValuesInArray) { mergedObjectOrArray = CB_Arrays.removeDuplicated(mergedObjectOrArray, undefined, false); }
1125 }
1126 else
1127 {
1128 mergedObjectOrArray = [];
1129 var arrayOrObjectALength = arrayOrObjectA.length;
1130 for (var x = 0; x &lt; arrayOrObjectALength; x++)
1131 {
1132 if (!avoidDuplicatedValuesInArray || CB_indexOf(mergedObjectOrArray, arrayOrObjectA[x]) === -1)
1133 {
1134 mergedObjectOrArray[x] = arrayOrObjectA[x];
1135 }
1136 }
1137 }
1138
1139 var arrayOrObjectBLength = arrayOrObjectB.length;
1140 for (var x = 0; x &lt; arrayOrObjectBLength; x++)
1141 {
1142 if (!avoidDuplicatedValuesInArray || CB_indexOf(mergedObjectOrArray, arrayOrObjectB[x]) === -1)
1143 {
1144 mergedObjectOrArray[mergedObjectOrArray.length] = arrayOrObjectB[x];
1145 }
1146 }
1147 }
1148 //...otherwise, if either of them is not an array, it will merge the elements (overwritting those whose index is the same and keeping the ones from the second object/array):
1149 else
1150 {
1151 if (modifyArrayOrObjectA)
1152 {
1153 mergedObjectOrArray = arrayOrObjectA;
1154 if (!avoidDuplicatedValuesInArray &amp;&amp; CB_isArray(arrayOrObjectA)) { mergedObjectOrArray = CB_Arrays.removeDuplicated(arrayOrObjectA, undefined, false); }
1155 }
1156 else
1157 {
1158 mergedObjectOrArray = {};
1159 for (var propertyName in arrayOrObjectA)
1160 {
1161 mergedObjectOrArray[propertyName] = arrayOrObjectA[propertyName];
1162 }
1163 }
1164
1165 for (var propertyName in arrayOrObjectB)
1166 {
1167 mergedObjectOrArray[propertyName] = arrayOrObjectB[propertyName];
1168 }
1169 }
1170
1171 return mergedObjectOrArray;
1172}
1173
1174
1175/**
1176 * Alias for {@link CB_combineArraysOrObjects}.
1177 * @function CB_combineJSON
1178 * @see {@link CB_combineArraysOrObjects}
1179 */
1180 var CB_combineJSON = CB_combineArraysOrObjects;
1181/*
1182function CB_combineJSON(JSONObjectA, JSONObjectB, avoidDuplicatedValuesInArray, modifyArrayOrObjectA)
1183{
1184 return CB_combineArraysOrObjects(JSONObjectA, JSONObjectB, avoidDuplicatedValuesInArray, modifyArrayOrObjectA);
1185}
1186*/
1187
1188
1189/**
1190 Object that contains different properties and methods that can be used as the "baseSymbols" parameter for the {@link CB_intToBase} and {@link CB_baseToInt} functions. Each property is a numeric array of characters.
1191 * @namespace
1192 * @type {Object}
1193 */
1194var CB_baseSymbols =
1195{
1196 "_getCache" : { "max" : [] },
1197
1198 /**
1199 * Function that will return a numeric array of characters containing as many items as the desired base. Uses a cache internally.
1200 * @function
1201 * @param {integer} [base=256] - The desired base (number of items, each with a character, that the returning array will contain). Minimum value is 1. The maximum can differ one client to another but it is not recommended to exceed 4096 (or even lower, depending on the client, although some clients could support up to 63988 or even more). All arrays of bases lower than 87 use the symbols included also in base 87.
1202 * @returns {array} Returns a numeric array of characters containing as many items as the desired base. All arrays of bases lower than 87 use the symbols included also in base 87. When the base is greater than 87 and it is not not created by default (88 and 128), each item of the returning array will be the result of calling the [String.fromCharCode]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode} function from 0 to one number less than the desired base number.
1203 */
1204 "get" : function(base)
1205 {
1206 if (typeof(base) === "undefined" || base === null || isNaN(base) || base &lt; 1) { base = 256; }
1207
1208 if (CB_isArray(CB_baseSymbols[base]) &amp;&amp; CB_baseSymbols[base].length === base) { return CB_baseSymbols[base]; }
1209 else if (CB_isArray(CB_baseSymbols._getCache[base]) &amp;&amp; CB_baseSymbols._getCache[base].length === base) { return CB_baseSymbols._getCache[base]; }
1210
1211 var baseSymbols = [];
1212 var _getCacheLength = CB_baseSymbols._getCache.max.length;
1213 //if (_getCacheLength === base) { return CB_baseSymbols._getCache.max; }
1214
1215 for (var x = 0; x &lt; base &amp;&amp; x &lt; _getCacheLength; x++) { baseSymbols[x] = CB_baseSymbols._getCache.max[x]; }
1216 for (; x &lt; base; x++) { CB_baseSymbols._getCache.max[x] = baseSymbols[x] = String.fromCharCode(x); }
1217
1218 CB_baseSymbols._getCache[base] = baseSymbols;
1219
1220 return baseSymbols;
1221 },
1222
1223 /**
1224 * Alias for {@link CB_baseSymbols.128}.
1225 * @var CB_baseSymbols._128
1226 * @see {@link CB_baseSymbols.128}
1227 */
1228 "_128" : [],
1229 /**
1230 * Numeric array of characters with 128 symbols. These symbols (and also the ones from other bases with higher number) will be encoded by the [escape]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape} function and also by the [encodeURIComponent]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent} function and they will need to be encoded in HTML (not recommended for URI components or JavaScript strings or HTML code).
1231 * @type {array}
1232 * @default An array with each item being the result of calling the [String.fromCharCode]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode} function from 0 to 127 as its unique parameter.
1233 */
1234 "128" : [],
1235
1236 /**
1237 * Alias for {@link CB_baseSymbols.88}.
1238 * @var CB_baseSymbols._88
1239 * @see {@link CB_baseSymbols.88}
1240 */
1241 /**
1242 * Numeric array of characters with 88 symbols. These symbols will be encoded by the [escape]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape} function and also by the [encodeURIComponent]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent} function, but they will not need to be encoded in HTML (not recommended for URI components or JavaScript strings, but useful for HTML code).
1243 * @type {array}
1244 * @default
1245 */
1246 "88" : [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ".", "~", "!", "'", "(", ")", "*", "-", "_", "@", "\\", "/", "|", "[", "]", "{", "}", "$", "%", "=", "?", "^", ":", ";", ",", "+" ],
1247
1248 /**
1249 * Alias for {@link CB_baseSymbols.87}.
1250 * @var CB_baseSymbols._87
1251 * @see {@link CB_baseSymbols.87}
1252 */
1253 /**
1254 * Numeric array of characters with 87 symbols. These symbols will be encoded by the [escape]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape} function and also by the [encodeURIComponent]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent} function but they will not need to be encoded neither in JavaScript strings nor in HTML (not recommended for URI components, but useful for JavaScript strings or HTML code). Includes all symbols from lower bases, respecting the same order (which is their value).
1255 * @type {array}
1256 * @default
1257 */
1258 "87" : [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ".", "*", "-", "_", "~", "!", "'", "(", ")", "@", "/", "|", "[", "]", "{", "}", "$", "%", "=", "?", "^", ":", ";", ",", "+" ],
1259
1260 /**
1261 * Alias for {@link CB_baseSymbols.71}.
1262 * @var CB_baseSymbols._71
1263 * @see {@link CB_baseSymbols.71}
1264 */
1265 /**
1266 * Numeric array of characters with 71 symbols. These symbols will be encoded by the [escape]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape} function but not by the [encodeURIComponent]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent} function (not recommended for URI components in old clients, but useful for URI components in new clients with [encodeURIComponent]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent} function support, for JavaScript strings or HTML code). Includes all symbols from lower bases, respecting the same order (which is their value).
1267 * @type {array}
1268 * @default
1269 */
1270 "71" : [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ".", "*", "-", "_", "~", "!", "'", "(", ")"],
1271
1272 /**
1273 * Alias for {@link CB_baseSymbols.66}.
1274 * @var CB_baseSymbols._66
1275 * @see {@link CB_baseSymbols.66}
1276 */
1277 /**
1278 * Numeric array of characters with 66 symbols. These symbols will not be encoded neither by the [escape]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape} function nor by the [encodeURIComponent]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent} function (recommended for URI components for any client, JavaScript strings or HTML code). Includes Includes all symbols from lower bases, respecting the same order (which is their value).
1279 * @type {array}
1280 * @default
1281 */
1282 "66" : [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ".", "*", "-", "_" ],
1283
1284 /**
1285 * Alias for {@link CB_baseSymbols.64}.
1286 * @var CB_baseSymbols._64
1287 * @see {@link CB_baseSymbols.64}
1288 */
1289 /**
1290 * Numeric array of characters with 64 symbols (using 0 to 9, A to Z, a to z, "." and "*"). These symbols will not be encoded neither by the [escape]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape} function nor by the [encodeURIComponent]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent} function (recommended for URI components for any client, JavaScript strings or HTML code in the case that we do not want to use base 66 from the {@link CB_baseSymbols.66} property). Includes all symbols from lower bases, respecting the same order (which is their value).
1291 * @type {array}
1292 * @default
1293 */
1294 "64" : [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ".", "*" ],
1295
1296 /**
1297 * Alias for {@link CB_baseSymbols.16}.
1298 * @var CB_baseSymbols._16
1299 * @see {@link CB_baseSymbols.16}
1300 */
1301 /**
1302 * Numeric array of characters with 16 symbols (using 0 to 9, A to F), hexadecimal system. These symbols will not be encoded neither by the [escape]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape} function nor by the [encodeURIComponent]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent} function (recommended for URI components for any client, JavaScript strings or HTML code). Includes all symbols from lower bases, respecting the same order (which is their value).
1303 * @type {array}
1304 * @default
1305 */
1306 "16" : [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" ],
1307
1308 /**
1309 * Alias for {@link CB_baseSymbols.10}.
1310 * @var CB_baseSymbols._10
1311 * @see {@link CB_baseSymbols.10}
1312 */
1313 /**
1314 * Numeric array of characters with 10 symbols (using 0 to 9), decimal system. These symbols will not be encoded neither by the [escape]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape} function nor by the [encodeURIComponent]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent} function (recommended for URI components for any client, JavaScript strings or HTML code). Includes all symbols from lower bases, respecting the same order (which is their value).
1315 * @type {array}
1316 * @default
1317 */
1318 "10" : [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ],
1319
1320 /**
1321 * Alias for {@link CB_baseSymbols.8}.
1322 * @var CB_baseSymbols._8
1323 * @see {@link CB_baseSymbols.8}
1324 */
1325 /**
1326 * Numeric array of characters with 8 symbols (using 0 to 7), octal system. These symbols will not be encoded neither by the [escape]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape} function nor by the [encodeURIComponent]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent} function (recommended for URI components for any client, JavaScript strings or HTML code). Includes all symbols from lower bases, respecting the same order (which is their value).
1327 * @type {array}
1328 * @default
1329 */
1330 "8" : [ "0", "1", "2", "3", "4", "5", "6", "7" ],
1331
1332 /**
1333 * Alias for {@link CB_baseSymbols.2}.
1334 * @var CB_baseSymbols._8
1335 * @see {@link CB_baseSymbols.2}
1336 */
1337 /**
1338 * Numeric array of characters with 2 symbols (using 0 and 1), binary system. These symbols will not be encoded neither by the [escape]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape} function nor by the [encodeURIComponent]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent} function (recommended for URI components for any client, JavaScript strings or HTML code).
1339 * @type {array}
1340 * @default
1341 */
1342 "2" : [ "0", "1" ]
1343};
1344CB_baseSymbols._128 = CB_baseSymbols["128"] = CB_baseSymbols.get(128);
1345CB_baseSymbols._88 = CB_baseSymbols["88"];
1346CB_baseSymbols._87 = CB_baseSymbols["87"];
1347CB_baseSymbols._71 = CB_baseSymbols["71"];
1348CB_baseSymbols._66 = CB_baseSymbols["66"];
1349CB_baseSymbols._64 = CB_baseSymbols["64"];
1350CB_baseSymbols._16 = CB_baseSymbols["16"];
1351CB_baseSymbols._10 = CB_baseSymbols["10"];
1352CB_baseSymbols._8 = CB_baseSymbols["8"];
1353CB_baseSymbols._2 = CB_baseSymbols["2"];
1354for (CB_baseSymbols._x = 3; CB_baseSymbols._x &lt; 87; CB_baseSymbols._x++)
1355{
1356 if (typeof(CB_baseSymbols[CB_baseSymbols._x]) !== "undefined") { continue; }
1357 CB_baseSymbols["_" + CB_baseSymbols._x] = CB_baseSymbols[CB_baseSymbols._x] = CB_baseSymbols._87.slice(0, CB_baseSymbols._x);
1358}
1359
1360
1361/**
1362 * Converts a given integer into a desired base.
1363 * @function
1364 * @param {integer|string} number - 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.
1365 * @param {array|integer} [baseSymbols={@link 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 {@link CB_baseSymbols} object and use it if found or use it as a parameter to call the {@link CB_baseSymbols.get} function otherwise. If not provided or the integer is lower than 2, it will use base 66 (defined in the {@link CB_baseSymbols._66} property of the {@link 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 {@link CB_baseSymbols} object or the {@link CB_baseSymbols.get} function can be used for this parameter.
1366 * @param {boolean} [unsigned=false] - Determines whether to treat the input and output numbers as unsigned or not.
1367 * @param {string} [minusSymbol='-'|'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.
1368 * @param {prefix} [prefix='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.
1369 * @returns {string} 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.
1370 * @todo 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.
1371 * @todo 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, ).
1372 * @todo Think about accepting a decimal symbol to separate decimals and support float numbers.
1373 */
1374function CB_intToBase(number, baseSymbols, unsigned, minusSymbol, prefix)
1375{
1376 number = parseInt(number);
1377 if (isNaN(number)) { return ""; }
1378
1379 var isNegative = false;
1380 if (!unsigned &amp;&amp; number &lt; 0) { isNegative = true; }
1381
1382 if (!CB_isArray(baseSymbols))
1383 {
1384 if (typeof(baseSymbols) !== "undefined" &amp;&amp; baseSymbols !== null &amp;&amp; !isNaN(baseSymbols) &amp;&amp; baseSymbols >= 2)
1385 {
1386 if (CB_isArray(CB_baseSymbols[baseSymbols])) { baseSymbols = CB_baseSymbols[baseSymbols]; }
1387 else { baseSymbols = CB_baseSymbols.get(baseSymbols); }
1388 }
1389 else { baseSymbols = CB_baseSymbols._66; }
1390 }
1391
1392 baseRadix = baseSymbols.length;
1393 if (!unsigned &amp;&amp; isNegative &amp;&amp; (typeof(minusSymbol) === "undefined" || minusSymbol === null)) { minusSymbol = baseRadix &lt;= 16 ? "-" : "0"; }
1394
1395 var total = "";
1396
1397 number = Math.abs(number);
1398 if (number >= baseRadix)
1399 {
1400 total = CB_intToBase(number / baseRadix, baseSymbols, true, "", "");
1401 number = parseInt(number % baseRadix);
1402 }
1403
1404 total += baseSymbols[number];
1405
1406 if (typeof(prefix) === "undefined" || prefix === null)
1407 {
1408 if (baseRadix === 8) { prefix = "0"; }
1409 else if (baseRadix === 16) { prefix = "0x"; }
1410 else { prefix = null; }
1411 }
1412 if (prefix !== null) { total = prefix + total; }
1413
1414 if (!unsigned &amp;&amp; isNegative) { total = minusSymbol + total; }
1415
1416 return total;
1417}
1418
1419
1420/**
1421 * Converts a given number which is already in a desired base into an integer (decimal base).
1422 &lt;br />
1423 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.
1424 * @function
1425 * @param {string} number - A string containing the number which is already in the desired base and that we want to convert to an integer.
1426 * @param {array|integer} [baseSymbols={@link 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 {@link CB_baseSymbols} object and use it if found or use it as a parameter to call the {@link CB_baseSymbols.get} function otherwise. If not provided or the integer is lower than 2, it will use base 66 (defined in the {@link CB_baseSymbols._66} property of the {@link 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 {@link CB_baseSymbols} object or the {@link CB_baseSymbols.get} function can be used for this parameter.
1427 * @param {boolean} [unsigned=false] - Determines whether to treat the input and output numbers as unsigned or not.
1428 * @param {string} [minusSymbol='-'|'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.
1429 * @param {prefix} [prefix='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.
1430 * @returns {integer} Returns the integer number in decimal base.
1431 * @todo 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.
1432 * @todo Think about allowing to specify the base for the integer.
1433 * @todo Think about accepting a decimal symbol to separate decimals and support float numbers.
1434 */
1435function CB_baseToInt(number, baseSymbols, unsigned, minusSymbol, prefix)
1436{
1437 number = "" + number;
1438 if (!CB_isArray(baseSymbols))
1439 {
1440 if (typeof(baseSymbols) !== "undefined" &amp;&amp; baseSymbols !== null &amp;&amp; !isNaN(baseSymbols) &amp;&amp; baseSymbols >= 2)
1441 {
1442 if (CB_isArray(CB_baseSymbols[baseSymbols])) { baseSymbols = CB_baseSymbols[baseSymbols]; }
1443 else { baseSymbols = CB_baseSymbols.get(baseSymbols); }
1444 }
1445 else { baseSymbols = CB_baseSymbols._66; }
1446 }
1447
1448 var value = CB_indexOf(baseSymbols, number.substring(number.length-1));
1449
1450 if (value === -1) { return 0; }
1451
1452 baseRadix = baseSymbols.length;
1453
1454 var isNegative = false;
1455 if (!unsigned)
1456 {
1457 if (typeof(minusSymbol) === "undefined" || minusSymbol === null) { minusSymbol = baseRadix &lt;= 16 ? "-" : "0"; }
1458 else { minusSymbol = minusSymbol + ""; }
1459 if (number.substring(0, minusSymbol.length) === minusSymbol)
1460 {
1461 number = number.substring(minusSymbol.length);
1462 isNegative = true;
1463 }
1464 }
1465
1466 if (typeof(prefix) === "undefined" || prefix === null)
1467 {
1468 if (baseRadix === 8) { prefix = "0"; }
1469 else if (baseRadix === 16) { prefix = "0x"; }
1470 else { prefix = null; }
1471 }
1472
1473 if (prefix !== null &amp;&amp; prefix.length &amp;&amp; number.substring(0, prefix.length) === prefix)
1474 {
1475 number = number.substring(prefix.length);
1476 }
1477
1478 number = number.substring(0, number.length - 1);
1479 if (number !== "")
1480 {
1481 value += CB_baseToInt(number, baseSymbols, true, "", "") * baseRadix;
1482 }
1483
1484 if (isNegative &amp;&amp; value > 0) { value *= -1; }
1485
1486 return value;
1487}
1488
1489
1490
1491/**
1492 * Converts a given number which is already in a desired base into another chosen base.
1493 &lt;br />
1494 Note: Uses {@link CB_baseToInt} and {@link CB_intToBase} internally.
1495 * @function
1496 * @param {string} number - 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 {@link CB_intToBase} and {@link CB_baseToInt} functions internally.
1497 * @param {array|integer} [baseSymbolsOrigin={@link CB_baseSymbols.66}] - Used as the "baseSymbols" parameter when calling the {@link CB_baseToInt} function internally.
1498 * @param {array|integer} [baseSymbolsDestiny={@link CB_baseSymbols.66}] - Used as the "baseSymbols" parameter when calling the {@link CB_intToBase} function internally.
1499 * @param {boolean} [unsigned=false] - Determines whether to treat the input and output numbers as unsigned or not. Used as the "unsigned" parameter for calling both {@link CB_intToBase} and {@link CB_baseToInt} functions internally.
1500 * @param {string} [minusSymbolOrigin='-'|'0'] - Used as the "minusSymbol" parameter when calling the {@link CB_baseToInt} function internally.
1501 * @param {string} [minusSymbolDestiny='-'|'0'] - Used as the "minusSymbol" parameter when calling the {@link CB_intToBase} function internally.
1502 * @param {prefix} [prefixOrigin='0'|'0x'|''] - Used as the "prefix" parameter when calling the {@link CB_baseToInt} function internally.
1503 * @param {prefix} [prefixDestiny='0'|'0x'|''] - Used as the "prefix" parameter when calling the {@link CB_intToBase} function internally.
1504 * @returns {string} Returns the returning value of the internal call to the {@link CB_intToBase} function.
1505 * @todo Think about accepting a decimal symbol to separate decimals and support float numbers.
1506 */
1507function CB_baseToBase(number, baseSymbolsOrigin, baseSymbolsDestiny, unsigned, minusSymbolOrigin, minusSymbolDestiny, prefixOrigin, prefixDestiny)
1508{
1509 var numberDecimal = CB_baseToInt(number, baseSymbolsOrigin, unsigned, minusSymbolOrigin, prefixOrigin);
1510 return CB_intToBase(numberDecimal, baseSymbolsDestiny, unsigned, minusSymbolDestiny, prefixDestiny);
1511}
1512
1513
1514/**
1515 * Returns the string or array of strings with all the desired occurrences replaced. Calls itself recursively and calls the {@link CB_regularExpressionString} function internally.
1516 * @function
1517 * @param {string|array} stringOrArray - 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.
1518 * @param {string|array} stringOrArrayFind - An string or an array of strings (not a regular expressions) that we want to find to be replaced (special characters will be escaped).
1519 * @param {string} [stringReplace=""] - The string that will replace "stringFind". If not provided, it will be replaced as an empty string (it will just remove the occurrences found).
1520 * @param {boolean} [caseInsensitive=false] - Defines whether we want to be case insensitive or not.
1521 * @returns {string|array} 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.
1522 */
1523function CB_replaceAll(stringOrArray, stringOrArrayFind, stringReplace, caseInsensitive)
1524{
1525 if (CB_isArray(stringOrArray))
1526 {
1527 var arrayCopy = [];
1528 for (var x = 0; x &lt; stringOrArray.length; x++)
1529 {
1530 arrayCopy[x] = CB_replaceAll(stringOrArray[x], stringOrArrayFind, stringReplace, caseInsensitive);
1531 }
1532 stringOrArray = arrayCopy;
1533 }
1534 else if (CB_isString(stringReplace))
1535 {
1536 stringOrArrayFind = CB_isArray(stringOrArrayFind) ? stringOrArrayFind : [ stringOrArrayFind ];
1537 for (var x = 0; x &lt; stringOrArrayFind.length; x++)
1538 {
1539 stringOrArray = (stringOrArray + "").replace(CB_regularExpressionString(stringOrArrayFind[x], true, caseInsensitive), stringReplace);
1540 }
1541 }
1542 return stringOrArray; //If it is neither a string nor an array, it will be returned without being modified.
1543}
1544
1545
1546
1547/**
1548 * Returns a desired regular expression (escaping the string) using the native JavaScript's [RegExp]{@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp} from a given string.
1549 * @function
1550 * @param {string} string - The string (not a regular expression) that we want to use (special characters will be escaped).
1551 * @param {boolean} [allOccurrences=false] - Defines whether we want the regular expression returned to match all occurrences of the given string or only first found.
1552 * @param {boolean} [caseInsensitive=false] - Defines whether we want the regular expression returned to be case insensitive or not.
1553 * @returns {RegExp} Returns the desired regular expression (escaping the string) using the native JavaScript's [RegExp]{@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp} from a given string.
1554 */
1555//* Source: Cory Gross @ http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript
1556function CB_regularExpressionString(string, allOccurrences, caseInsensitive)
1557{
1558 var parameters = "";
1559 if (allOccurrences) { parameters += "g"; }
1560 if (caseInsensitive) { parameters += "i"; }
1561 return new RegExp(string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&amp;"), parameters === "" ? undefined : parameters);
1562}
1563
1564
1565/**
1566 * Returns the "LZString" object (used by the [lz-string]{@link http://pieroxy.net/blog/pages/lz-string/index.html} library), if any. Useful for compressing/decompressing strings.
1567 * @function
1568 * @returns {Object} Returns the "LZString" object (used by the [lz-string]{@link http://pieroxy.net/blog/pages/lz-string/index.html} library) if available or null otherwise.
1569 */
1570function CB_getLZStringObject()
1571{
1572 return (typeof(LZString) === "object") ? LZString : null;
1573}
1574
1575
1576/**
1577 * Returns the "Base64String" object (used by the base64-string library included in [lz-string]{@link http://pieroxy.net/blog/pages/lz-string/index.html}), if any. Useful for compressing/decompressing base64 code.
1578 * @function
1579 * @returns {Object} Returns the "Base64String" object (used by the base64-string library included in [lz-string]{@link http://pieroxy.net/blog/pages/lz-string/index.html}) if available or null otherwise.
1580 */
1581function CB_getBase64StringObject()
1582{
1583 return (typeof(Base64String) === "object") ? Base64String : null;
1584}</pre>
1585 </article>
1586</section>
1587
1588
1589
1590
1591
1592 </div>
1593 </div>
1594
1595 <div class="clearfix"></div>
1596
1597
1598
1599</div>
1600</div>
1601
1602
1603 <div class="modal fade" id="searchResults">
1604 <div class="modal-dialog">
1605 <div class="modal-content">
1606 <div class="modal-header">
1607 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
1608 <h4 class="modal-title">Search results</h4>
1609 </div>
1610 <div class="modal-body"></div>
1611 <div class="modal-footer">
1612 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
1613 </div>
1614 </div><!-- /.modal-content -->
1615 </div><!-- /.modal-dialog -->
1616 </div>
1617
1618
1619<footer>
1620
1621
1622 <span class="copyright">
1623 <a href="printable/" target="_blank">See a more printer-friendly version</a><hr /><span style="color:#000000">© <address style="display:inline; font-style:normal;"><a href="https://crossbrowdy.com/" target="_blank">CrossBrowdy</a> API documentation</address> by <a href="https://joanalbamaldonado.com/" target="_blank">Joan Alba Maldonado</a> - <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank">Creative Commons Attribution 4.0 International</a><br />DocStrap Copyright © 2012-2015 The contributors to the JSDoc3 and DocStrap projects.</span>
1624 </span>
1625
1626<span class="jsdoc-message">
1627 Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
1628
1629 on Mon Feb 3rd 2020
1630
1631 using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
1632</span>
1633</footer>
1634
1635<script src="scripts/docstrap.lib.js"></script>
1636<script src="scripts/toc.js"></script>
1637
1638 <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
1639
1640
1641<script>
1642$( function () {
1643 $( "[id*='$']" ).each( function () {
1644 var $this = $( this );
1645
1646 $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
1647 } );
1648
1649 $( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
1650 var $this = $( this );
1651
1652 var example = $this.find( "code" );
1653 exampleText = example.html();
1654 var lang = /{@lang (.*?)}/.exec( exampleText );
1655 if ( lang && lang[1] ) {
1656 exampleText = exampleText.replace( lang[0], "" );
1657 example.html( exampleText );
1658 lang = lang[1];
1659 } else {
1660 var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
1661 lang = langClassMatch ? langClassMatch[1] : "javascript";
1662 }
1663
1664 if ( lang ) {
1665
1666 $this
1667 .addClass( "sunlight-highlight-" + lang )
1668 .addClass( "linenums" )
1669 .html( example.html() );
1670
1671 }
1672 } );
1673
1674 Sunlight.highlightAll( {
1675 lineNumbers : true,
1676 showMenu : true,
1677 enableDoclinks : true
1678 } );
1679
1680 $.catchAnchorLinks( {
1681 navbarOffset: 10
1682 } );
1683 $( "#toc" ).toc( {
1684 anchorName : function ( i, heading, prefix ) {
1685 return $( heading ).attr( "id" ) || ( prefix + i );
1686 },
1687 selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
1688 showAndHide : false,
1689 smoothScrolling: true
1690 } );
1691
1692 $( "#main span[id^='toc']" ).addClass( "toc-shim" );
1693 $( '.dropdown-toggle' ).dropdown();
1694
1695 $( "table" ).each( function () {
1696 var $this = $( this );
1697 $this.addClass('table');
1698 } );
1699
1700} );
1701</script>
1702
1703
1704
1705<!--Navigation and Symbol Display-->
1706
1707<script>
1708 $( function () {
1709 $( '#main' ).localScroll( {
1710 offset : { top : 60 } //offset by the height of your header (give or take a few px, see what works for you)
1711 } );
1712 $( "dt.name" ).each( function () {
1713 var $this = $( this ).find("h4");
1714 var icon = $( "<i/>" ).addClass( "icon-plus-sign" ).addClass( "pull-right" ).addClass( "icon-white" );
1715 var dt = $(this);
1716 var children = dt.next( "dd" );
1717
1718 dt.prepend( icon ).css( {cursor : "pointer"} );
1719 dt.addClass( "member-collapsed" ).addClass( "member" );
1720
1721
1722 children.hide();
1723
1724 dt.children().on( "click", function () {
1725 children = dt.next( "dd" );
1726 children.slideToggle( "fast", function () {
1727
1728 if ( children.is( ":visible" ) ) {
1729 icon.addClass( "icon-minus-sign" ).removeClass( "icon-plus-sign" ).removeClass( "icon-white" );
1730 dt.addClass( "member-open" ).animate( "member-collapsed" );
1731 } else {
1732 icon.addClass( "icon-plus-sign" ).removeClass( "icon-minus-sign" ).addClass( "icon-white" );
1733 dt.addClass( "member-collapsed" ).removeClass( "member-open" );
1734 }
1735 } );
1736 } );
1737
1738 } );
1739 } );
1740</script>
1741
1742
1743<!--Google Analytics-->
1744
1745
1746
1747 <script type="text/javascript">
1748 $(document).ready(function() {
1749 SearcherDisplay.init();
1750 });
1751 </script>
1752
1753
1754</body>
1755</html>