jsduck 3.0.pre → 3.0.pre2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1034 @@
1
+ /**
2
+ * @class String
3
+ *
4
+ * `String` is a global object that may be used to construct String instances.
5
+ *
6
+ * String objects may be created by calling the constructor `new String()`. The `String` object wraps
7
+ * JavaScript's string primitive data type with the methods described below. The global function
8
+ * `String()` can also be called without new in front to create a primitive string. String literals in
9
+ * JavaScript are primitive strings.
10
+ *
11
+ * Because JavaScript automatically converts between string primitives and String objects, you can call
12
+ * any of the methods of the `String` object on a string primitive. JavaScript automatically converts the
13
+ * string primitive to a temporary `String` object, calls the method, then discards the temporary String
14
+ * object. For example, you can use the `String.length` property on a string primitive created from a
15
+ * string literal:
16
+ *
17
+ * s_obj = new String(s_prim = s_also_prim = "foo");
18
+ *
19
+ * s_obj.length; // 3
20
+ * s_prim.length; // 3
21
+ * s_also_prim.length; // 3
22
+ * 'foo'.length; // 3
23
+ * "foo".length; // 3
24
+ *
25
+ * (A string literal is denoted with single or double quotation marks.)
26
+ *
27
+ * String objects can be converted to primitive strings with the `valueOf` method.
28
+ *
29
+ * String primitives and String objects give different results when evaluated as JavaScript. Primitives
30
+ * are treated as source code; String objects are treated as a character sequence object. For example:
31
+ *
32
+ * s1 = "2 + 2"; // creates a string primitive
33
+ * s2 = new String("2 + 2"); // creates a String object
34
+ * eval(s1); // returns the number 4
35
+ * eval(s2); // returns the string "2 + 2"
36
+ * eval(s2.valueOf()); // returns the number 4
37
+ *
38
+ * # Character access
39
+ *
40
+ * There are two ways to access an individual character in a string. The first is the `charAt` method:
41
+ *
42
+ * return 'cat'.charAt(1); // returns "a"
43
+ *
44
+ * The other way is to treat the string as an array, where each index corresponds to an individual
45
+ * character:
46
+ *
47
+ * return 'cat'[1]; // returns "a"
48
+ *
49
+ * The second way (treating the string as an array) is not part of ECMAScript 3. It is a JavaScript and
50
+ * ECMAScript 5 feature.
51
+ *
52
+ * In both cases, attempting to set an individual character won't work. Trying to set a character
53
+ * through `charAt` results in an error, while trying to set a character via indexing does not throw an
54
+ * error, but the string itself is unchanged.
55
+ *
56
+ * # Comparing strings
57
+ *
58
+ * C developers have the `strcmp()` function for comparing strings. In JavaScript, you just use the less-
59
+ * than and greater-than operators:
60
+ *
61
+ * var a = "a";
62
+ * var b = "b";
63
+ * if (a < b) // true
64
+ * print(a + " is less than " + b);
65
+ * else if (a > b)
66
+ * print(a + " is greater than " + b);
67
+ * else
68
+ * print(a + " and " + b + " are equal.");
69
+ *
70
+ * A similar result can be achieved using the `localeCompare` method inherited by `String` instances.
71
+ *
72
+ * <div class="notice">
73
+ * Documentation for this class comes from <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String">MDN</a>
74
+ * and is available under <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons: Attribution-Sharealike license</a>.
75
+ * </div>
76
+ */
77
+
78
+ /**
79
+ * @method constructor
80
+ * Creates new String object.
81
+ * @param {Object} value The value to wrap into String object.
82
+ */
83
+
84
+ //Methods
85
+
86
+ /**
87
+ * @method fromCharCode
88
+ * Returns a string created by using the specified sequence of Unicode values.
89
+ *
90
+ * This method returns a string and not a `String` object.
91
+ *
92
+ * Because `fromCharCode` is a static method of `String`, you always use it as `String.fromCharCode()`,
93
+ * rather than as a method of a `String` object you created.
94
+ *
95
+ * Although most common Unicode values can be represented in a fixed width system/with one number (as
96
+ * expected early on during JavaScript standardization) and `fromCharCode()` can be used to return a
97
+ * single character for the most common values (i.e., UCS-2 values which are the subset of UTF-16 with
98
+ * the most common characters), in order to deal with ALL legal Unicode values, `fromCharCode()` alone
99
+ * is inadequate. Since the higher code point characters use two (lower value) "surrogate" numbers to
100
+ * form a single character, `fromCharCode()` can be used to return such a pair and thus adequately
101
+ * represent these higher valued characters.
102
+ *
103
+ * Be aware, therefore, that the following utility function to grab the accurate character even for
104
+ * higher value code points, may be returning a value which is rendered as a single character, but
105
+ * which has a string count of two (though usually the count will be one).
106
+ *
107
+ * // String.fromCharCode() alone cannot get the character at such a high code point
108
+ * // The following, on the other hand, can return a 4-byte character as well as the
109
+ * // usual 2-byte ones (i.e., it can return a single character which actually has
110
+ * // a string length of 2 instead of 1!)
111
+ * alert(fixedFromCharCode(0x2F804)); // or 194564 in decimal
112
+ *
113
+ * function fixedFromCharCode (codePt) {
114
+ * if (codePt > 0xFFFF) {
115
+ * codePt -= 0x10000;
116
+ * return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 +
117
+ * (codePt & 0x3FF));
118
+ * }
119
+ * else {
120
+ * return String.fromCharCode(codePt);
121
+ * }
122
+ * }
123
+ *
124
+ * The following example returns the string "ABC".
125
+ *
126
+ * String.fromCharCode(65,66,67)
127
+ *
128
+ * @param {Number} num1, ..., numN A sequence of numbers that are Unicode values.
129
+ * @return {String} String containing characters from encoding.
130
+ */
131
+
132
+ //Properties
133
+
134
+ /**
135
+ * @property {Number} length
136
+ * Reflects the length of the string.
137
+ *
138
+ * This property returns the number of code units in the string. UTF-16, the string format used by JavaScript, uses a single 16-bit
139
+ * code unit to represent the most common characters, but needs to use two code units for less commonly-used characters, so it's
140
+ * possible for the value returned by `length` to not match the actual number of characters in the string.
141
+ *
142
+ * For an empty string, `length` is 0.
143
+ *
144
+ * var x = "Netscape";
145
+ * var empty = "";
146
+ *
147
+ * console.log("Netspace is " + x.length + " code units long");
148
+ * console.log("The empty string is has a length of " + empty.length); // should be 0
149
+ */
150
+
151
+ //Methods
152
+
153
+ /**
154
+ * @method charAt
155
+ * Returns the character at the specified index.
156
+ *
157
+ * Characters in a string are indexed from left to right. The index of the first character is 0, and
158
+ * the index of the last character in a string called `stringName` is `stringName.length - 1`. If the
159
+ * index you supply is out of range, JavaScript returns an empty string.
160
+ *
161
+ * The following example displays characters at different locations in the string "Brave new world":
162
+ *
163
+ * var anyString="Brave new world";
164
+ *
165
+ * document.writeln("The character at index 0 is '" + anyString.charAt(0) + "'");
166
+ * document.writeln("The character at index 1 is '" + anyString.charAt(1) + "'");
167
+ * document.writeln("The character at index 2 is '" + anyString.charAt(2) + "'");
168
+ * document.writeln("The character at index 3 is '" + anyString.charAt(3) + "'");
169
+ * document.writeln("The character at index 4 is '" + anyString.charAt(4) + "'");
170
+ * document.writeln("The character at index 999 is '" + anyString.charAt(999) + "'");
171
+ *
172
+ * These lines display the following:
173
+ *
174
+ * The character at index 0 is 'B'
175
+ * The character at index 1 is 'r'
176
+ * The character at index 2 is 'a'
177
+ * The character at index 3 is 'v'
178
+ * The character at index 4 is 'e'
179
+ * The character at index 999 is ''
180
+ *
181
+ * The following provides a means of ensuring that going through a string loop always provides a whole
182
+ * character, even if the string contains characters that are not in the Basic Multi-lingual Plane.
183
+ *
184
+ * var str = 'A\uD87E\uDC04Z'; // We could also use a non-BMP character directly
185
+ * for (var i=0, chr; i < str.length; i++) {
186
+ * if ((chr = getWholeChar(str, i)) === false) {continue;} // Adapt this line at the top of
187
+ * each loop, passing in the whole string and the current iteration and returning a variable to
188
+ * represent the individual character
189
+ * alert(chr);
190
+ * }
191
+ *
192
+ * function getWholeChar (str, i) {
193
+ * var code = str.charCodeAt(i);
194
+ *
195
+ * if (isNaN(code)) {
196
+ * return ''; // Position not found
197
+ * }
198
+ * if (code < 0xD800 || code > 0xDFFF) {
199
+ * return str.charAt(i);
200
+ * }
201
+ * if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F
202
+ * to treat high private surrogates as single characters)
203
+ * if (str.length <= (i+1)) {
204
+ * throw 'High surrogate without following low surrogate';
205
+ * }
206
+ * var next = str.charCodeAt(i+1);
207
+ * if (0xDC00 > next || next > 0xDFFF) {
208
+ * throw 'High surrogate without following low surrogate';
209
+ * }
210
+ * return str.charAt(i)+str.charAt(i+1);
211
+ * }
212
+ * // Low surrogate (0xDC00 <= code && code <= 0xDFFF)
213
+ * if (i === 0) {
214
+ * throw 'Low surrogate without preceding high surrogate';
215
+ * }
216
+ * var prev = str.charCodeAt(i-1);
217
+ * if (0xD800 > prev || prev > 0xDBFF) { // (could change last hex to 0xDB7F to treat high private
218
+ * surrogates as single characters)
219
+ * throw 'Low surrogate without preceding high surrogate';
220
+ * }
221
+ * return false; // We can pass over low surrogates now as the second component in a pair which we
222
+ * have already processed
223
+ * }
224
+ *
225
+ * While the second example may be more frequently useful for those wishing to support non-BMP
226
+ * characters (since the above does not require the caller to know where any non-BMP character might
227
+ * appear), in the event that one _does_ wish, in choosing a character by index, to treat the surrogate
228
+ * pairs within a string as the single characters they represent, one can use the following:
229
+ *
230
+ * function fixedCharAt (str, idx) {
231
+ * var ret = '';
232
+ * str += '';
233
+ * var end = str.length;
234
+ *
235
+ * var surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
236
+ * while ((surrogatePairs.exec(str)) != null) {
237
+ * var li = surrogatePairs.lastIndex;
238
+ * if (li - 2 < idx) {
239
+ * idx++;
240
+ * }
241
+ * else {
242
+ * break;
243
+ * }
244
+ * }
245
+ *
246
+ * if (idx >= end || idx < 0) {
247
+ * return '';
248
+ * }
249
+ *
250
+ * ret += str.charAt(idx);
251
+ *
252
+ * if (/[\uD800-\uDBFF]/.test(ret) && /[\uDC00-\uDFFF]/.test(str.charAt(idx+1))) {
253
+ * ret += str.charAt(idx+1); // Go one further, since one of the "characters" is part of a
254
+ * surrogate pair
255
+ * }
256
+ * return ret;
257
+ * }
258
+ *
259
+ * @param {Number} index An integer between 0 and 1 less than the length of the string.
260
+ * @return {String} Individual character from string.
261
+ */
262
+
263
+ /**
264
+ * @method charCodeAt
265
+ * Returns a number indicating the Unicode value of the character at the given index.
266
+ *
267
+ * Unicode code points range from 0 to 1,114,111. The first 128 Unicode code points are a direct match
268
+ * of the ASCII character encoding.
269
+ *
270
+ * Note that `charCodeAt` will always return a value that is less than 65,536. This is because the
271
+ * higher code points are represented by a pair of (lower valued) "surrogate" pseudo-characters which
272
+ * are used to comprise the real character. Because of this, in order to examine or reproduce the full
273
+ * character for individual characters of value 65,536 and above, for such characters, it is necessary
274
+ * to retrieve not only `charCodeAt(i)`, but also `charCodeAt(i+1)` (as if examining/reproducing a
275
+ * string with two letters). See example 2 and 3 below.
276
+ *
277
+ * `charCodeAt` returns `NaN` if the given index is not greater than 0 or is greater than the length of
278
+ * the string.
279
+ *
280
+ * Backward Compatibility with JavaScript 1.2
281
+ *
282
+ * The `charCodeAt` method returns a number indicating the ISO-Latin-1 codeset value of the character
283
+ * at the given index. The ISO-Latin-1 codeset ranges from 0 to 255. The first 0 to 127 are a direct
284
+ * match of the ASCII character set.
285
+ *
286
+ * Example 1: Using `charCodeAt`
287
+ *
288
+ * The following example returns 65, the Unicode value for A.
289
+ *
290
+ * "ABC".charCodeAt(0) // returns 65
291
+ *
292
+ * Example 2: Fixing `charCodeAt` to handle non-Basic-Multilingual-Plane characters if their presence
293
+ * earlier in the string is unknown
294
+ *
295
+ * This version might be used in for loops and the like when it is unknown whether non-BMP characters
296
+ * exist before the specified index position.
297
+ *
298
+ * function fixedCharCodeAt (str, idx) {
299
+ * // ex. fixedCharCodeAt ('\uD800\uDC00', 0); // 65536
300
+ * // ex. fixedCharCodeAt ('\uD800\uDC00', 1); // 65536
301
+ * idx = idx || 0;
302
+ * var code = str.charCodeAt(idx);
303
+ * var hi, low;
304
+ * if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
305
+ * hi = code;
306
+ * low = str.charCodeAt(idx+1);
307
+ * if (isNaN(low)) {
308
+ * throw 'High surrogate not followed by low surrogate in fixedCharCodeAt()';
309
+ * }
310
+ * return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
311
+ * }
312
+ * if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
313
+ * // We return false to allow loops to skip this iteration since should have already handled
314
+ * high surrogate above in the previous iteration
315
+ * return false;
316
+ * }
317
+ * return code;
318
+ * }
319
+ *
320
+ * Example 3: Fixing `charCodeAt` to handle non-Basic-Multilingual-Plane characters if their presence
321
+ * earlier in the string is known
322
+ *
323
+ * function knownCharCodeAt (str, idx) {
324
+ * str += '';
325
+ * var code,
326
+ * end = str.length;
327
+ *
328
+ * var surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
329
+ * while ((surrogatePairs.exec(str)) != null) {
330
+ * var li = surrogatePairs.lastIndex;
331
+ * if (li - 2 < idx) {
332
+ * idx++;
333
+ * }
334
+ * else {
335
+ * break;
336
+ * }
337
+ * }
338
+ *
339
+ * if (idx >= end || idx < 0) {
340
+ * return NaN;
341
+ * }
342
+ *
343
+ * code = str.charCodeAt(idx);
344
+ *
345
+ * var hi, low;
346
+ * if (0xD800 <= code && code <= 0xDBFF) {
347
+ * hi = code;
348
+ * low = str.charCodeAt(idx+1); // Go one further, since one of the "characters" is part of
349
+ * a surrogate pair
350
+ * return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
351
+ * }
352
+ * return code;
353
+ * }
354
+ *
355
+ * @param {Number} index An integer greater than 0 and less than the length of the string; if it is
356
+ * not a number, it defaults to 0.
357
+ * @return {Number} Value between 0 and 65535.
358
+ */
359
+
360
+ /**
361
+ * @method concat
362
+ * Combines the text of two strings and returns a new string.
363
+ *
364
+ * `concat` combines the text from one or more strings and returns a new string. Changes to the text in
365
+ * one string do not affect the other string.
366
+ *
367
+ * The following example combines strings into a new string.
368
+ *
369
+ * var hello = "Hello, ";
370
+ * console.log(hello.concat("Kevin", " have a nice day.")); // Hello, Kevin have a nice day.
371
+ *
372
+ * @param {String} string2...stringN
373
+ * @return {String} Result of both strings.
374
+ */
375
+
376
+ /**
377
+ * @method indexOf
378
+ * Returns the index within the calling `String` object of the first occurrence of the specified value,
379
+ * or -1 if not found.
380
+ *
381
+ * Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character
382
+ * of a string called `stringName` is `stringName.length - 1`.
383
+ *
384
+ * "Blue Whale".indexOf("Blue") // returns 0
385
+ * "Blue Whale".indexOf("Blute") // returns -1
386
+ * "Blue Whale".indexOf("Whale",0) // returns 5
387
+ * "Blue Whale".indexOf("Whale",5) // returns 5
388
+ * "Blue Whale".indexOf("",9) // returns 9
389
+ * "Blue Whale".indexOf("",10) // returns 10
390
+ * "Blue Whale".indexOf("",11) // returns 10
391
+ *
392
+ * The `indexOf` method is case sensitive. For example, the following expression returns -1:
393
+ *
394
+ * "Blue Whale".indexOf("blue")
395
+ *
396
+ * Note that '0' doesn't evaluate to true and '-1' doesn't evaluate to false. Therefore, when checking if a specific string exists
397
+ * within another string the correct way to check would be:
398
+ *
399
+ * "Blue Whale".indexOf("Blue") != -1 // true
400
+ * "Blue Whale".indexOf("Bloe") != -1 // false
401
+ *
402
+ * The following example uses indexOf and lastIndexOf to locate values in the string "Brave new world".
403
+ *
404
+ * var anyString="Brave new world"
405
+ *
406
+ * document.write("<P>The index of the first w from the beginning is " + anyString.indexOf("w")) // Displays 8
407
+ * document.write("<P>The index of the first w from the end is " + anyString.lastIndexOf("w")) // Displays 10
408
+ * document.write("<P>The index of 'new' from the beginning is " + anyString.indexOf("new")) // Displays 6
409
+ * document.write("<P>The index of 'new' from the end is " + anyString.lastIndexOf("new")) // Displays 6
410
+ *
411
+ * The following example defines two string variables. The variables contain the same string except that the second string contains
412
+ * uppercase letters. The first `writeln` method displays 19. But because the `indexOf` method is case sensitive, the string
413
+ * "cheddar" is not found in `myCapString`, so the second `writeln` method displays -1.
414
+ *
415
+ * myString="brie, pepper jack, cheddar"
416
+ * myCapString="Brie, Pepper Jack, Cheddar"
417
+ * document.writeln('myString.indexOf("cheddar") is ' + myString.indexOf("cheddar"))
418
+ * document.writeln('<P>myCapString.indexOf("cheddar") is ' + myCapString.indexOf("cheddar"))
419
+ *
420
+ * The following example sets count to the number of occurrences of the letter x in the string str:
421
+ *
422
+ * count = 0;
423
+ * pos = str.indexOf("x");
424
+ * while ( pos != -1 ) {
425
+ * count++;
426
+ * pos = str.indexOf("x",pos+1);
427
+ * }
428
+ *
429
+ * @param {String} searchValue A string representing the value to search for.
430
+ * @param {Number} fromIndex The location within the calling string to start the search from. It can be any integer between 0 and
431
+ * the length of the string. The default value is 0.
432
+ * @return {Number} Position of specified value or -1 if not found.
433
+ */
434
+
435
+ /**
436
+ * @method lastIndexOf
437
+ * Returns the index within the calling String object of the last occurrence of
438
+ * the specified value, or -1 if not found. The calling string is searched
439
+ * backward, starting at fromIndex.
440
+ *
441
+ * Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character
442
+ * is `stringName.length - 1`.
443
+ *
444
+ * "canal".lastIndexOf("a") // returns 3
445
+ * "canal".lastIndexOf("a",2) // returns 1
446
+ * "canal".lastIndexOf("a",0) // returns -1
447
+ * "canal".lastIndexOf("x") // returns -1
448
+ *
449
+ * The `lastIndexOf` method is case sensitive. For example, the following expression returns -1:
450
+ *
451
+ * "Blue Whale, Killer Whale".lastIndexOf("blue")
452
+ *
453
+ * The following example uses `indexOf` and `lastIndexOf` to locate values in the string "`Brave new world`".
454
+ *
455
+ * var anyString="Brave new world"
456
+ *
457
+ * // Displays 8
458
+ * document.write("<P>The index of the first w from the beginning is " +
459
+ * anyString.indexOf("w"))
460
+ * // Displays 10
461
+ * document.write("<P>The index of the first w from the end is " +
462
+ * anyString.lastIndexOf("w"))
463
+ * // Displays 6
464
+ * document.write("<P>The index of 'new' from the beginning is " +
465
+ * anyString.indexOf("new"))
466
+ * // Displays 6
467
+ * document.write("<P>The index of 'new' from the end is " +
468
+ * anyString.lastIndexOf("new"))
469
+ *
470
+ * @param {String} searchValue A string representing the value to search for.
471
+ * @param {Number} fromIndex The location within the calling string to start the search from, indexed from left to right. It can
472
+ * be any integer between 0 and the length of the string. The default value is the length of the string.
473
+ * @return {Number}
474
+ */
475
+
476
+ /**
477
+ * @method localeCompare
478
+ * Returns a number indicating whether a reference string comes before or after or is the same as the
479
+ * given string in sort order.
480
+ *
481
+ * Returns a number indicating whether a reference string comes before or after or is the same as the
482
+ * given string in sort order. Returns -1 if the string occurs earlier in a sort than `compareString`,
483
+ * returns 1 if the string occurs afterwards in such a sort, and returns 0 if they occur at the same
484
+ * level.
485
+ *
486
+ * The following example demonstrates the different potential results for a string occurring before,
487
+ * after, or at the same level as another:
488
+ *
489
+ * alert('a'.localeCompare('b')); // -1
490
+ * alert('b'.localeCompare('a')); // 1
491
+ * alert('b'.localeCompare('b')); // 0
492
+ *
493
+ * @param {String} compareString The string against which the referring string is comparing.
494
+ * @return {Number} Returns -1 if the string occurs earlier in a sort than
495
+ * compareString, returns 1 if the string occurs afterwards in such a sort, and
496
+ * returns 0 if they occur at the same level.
497
+ */
498
+
499
+ /**
500
+ * @method match
501
+ * Used to match a regular expression against a string.
502
+ *
503
+ * If the regular expression does not include the `g` flag, returns the same result as `regexp.exec(string)`.
504
+ *
505
+ * If the regular expression includes the `g` flag, the method returns an Array containing all matches. If there were no matches,
506
+ * the method returns `null`.
507
+ *
508
+ * The returned {@link Array} has an extra `input` property, which contains the regexp that generated it as a result. In addition,
509
+ * it has an `index` property, which represents the zero-based index of the match in the string.
510
+ *
511
+ * In the following example, `match` is used to find "Chapter" followed by 1 or more numeric characters followed by a decimal point
512
+ * and numeric character 0 or more times. The regular expression includes the `i` flag so that case will be ignored.
513
+ *
514
+ * str = "For more information, see Chapter 3.4.5.1";
515
+ * re = /(chapter \d+(\.\d)*)/i;
516
+ * found = str.match(re);
517
+ * document.write(found);
518
+ *
519
+ * This returns the array containing Chapter 3.4.5.1,Chapter 3.4.5.1,.1
520
+ *
521
+ * "`Chapter 3.4.5.1`" is the first match and the first value remembered from `(Chapter \d+(\.\d)*)`.
522
+ *
523
+ * "`.1`" is the second value remembered from `(\.\d)`.
524
+ *
525
+ * The following example demonstrates the use of the global and ignore case flags with `match`. All letters A through E and a
526
+ * through e are returned, each its own element in the array
527
+ *
528
+ * var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
529
+ * var regexp = /[A-E]/gi;
530
+ * var matches_array = str.match(regexp);
531
+ * document.write(matches_array);
532
+ *
533
+ * `matches_array` now equals `['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']`.
534
+ *
535
+ * @param {RegExp} regexp A {@link RegExp} object. If a non-RegExp object `obj` is passed, it is
536
+ * implicitly converted to a RegExp by using `new RegExp(obj)`.
537
+ * @return {Array} Contains results of the match (if any).
538
+ */
539
+
540
+ /**
541
+ * @method replace
542
+ * Used to find a match between a regular expression and a string, and to replace the matched substring
543
+ * with a new substring.
544
+ *
545
+ * This method does not change the `String` object it is called on. It simply returns a new string.
546
+ *
547
+ * To perform a global search and replace, either include the `g` flag in the regular expression or if
548
+ * the first parameter is a string, include `g` in the flags parameter.
549
+ *
550
+ * The replacement string can include the following special replacement patterns:
551
+ *
552
+ * | Pattern | Inserts
553
+ * |:--------------|:--------------------------------------------------------------------------------------
554
+ * | `$$` | Inserts a `$`.
555
+ * | `$&` | Inserts the matched substring.
556
+ * | `$`` | Inserts the portion of the string that precedes the matched substring.
557
+ * | `$'` | Inserts the portion of the string that follows the matched substring.
558
+ * | `$n` or `$nn` | Where `n` or `nn` are decimal digits, inserts the _n_th parenthesized submatch string, provided the first
559
+ * | | argument was a `RegExp` object.
560
+ *
561
+ * You can specify a function as the second parameter. In this case, the function will be invoked after the match has been
562
+ * performed. The function's result (return value) will be used as the replacement string. (Note: the above-mentioned special
563
+ * replacement patterns do not apply in this case.) Note that the function will be invoked multiple times for each full match to be
564
+ * replaced if the regular expression in the first parameter is global.
565
+ *
566
+ * The arguments to the function are as follows:
567
+ *
568
+ * | Possible Name | Supplied Value
569
+ * |:--------------|:--------------------------------------------------------------------------------------
570
+ * | `str` | The matched substring. (Corresponds to `$&` above.)
571
+ * | `p1, p2, ...` | The _n_th parenthesized submatch string, provided the first argument to replace was a `RegExp` object.
572
+ * | | (Correspond to $1, $2, etc. above.)
573
+ * | `offset` | The offset of the matched substring within the total string being examined. (For example, if the total string
574
+ * | | was "`abcd`", and the matched substring was "`bc`", then this argument will be 1.)
575
+ * | `s` | The total string being examined.
576
+ *
577
+ * (The exact number of arguments will depend on whether the first argument was a `RegExp` object and, if so, how many parenthesized
578
+ * submatches it specifies.)
579
+ *
580
+ * The following example will set `newString` to "`XXzzzz - XX , zzzz`":
581
+ *
582
+ * function replacer(str, p1, p2, offset, s)
583
+ * {
584
+ * return str + " - " + p1 + " , " + p2;
585
+ * }
586
+ * var newString = "XXzzzz".replace(/(X*)(z*)/, replacer);
587
+ *
588
+ * In the following example, the regular expression includes the global and ignore case flags which permits replace to replace each
589
+ * occurrence of 'apples' in the string with 'oranges'.
590
+ *
591
+ * var re = /apples/gi;
592
+ * var str = "Apples are round, and apples are juicy.";
593
+ * var newstr = str.replace(re, "oranges");
594
+ * print(newstr);
595
+ *
596
+ * In this version, a string is used as the first parameter and the global and ignore case flags are specified in the flags
597
+ * parameter.
598
+ *
599
+ * var str = "Apples are round, and apples are juicy.";
600
+ * var newstr = str.replace("apples", "oranges", "gi");
601
+ * print(newstr);
602
+ *
603
+ * Both of these examples print "oranges are round, and oranges are juicy."
604
+ *
605
+ * In the following example, the regular expression is defined in replace and includes the ignore case flag.
606
+ *
607
+ * var str = "Twas the night before Xmas...";
608
+ * var newstr = str.replace(/xmas/i, "Christmas");
609
+ * print(newstr);
610
+ *
611
+ * This prints "Twas the night before Christmas..."
612
+ *
613
+ * The following script switches the words in the string. For the replacement text, the script uses the $1 and $2 replacement
614
+ * patterns.
615
+ *
616
+ * var re = /(\w+)\s(\w+)/;
617
+ * var str = "John Smith";
618
+ * var newstr = str.replace(re, "$2, $1");
619
+ * print(newstr);
620
+ *
621
+ * This prints "Smith, John".
622
+ *
623
+ * In this example, all occurrences of capital letters in the string are converted to lower case, and a hyphen is inserted just
624
+ * before the match location. The important thing here is that additional operations are needed on the matched item before it is
625
+ * given back as a replacement.
626
+ *
627
+ * The replacement function accepts the matched snippet as its parameter, and uses it to transform the case and concatenate the
628
+ * hyphen before returning.
629
+ *
630
+ * function styleHyphenFormat(propertyName)
631
+ * {
632
+ * function upperToHyphenLower(match)
633
+ * {
634
+ * return '-' + match.toLowerCase();
635
+ * }
636
+ * return propertyName.replace(/[A-Z]/, upperToHyphenLower);
637
+ * }
638
+ *
639
+ * Given `styleHyphenFormat('borderTop')`, this returns 'border-top'.
640
+ *
641
+ * Because we want to further transform the _result_ of the match before the final substitution is made, we must use a function.
642
+ * This forces the evaluation of the match prior to the `toLowerCase()` method. If we had tried to do this using the match without a
643
+ * function, the `toLowerCase()` would have no effect.
644
+ *
645
+ * var newString = propertyName.replace(/[A-Z]/, '-' + '$&'.toLowerCase()); // won't work
646
+ *
647
+ * This is because `'$&'.toLowerCase()` would be evaluated first as a string literal (resulting in the same `'$&'`) before using the
648
+ * characters as a pattern.
649
+ *
650
+ * The following example replaces a Fahrenheit degree with its equivalent Celsius degree. The Fahrenheit degree should be a number
651
+ * ending with F. The function returns the Celsius number ending with C. For example, if the input number is 212F, the function
652
+ * returns 100C. If the number is 0F, the function returns -17.77777777777778C.
653
+ *
654
+ * The regular expression `test` checks for any number that ends with F. The number of Fahrenheit degree is accessible to the
655
+ * function through its second parameter, `p1`. The function sets the Celsius number based on the Fahrenheit degree passed in a
656
+ * string to the `f2c` function. `f2c` then returns the Celsius number. This function approximates Perl's `s///e` flag.
657
+ *
658
+ * function f2c(x)
659
+ * {
660
+ * function convert(str, p1, offset, s)
661
+ * {
662
+ * return ((p1-32) * 5/9) + "C";
663
+ * }
664
+ * var s = String(x);
665
+ * var test = /(\d+(?:\.\d*)?)F\b/g;
666
+ * return s.replace(test, convert);
667
+ * }
668
+ *
669
+ * @param {RegExp} regexp A RegExp object. The match is replaced by the return value of parameter #2.
670
+ * @param {String} substr A String that is to be replaced by `newSubStr`.
671
+ * @param {String} newSubStr The String that replaces the substring received from parameter #1. A
672
+ * number of special replacement patterns are supported; see the "Specifying a string as a parameter"
673
+ * section below.
674
+ * @param {Function} function A function to be invoked to create the new substring (to put in place
675
+ * of the substring received from parameter #1). The arguments supplied to this function are described
676
+ * in the "Specifying a function as a parameter" section below.
677
+ * @return {String} String of matched replaced items.
678
+ */
679
+
680
+ /**
681
+ * @method search
682
+ * Executes the search for a match between a regular expression and a specified string.
683
+ *
684
+ * If successful, search returns the index of the regular expression inside the string. Otherwise, it
685
+ * returns -1.
686
+ *
687
+ * When you want to know whether a pattern is found in a string use search (similar to the regular
688
+ * expression `test` method); for more information (but slower execution) use `match` (similar to the
689
+ * regular expression `exec` method).
690
+ *
691
+ * The following example prints a message which depends on the success of the test.
692
+ *
693
+ * function testinput(re, str){
694
+ * if (str.search(re) != -1)
695
+ * midstring = " contains ";
696
+ * else
697
+ * midstring = " does not contain ";
698
+ * document.write (str + midstring + re);
699
+ * }
700
+ *
701
+ * @param {RegExp} regexp A regular expression object. If a non-RegExp object obj is passed, it is
702
+ * implicitly converted to a RegExp by using `new RegExp(obj)`.
703
+ * @return {Number} If successful, search returns the index of the regular
704
+ * expression inside the string. Otherwise, it returns -1.
705
+ */
706
+
707
+ /**
708
+ * @method slice
709
+ * Extracts a section of a string and returns a new string.
710
+ *
711
+ * `slice` extracts the text from one string and returns a new string. Changes to the text in one
712
+ * string do not affect the other string.
713
+ *
714
+ * `slice` extracts up to but not including `endSlice`. `string.slice(1,4)` extracts the second
715
+ * character through the fourth character (characters indexed 1, 2, and 3).
716
+ *
717
+ * As a negative index, `endSlice` indicates an offset from the end of the string. `string.slice(2,-1)`
718
+ * extracts the third character through the second to last character in the string.
719
+ *
720
+ * The following example uses slice to create a new string.
721
+ *
722
+ * // assumes a print function is defined
723
+ * var str1 = "The morning is upon us.";
724
+ * var str2 = str1.slice(4, -2);
725
+ * print(str2);
726
+ *
727
+ * This writes:
728
+ *
729
+ * morning is upon u
730
+ *
731
+ * @param {Number} beginSlice The zero-based index at which to begin extraction.
732
+ * @param {Number} endSlice The zero-based index at which to end extraction. If omitted, `slice`
733
+ * extracts to the end of the string.
734
+ * @return {String} All characters from specified start up to (but excluding)
735
+ * end.
736
+ */
737
+
738
+ /**
739
+ * @method split
740
+ * Splits a `String` object into an array of strings by separating the string into substrings.
741
+ *
742
+ * The `split` method returns the new array.
743
+ *
744
+ * When found, `separator` is removed from the string and the substrings are returned in an array. If
745
+ * `separator` is omitted, the array contains one element consisting of the entire string.
746
+ *
747
+ * If `separator` is a regular expression that contains capturing parentheses, then each time separator
748
+ * is matched the results (including any undefined results) of the capturing parentheses are spliced
749
+ * into the output array. However, not all browsers support this capability.
750
+ *
751
+ * Note: When the string is empty, `split` returns an array containing one empty string, rather than an
752
+ * empty array.
753
+ *
754
+ * The following example defines a function that splits a string into an array of strings using the
755
+ * specified separator. After splitting the string, the function displays messages indicating the
756
+ * original string (before the split), the separator used, the number of elements in the array, and the
757
+ * individual array elements.
758
+ *
759
+ * function splitString(stringToSplit,separator)
760
+ * {
761
+ * var arrayOfStrings = stringToSplit.split(separator);
762
+ * print('The original string is: "' + stringToSplit + '"');
763
+ * print('The separator is: "' + separator + '"');
764
+ * print("The array has " + arrayOfStrings.length + " elements: ");
765
+ *
766
+ * for (var i=0; i < arrayOfStrings.length; i++)
767
+ * print(arrayOfStrings[i] + " / ");
768
+ * }
769
+ *
770
+ * var tempestString = "Oh brave new world that has such people in it.";
771
+ * var monthString = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
772
+ *
773
+ * var space = " ";
774
+ * var comma = ",";
775
+ *
776
+ * splitString(tempestString, space);
777
+ * splitString(tempestString);
778
+ * splitString(monthString, comma);
779
+ *
780
+ * This example produces the following output:
781
+ *
782
+ * The original string is: "Oh brave new world that has such people in it."
783
+ * The separator is: " "
784
+ * The array has 10 elements: Oh / brave / new / world / that / has / such / people / in / it. /
785
+ *
786
+ * The original string is: "Oh brave new world that has such people in it."
787
+ * The separator is: "undefined"
788
+ * The array has 1 elements: Oh brave new world that has such people in it. /
789
+ *
790
+ * The original string is: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
791
+ * The separator is: ","
792
+ * The array has 12 elements: Jan / Feb / Mar / Apr / May / Jun / Jul / Aug / Sep / Oct / Nov / Dec /
793
+ *
794
+ * In the following example, `split` looks for 0 or more spaces followed by a semicolon followed by 0
795
+ * or more spaces and, when found, removes the spaces from the string. nameList is the array returned
796
+ * as a result of split.
797
+ *
798
+ * var names = "Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand ";
799
+ * print(names);
800
+ * var re = /\s*;\s*\/;
801
+ * var nameList = names.split(re);
802
+ * print(nameList);
803
+ *
804
+ * This prints two lines; the first line prints the original string, and the second line prints the
805
+ * resulting array.
806
+ *
807
+ * Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand
808
+ * Harry Trump,Fred Barney,Helen Rigby,Bill Abel,Chris Hand
809
+ *
810
+ * In the following example, split looks for 0 or more spaces in a string and returns the first 3
811
+ * splits that it finds.
812
+ *
813
+ * var myString = "Hello World. How are you doing?";
814
+ * var splits = myString.split(" ", 3);
815
+ * print(splits);
816
+ *
817
+ * This script displays the following:
818
+ *
819
+ * Hello,World.,How
820
+ *
821
+ * If `separator` contains capturing parentheses, matched results are returned in the array.
822
+ *
823
+ * var myString = "Hello 1 word. Sentence number 2.";
824
+ * var splits = myString.split(/(\d)/);
825
+ * print(splits);
826
+ *
827
+ * This script displays the following:
828
+ *
829
+ * Hello ,1, word. Sentence number ,2, .
830
+ *
831
+ * @param {String} seperator Specifies the character to use for separating the string. The separator is treated as a string or a
832
+ * regular expression. If separator is omitted, the array returned contains one element consisting of the entire string.
833
+ * @param {Number} limit Integer specifying a limit on the number of splits to be found. The split method still splits on every
834
+ * match of separator, but it truncates the returned array to at most limit elements.
835
+ * @return {Array} Substrings are returned in an array.
836
+ */
837
+
838
+ /**
839
+ * @method substr
840
+ * Returns the characters in a string beginning at the specified location through the specified number
841
+ * of characters.
842
+ *
843
+ * `start` is a character index. The index of the first character is 0, and the index of the last
844
+ * character is 1 less than the length of the string. `substr` begins extracting characters at start
845
+ * and collects length characters (unless it reaches the end of the string first, in which case it will
846
+ * return fewer).
847
+ *
848
+ * If `start` is positive and is greater than or equal to the length of the string, `substr` returns an
849
+ * empty string.
850
+ *
851
+ * If `start` is negative, `substr` uses it as a character index from the end of the string. If start
852
+ * is negative and abs(start) is larger than the length of the string, `substr` uses 0 as the start
853
+ * index. Note: the described handling of negative values of the start argument is not supported by
854
+ * Microsoft JScript.
855
+ *
856
+ * If length is 0 or negative, `substr` returns an empty string. If length is omitted, `substr`
857
+ * extracts characters to the end of the string.
858
+ *
859
+ * Consider the following script:
860
+ *
861
+ * // assumes a print function is defined
862
+ * var str = "abcdefghij";
863
+ * print("(1,2): " + str.substr(1,2));
864
+ * print("(-3,2): " + str.substr(-3,2));
865
+ * print("(-3): " + str.substr(-3));
866
+ * print("(1): " + str.substr(1));
867
+ * print("(-20, 2): " + str.substr(-20,2));
868
+ * print("(20, 2): " + str.substr(20,2));
869
+ *
870
+ * This script displays:
871
+ *
872
+ * (1,2): bc
873
+ * (-3,2): hi
874
+ * (-3): hij
875
+ * (1): bcdefghij
876
+ * (-20, 2): ab
877
+ * (20, 2):
878
+ *
879
+ * @param {Number} start Location at which to begin extracting characters.
880
+ * @param {Number} length The number of characters to extract.
881
+ * @return {String} Modified string.
882
+ */
883
+
884
+ /**
885
+ * @method substring
886
+ * Returns the characters in a string between two indexes into the string.
887
+ *
888
+ * substring extracts characters from indexA up to but not including indexB. In particular:
889
+ * * If `indexA` equals `indexB`, `substring` returns an empty string.
890
+ * * If `indexB` is omitted, substring extracts characters to the end of the string.
891
+ * * If either argument is less than 0 or is `NaN`, it is treated as if it were 0.
892
+ * * If either argument is greater than `stringName.length`, it is treated as if it were
893
+ * `stringName.length`.
894
+ *
895
+ * If `indexA` is larger than `indexB`, then the effect of substring is as if the two arguments were
896
+ * swapped; for example, `str.substring(1, 0) == str.substring(0, 1)`.
897
+ *
898
+ * The following example uses substring to display characters from the string "Sencha":
899
+ *
900
+ * // assumes a print function is defined
901
+ * var anyString = "Sencha";
902
+ *
903
+ * // Displays "Sen"
904
+ * print(anyString.substring(0,3));
905
+ * print(anyString.substring(3,0));
906
+ *
907
+ * // Displays "cha"
908
+ * print(anyString.substring(3,6));
909
+ * print(anyString.substring(6,3));
910
+ *
911
+ * // Displays "Sencha"
912
+ * print(anyString.substring(0,6));
913
+ * print(anyString.substring(0,10));
914
+ *
915
+ * The following example replaces a substring within a string. It will replace both individual
916
+ * characters and `substrings`. The function call at the end of the example changes the string "Brave
917
+ * New World" into "Brave New Web".
918
+ *
919
+ * function replaceString(oldS, newS, fullS) {
920
+ * // Replaces oldS with newS in the string fullS
921
+ * for (var i = 0; i < fullS.length; i++) {
922
+ * if (fullS.substring(i, i + oldS.length) == oldS) {
923
+ * fullS = fullS.substring(0, i) + newS + fullS.substring(i + oldS.length,
924
+ * fullS.length);
925
+ * }
926
+ * }
927
+ * return fullS;
928
+ * }
929
+ *
930
+ * replaceString("World", "Web", "Brave New World");
931
+ *
932
+ * @param {Number} indexA An integer between 0 and one less than the length of the string.
933
+ * @param {Number} indexB (optional) An integer between 0 and the length of the string.
934
+ * @return {String} Returns the characters in a string between two indexes into the string.
935
+ */
936
+
937
+ /**
938
+ * @method toLocaleLowerCase
939
+ * The characters within a string are converted to lower case while respecting the current locale. For
940
+ * most languages, this will return the same as `toLowerCase`.
941
+ *
942
+ * The `toLocaleLowerCase` method returns the value of the string converted to lower case according to
943
+ * any locale-specific case mappings. `toLocaleLowerCase` does not affect the value of the string
944
+ * itself. In most cases, this will produce the same result as `toLowerCase()`, but for some locales,
945
+ * such as Turkish, whose case mappings do not follow the default case mappings in Unicode, there may
946
+ * be a different result.
947
+ *
948
+ * The following example displays the string "sencha":
949
+ *
950
+ * var upperText="sencha";
951
+ * document.write(upperText.toLocaleLowerCase());
952
+ *
953
+ * @return {String} Returns value of the string in lowercase.
954
+ */
955
+
956
+ /**
957
+ * @method toLocaleUpperCase
958
+ * The characters within a string are converted to upper case while respecting the current locale. For
959
+ * most languages, this will return the same as `toUpperCase`.
960
+ *
961
+ * The `toLocaleUpperCase` method returns the value of the string converted to upper case according to
962
+ * any locale-specific case mappings. `toLocaleUpperCase` does not affect the value of the string
963
+ * itself. In most cases, this will produce the same result as `toUpperCase()`, but for some locales,
964
+ * such as Turkish, whose case mappings do not follow the default case mappings in Unicode, there may
965
+ * be a different result.
966
+ *
967
+ * The following example displays the string "SENCHA":
968
+ *
969
+ * var lowerText="sencha";
970
+ * document.write(lowerText.toLocaleUpperCase());
971
+ *
972
+ * @return {String} Returns value of the string in uppercase.
973
+ */
974
+
975
+ /**
976
+ * @method toLowerCase
977
+ * Returns the calling string value converted to lower case.
978
+ *
979
+ * The `toLowerCase` method returns the value of the string converted to lowercase. `toLowerCase` does
980
+ * not affect the value of the string itself.
981
+ *
982
+ * The following example displays the lowercase string "sencha":
983
+ *
984
+ * var upperText="SENCHA";
985
+ * document.write(upperText.toLowerCase());
986
+ *
987
+ * @return {String} Returns value of the string in lowercase.
988
+ */
989
+
990
+ /**
991
+ * @method toString
992
+ * Returns a string representing the specified object. Overrides the `Object.toString` method.
993
+ *
994
+ * The `String` object overrides the `toString` method of the `Object` object; it does not inherit
995
+ * `Object.toString`. For `String` objects, the `toString` method returns a string representation of
996
+ * the object.
997
+ *
998
+ * The following example displays the string value of a String object:
999
+ *
1000
+ * x = new String("Hello world");
1001
+ * alert(x.toString()) // Displays "Hello world"
1002
+ *
1003
+ * @return {String} A string representation of the object.
1004
+ */
1005
+
1006
+ /**
1007
+ * @method toUpperCase
1008
+ * Returns the calling string value converted to uppercase.
1009
+ *
1010
+ * The `toUpperCase` method returns the value of the string converted to uppercase. `toUpperCase` does
1011
+ * not affect the value of the string itself.
1012
+ *
1013
+ * The following example displays the string "SENCHA":
1014
+
1015
+ * var lowerText="sencha";
1016
+ * document.write(lowerText.toUpperCase());
1017
+ *
1018
+ * @return {String} Returns value of the string in uppercase.
1019
+ */
1020
+
1021
+ /**
1022
+ * @method valueOf
1023
+ * Returns the primitive value of the specified object. Overrides the `Object.valueOf` method.
1024
+ *
1025
+ * The `valueOf` method of String returns the primitive value of a `String` object as a string data
1026
+ * type. This value is equivalent to `String.toString`.
1027
+ *
1028
+ * This method is usually called internally by JavaScript and not explicitly in code.
1029
+ *
1030
+ * x = new String("Hello world");
1031
+ * alert(x.valueOf()) // Displays "Hello world"
1032
+ *
1033
+ * @return {String} Returns value of string.
1034
+ */