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.
- data/README.md +21 -229
- data/Rakefile +31 -17
- data/bin/jsduck +1 -0
- data/js-classes/Array.js +561 -0
- data/js-classes/Boolean.js +110 -0
- data/js-classes/Date.js +999 -0
- data/js-classes/Function.js +256 -0
- data/js-classes/Number.js +308 -0
- data/js-classes/Object.js +404 -0
- data/js-classes/RegExp.js +415 -0
- data/js-classes/String.js +1034 -0
- data/jsduck.gemspec +2 -2
- data/lib/jsduck/accessors.rb +71 -0
- data/lib/jsduck/aggregator.rb +14 -2
- data/lib/jsduck/app.rb +6 -5
- data/lib/jsduck/class_formatter.rb +12 -8
- data/lib/jsduck/css_parser.rb +2 -2
- data/lib/jsduck/doc_formatter.rb +2 -2
- data/lib/jsduck/doc_parser.rb +32 -25
- data/lib/jsduck/exporter.rb +1 -1
- data/lib/jsduck/guides.rb +11 -2
- data/lib/jsduck/js_parser.rb +30 -8
- data/lib/jsduck/merger.rb +31 -16
- data/lib/jsduck/options.rb +93 -15
- data/lib/jsduck/renderer.rb +40 -3
- data/lib/jsduck/search_data.rb +8 -5
- data/lib/jsduck/source_file.rb +5 -4
- data/lib/jsduck/type_parser.rb +7 -6
- metadata +17 -5
- data/example.js +0 -144
@@ -0,0 +1,404 @@
|
|
1
|
+
/**
|
2
|
+
* @class Object
|
3
|
+
*
|
4
|
+
* Creates an object wrapper.
|
5
|
+
*
|
6
|
+
* The Object constructor creates an object wrapper for the given value. If the value is null or
|
7
|
+
* undefined, it will create and return an empty object, otherwise, it will return an object of a type
|
8
|
+
* that corresponds to the given value.
|
9
|
+
*
|
10
|
+
* When called in a non-constructor context, Object behaves identically.
|
11
|
+
*
|
12
|
+
* # Using Object given undefined and null types
|
13
|
+
*
|
14
|
+
* The following examples store an empty Object object in o:
|
15
|
+
* var o = new Object();
|
16
|
+
*
|
17
|
+
* var o = new Object(undefined);
|
18
|
+
*
|
19
|
+
* var o = new Object(null);
|
20
|
+
*
|
21
|
+
* # Using Object to create Boolean objects
|
22
|
+
*
|
23
|
+
* The following examples store Boolean objects in o:
|
24
|
+
*
|
25
|
+
* // equivalent to o = new Boolean(true);
|
26
|
+
* var o = new Object(true);
|
27
|
+
*
|
28
|
+
* // equivalent to o = new Boolean(false);
|
29
|
+
* var o = new Object(Boolean());
|
30
|
+
*
|
31
|
+
* <div class="notice">
|
32
|
+
* Documentation for this class comes from <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object">MDN</a>
|
33
|
+
* and is available under <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons: Attribution-Sharealike license</a>.
|
34
|
+
* </div>
|
35
|
+
*/
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @method constructor
|
39
|
+
* Creates new Object.
|
40
|
+
* @param {Object} [value] The value to wrap.
|
41
|
+
*/
|
42
|
+
|
43
|
+
//Properties
|
44
|
+
|
45
|
+
/**
|
46
|
+
* @property prototype
|
47
|
+
* Allows the addition of properties to all objects of type Object.
|
48
|
+
*/
|
49
|
+
|
50
|
+
//Methods
|
51
|
+
|
52
|
+
/**
|
53
|
+
* @method hasOwnProperty
|
54
|
+
* Returns a boolean indicating whether an object contains the specified property as a direct property
|
55
|
+
* of that object and not inherited through the prototype chain.
|
56
|
+
*
|
57
|
+
* Every object descended from `Object` inherits the `hasOwnProperty` method. This method can be used
|
58
|
+
* to determine whether an object has the specified property as a direct property of that object;
|
59
|
+
* unlike the `in` operator, this method does not check down the object's prototype chain.
|
60
|
+
*
|
61
|
+
* The following example determines whether the o object contains a property named prop:
|
62
|
+
*
|
63
|
+
* o = new Object();
|
64
|
+
* o.prop = 'exists';
|
65
|
+
*
|
66
|
+
* function changeO() {
|
67
|
+
* o.newprop = o.prop;
|
68
|
+
* delete o.prop;
|
69
|
+
* }
|
70
|
+
*
|
71
|
+
* o.hasOwnProperty('prop'); //returns true
|
72
|
+
* changeO();
|
73
|
+
* o.hasOwnProperty('prop'); //returns false
|
74
|
+
*
|
75
|
+
* The following example differentiates between direct properties and properties inherited through the
|
76
|
+
* prototype chain:
|
77
|
+
*
|
78
|
+
* o = new Object();
|
79
|
+
* o.prop = 'exists';
|
80
|
+
* o.hasOwnProperty('prop'); // returns true
|
81
|
+
* o.hasOwnProperty('toString'); // returns false
|
82
|
+
* o.hasOwnProperty('hasOwnProperty'); // returns false
|
83
|
+
*
|
84
|
+
* The following example shows how to iterate over the properties of an object without executing on
|
85
|
+
* inherit properties.
|
86
|
+
*
|
87
|
+
* var buz = {
|
88
|
+
* fog: 'stack'
|
89
|
+
* };
|
90
|
+
*
|
91
|
+
* for (var name in buz) {
|
92
|
+
* if (buz.hasOwnProperty(name)) {
|
93
|
+
* alert("this is fog (" + name + ") for sure. Value: " + buz[name]);
|
94
|
+
* }
|
95
|
+
* else {
|
96
|
+
* alert(name); // toString or something else
|
97
|
+
* }
|
98
|
+
* }
|
99
|
+
*
|
100
|
+
* @param {String} prop The name of the property to test.
|
101
|
+
* @return {Boolean} Returns true if object contains specified property; else
|
102
|
+
* returns false.
|
103
|
+
*/
|
104
|
+
|
105
|
+
/**
|
106
|
+
* @method isPrototypeOf
|
107
|
+
* Returns a boolean indication whether the specified object is in the prototype chain of the object
|
108
|
+
* this method is called upon.
|
109
|
+
*
|
110
|
+
* `isPrototypeOf` allows you to check whether or not an object exists within another object's
|
111
|
+
* prototype chain.
|
112
|
+
*
|
113
|
+
* For example, consider the following prototype chain:
|
114
|
+
*
|
115
|
+
* function Fee() {
|
116
|
+
* // . . .
|
117
|
+
* }
|
118
|
+
*
|
119
|
+
* function Fi() {
|
120
|
+
* // . . .
|
121
|
+
* }
|
122
|
+
* Fi.prototype = new Fee();
|
123
|
+
*
|
124
|
+
* function Fo() {
|
125
|
+
* // . . .
|
126
|
+
* }
|
127
|
+
* Fo.prototype = new Fi();
|
128
|
+
*
|
129
|
+
* function Fum() {
|
130
|
+
* // . . .
|
131
|
+
* }
|
132
|
+
* Fum.prototype = new Fo();
|
133
|
+
*
|
134
|
+
* Later on down the road, if you instantiate `Fum` and need to check if `Fi`'s prototype exists
|
135
|
+
* within the `Fum` prototype chain, you could do this:
|
136
|
+
*
|
137
|
+
* var fum = new Fum();
|
138
|
+
* . . .
|
139
|
+
*
|
140
|
+
* if (Fi.prototype.isPrototypeOf(fum)) {
|
141
|
+
* // do something safe
|
142
|
+
* }
|
143
|
+
*
|
144
|
+
* This, along with the `instanceof` operator particularly comes in handy if you have code that can
|
145
|
+
* only function when dealing with objects descended from a specific prototype chain, e.g., to
|
146
|
+
* guarantee that certain methods or properties will be present on that object.
|
147
|
+
*
|
148
|
+
* @param {Object} prototype an object to be tested against each link in the prototype chain of the
|
149
|
+
* *object* argument
|
150
|
+
* @param {Object} object the object whose prototype chain will be searched
|
151
|
+
* @return {Boolean} Returns true if object is a prototype and false if not.
|
152
|
+
*/
|
153
|
+
|
154
|
+
/**
|
155
|
+
* @method propertyIsEnumerable
|
156
|
+
* Returns a boolean indicating if the internal ECMAScript DontEnum attribute is set.
|
157
|
+
*
|
158
|
+
* Every object has a `propertyIsEnumerable` method. This method can determine whether the specified
|
159
|
+
* property in an object can be enumerated by a `for...in` loop, with the exception of properties
|
160
|
+
* inherited through the prototype chain. If the object does not have the specified property, this
|
161
|
+
* method returns false.
|
162
|
+
*
|
163
|
+
* The following example shows the use of `propertyIsEnumerable` on objects and arrays:
|
164
|
+
*
|
165
|
+
* var o = {};
|
166
|
+
* var a = [];
|
167
|
+
* o.prop = 'is enumerable';
|
168
|
+
* a[0] = 'is enumerable';
|
169
|
+
*
|
170
|
+
* o.propertyIsEnumerable('prop'); // returns true
|
171
|
+
* a.propertyIsEnumerable(0); // returns true
|
172
|
+
*
|
173
|
+
* The following example demonstrates the enumerability of user-defined versus built-in properties:
|
174
|
+
*
|
175
|
+
* var a = ['is enumerable'];
|
176
|
+
*
|
177
|
+
* a.propertyIsEnumerable(0); // returns true
|
178
|
+
* a.propertyIsEnumerable('length'); // returns false
|
179
|
+
*
|
180
|
+
* Math.propertyIsEnumerable('random'); // returns false
|
181
|
+
* this.propertyIsEnumerable('Math'); // returns false
|
182
|
+
*
|
183
|
+
* Direct versus inherited properties
|
184
|
+
*
|
185
|
+
* var a = [];
|
186
|
+
* a.propertyIsEnumerable('constructor'); // returns false
|
187
|
+
*
|
188
|
+
* function firstConstructor()
|
189
|
+
* {
|
190
|
+
* this.property = 'is not enumerable';
|
191
|
+
* }
|
192
|
+
* firstConstructor.prototype.firstMethod = function () {};
|
193
|
+
*
|
194
|
+
* function secondConstructor()
|
195
|
+
* {
|
196
|
+
* this.method = function method() { return 'is enumerable'; };
|
197
|
+
* }
|
198
|
+
*
|
199
|
+
* secondConstructor.prototype = new firstConstructor;
|
200
|
+
* secondConstructor.prototype.constructor = secondConstructor;
|
201
|
+
*
|
202
|
+
* var o = new secondConstructor();
|
203
|
+
* o.arbitraryProperty = 'is enumerable';
|
204
|
+
*
|
205
|
+
* o.propertyIsEnumerable('arbitraryProperty'); // returns true
|
206
|
+
* o.propertyIsEnumerable('method'); // returns true
|
207
|
+
* o.propertyIsEnumerable('property'); // returns false
|
208
|
+
*
|
209
|
+
* o.property = 'is enumerable';
|
210
|
+
*
|
211
|
+
* o.propertyIsEnumerable('property'); // returns true
|
212
|
+
*
|
213
|
+
* // These return false as they are on the prototype which
|
214
|
+
* // propertyIsEnumerable does not consider (even though the last two
|
215
|
+
* // are iteratable with for-in)
|
216
|
+
* o.propertyIsEnumerable('prototype'); // returns false (as of JS 1.8.1/FF3.6)
|
217
|
+
* o.propertyIsEnumerable('constructor'); // returns false
|
218
|
+
* o.propertyIsEnumerable('firstMethod'); // returns false
|
219
|
+
*
|
220
|
+
* @param {String} prop The name of the property to test.
|
221
|
+
* @return {Boolean} If the object does not have the specified property, this
|
222
|
+
* method returns false.
|
223
|
+
*/
|
224
|
+
|
225
|
+
/**
|
226
|
+
* @method toLocaleString
|
227
|
+
* Returns a string representing the object. This method is meant to be overridden by derived objects
|
228
|
+
* for locale-specific purposes.
|
229
|
+
*
|
230
|
+
* `Object`'s `toLocaleString` returns the result of calling `toString`.
|
231
|
+
*
|
232
|
+
* This function is provided to give objects a generic `toLocaleString` method, even though not all
|
233
|
+
* may use it. Currently, only `Array`, `Number`, and `Date` override `toLocaleString`.
|
234
|
+
*
|
235
|
+
* @return {String} Object represented as a string.
|
236
|
+
*/
|
237
|
+
|
238
|
+
/**
|
239
|
+
* @method toString
|
240
|
+
* Returns a string representation of the object.
|
241
|
+
*
|
242
|
+
* Every object has a `toString()` method that is automatically called when the object is to be
|
243
|
+
* represented as a text value or when an object is referred to in a manner in which a string is
|
244
|
+
* expected. By default, the `toString()` method is inherited by every object descended from `Object`.
|
245
|
+
* If this method is not overridden in a custom object, `toString()` returns "[object type]", where
|
246
|
+
* `type` is the object type. The following code illustrates this:
|
247
|
+
*
|
248
|
+
* var o = new Object();
|
249
|
+
* o.toString(); // returns [object Object]
|
250
|
+
*
|
251
|
+
* You can create a function to be called in place of the default `toString()` method. The
|
252
|
+
* `toString()` method takes no arguments and should return a string. The `toString()` method you
|
253
|
+
* create can be any value you want, but it will be most useful if it carries information about the
|
254
|
+
* object.
|
255
|
+
*
|
256
|
+
* The following code defines the `Dog` object type and creates `theDog`, an object of type `Dog`:
|
257
|
+
*
|
258
|
+
* function Dog(name,breed,color,sex) {
|
259
|
+
* this.name=name;
|
260
|
+
* this.breed=breed;
|
261
|
+
* this.color=color;
|
262
|
+
* this.sex=sex;
|
263
|
+
* }
|
264
|
+
*
|
265
|
+
* theDog = new Dog("Gabby","Lab","chocolate","female");
|
266
|
+
*
|
267
|
+
* If you call the `toString()` method on this custom object, it returns the default value inherited
|
268
|
+
* from `Object`:
|
269
|
+
*
|
270
|
+
* theDog.toString(); //returns [object Object]
|
271
|
+
*
|
272
|
+
* The following code creates and assigns `dogToString()` to override the default `toString()` method.
|
273
|
+
* This function generates a string containing the name, breed, color, and sex of the object, in the
|
274
|
+
* form `"property = value;"`.
|
275
|
+
*
|
276
|
+
* Dog.prototype.toString = function dogToString() {
|
277
|
+
* var ret = "Dog " + this.name + " is a " + this.sex + " " + this.color + " " + this.breed;
|
278
|
+
* return ret;
|
279
|
+
* }
|
280
|
+
*
|
281
|
+
* With the preceding code in place, any time theDog is used in a string context, JavaScript
|
282
|
+
* automatically calls the `dogToString()` function, which returns the following string:
|
283
|
+
*
|
284
|
+
* Dog Gabby is a female chocolate Lab
|
285
|
+
*
|
286
|
+
* `toString()` can be used with every object and allows you to get its class. To use the
|
287
|
+
* `Object.prototype.toString()` with every object, you need to call `Function.prototype.call()` or
|
288
|
+
* `Function.prototype.apply()` on it, passing the object you want to inspect as the first parameter
|
289
|
+
* called `thisArg`.
|
290
|
+
*
|
291
|
+
* var toString = Object.prototype.toString;
|
292
|
+
*
|
293
|
+
* toString.call(new Date); // [object Date]
|
294
|
+
* toString.call(new String); // [object String]
|
295
|
+
* toString.call(Math); // [object Math]
|
296
|
+
*
|
297
|
+
* @return {String} Object represented as a string.
|
298
|
+
*/
|
299
|
+
|
300
|
+
/**
|
301
|
+
* @method valueOf
|
302
|
+
* Returns the primitive value of the specified object.
|
303
|
+
*
|
304
|
+
* JavaScript calls the `valueOf` method to convert an object to a primitive value. You rarely need to
|
305
|
+
* invoke the `valueOf` method yourself; JavaScript automatically invokes it when encountering an
|
306
|
+
* object where a primitive value is expected.
|
307
|
+
*
|
308
|
+
* By default, the `valueOf` method is inherited by every object descended from `Object`. Every built-
|
309
|
+
* in core object overrides this method to return an appropriate value. If an object has no primitive
|
310
|
+
* value, `valueOf` returns the object itself, which is displayed as:
|
311
|
+
*
|
312
|
+
* [object Object]
|
313
|
+
*
|
314
|
+
* You can use `valueOf` within your own code to convert a built-in object into a primitive value.
|
315
|
+
* When you create a custom object, you can override `Object.valueOf` to call a custom method instead
|
316
|
+
* of the default `Object` method.
|
317
|
+
*
|
318
|
+
* You can create a function to be called in place of the default `valueOf` method. Your function must
|
319
|
+
* take no arguments.
|
320
|
+
*
|
321
|
+
* Suppose you have an object type `myNumberType` and you want to create a `valueOf` method for it.
|
322
|
+
* The following code assigns a user-defined function to the object's valueOf method:
|
323
|
+
*
|
324
|
+
* myNumberType.prototype.valueOf = new Function(functionText)
|
325
|
+
*
|
326
|
+
* With the preceding code in place, any time an object of type `myNumberType` is used in a context
|
327
|
+
* where it is to be represented as a primitive value, JavaScript automatically calls the function
|
328
|
+
* defined in the preceding code.
|
329
|
+
*
|
330
|
+
* An object's `valueOf` method is usually invoked by JavaScript, but you can invoke it yourself as
|
331
|
+
* follows:
|
332
|
+
*
|
333
|
+
* myNumber.valueOf()
|
334
|
+
*
|
335
|
+
* Note: Objects in string contexts convert via the `toString` method, which is different from
|
336
|
+
* `String` objects converting to string primitives using `valueOf`. All objects have a string
|
337
|
+
* conversion, if only `"[object type]"`. But many objects do not convert to number, boolean, or
|
338
|
+
* function.
|
339
|
+
*
|
340
|
+
* @return {Object} Returns value of the object or the object itself.
|
341
|
+
*/
|
342
|
+
|
343
|
+
//Properties
|
344
|
+
|
345
|
+
/**
|
346
|
+
* @property constructor
|
347
|
+
* Specifies the function that creates an object's prototype.
|
348
|
+
*
|
349
|
+
* Returns a reference to the Object function that created the instance's prototype. Note that the
|
350
|
+
* value of this property is a reference to the function itself, not a string containing the
|
351
|
+
* function's name, but it isn't read only (except for primitive Boolean, Number or String values: 1,
|
352
|
+
* true, "read-only").
|
353
|
+
*
|
354
|
+
* All objects inherit a `constructor` property from their `prototype`:
|
355
|
+
*
|
356
|
+
* o = new Object // or o = {} in JavaScript 1.2
|
357
|
+
* o.constructor == Object
|
358
|
+
* a = new Array // or a = [] in JavaScript 1.2
|
359
|
+
* a.constructor == Array
|
360
|
+
* n = new Number(3)
|
361
|
+
* n.constructor == Number
|
362
|
+
*
|
363
|
+
* Even though you cannot construct most HTML objects, you can do comparisons. For example,
|
364
|
+
*
|
365
|
+
* document.constructor == Document
|
366
|
+
* document.form3.constructor == Form
|
367
|
+
*
|
368
|
+
* The following example creates a prototype, `Tree`, and an object of that type, theTree. The example then displays the `constructor` property for the object `theTree`.
|
369
|
+
*
|
370
|
+
* function Tree(name) {
|
371
|
+
* this.name = name;
|
372
|
+
* }
|
373
|
+
* theTree = new Tree("Redwood");
|
374
|
+
* console.log("theTree.constructor is " + theTree.constructor);
|
375
|
+
*
|
376
|
+
* This example displays the following output:
|
377
|
+
*
|
378
|
+
* theTree.constructor is function Tree(name) {
|
379
|
+
* this.name = name;
|
380
|
+
* }
|
381
|
+
*
|
382
|
+
* The following example shows how to modify constructor value of generic objects. Only true, 1 and
|
383
|
+
* "test" variable constructors will not be changed. This example explains that is not always so safe
|
384
|
+
* to believe in constructor function.
|
385
|
+
*
|
386
|
+
* function Type(){};
|
387
|
+
* var types = [
|
388
|
+
* new Array, [],
|
389
|
+
* new Boolean, true,
|
390
|
+
* new Date,
|
391
|
+
* new Error,
|
392
|
+
* new Function, function(){},
|
393
|
+
* Math,
|
394
|
+
* new Number, 1,
|
395
|
+
* new Object, {},
|
396
|
+
* new RegExp, /(?:)/,
|
397
|
+
* new String, "test"
|
398
|
+
* ];
|
399
|
+
* for(var i = 0; i < types.length; i++){
|
400
|
+
* types[i].constructor = Type;
|
401
|
+
* types[i] = [types[i].constructor, types[i] instanceof Type, types[i].toString()];
|
402
|
+
* };
|
403
|
+
* alert(types.join("\n"));
|
404
|
+
*/
|
@@ -0,0 +1,415 @@
|
|
1
|
+
/**
|
2
|
+
* @class RegExp
|
3
|
+
*
|
4
|
+
* Creates a regular expression object for matching text according to a pattern.
|
5
|
+
*
|
6
|
+
* When using the constructor function, the normal string escape rules (preceding
|
7
|
+
* special characters with \ when included in a string) are necessary. For
|
8
|
+
* example, the following are equivalent:
|
9
|
+
*
|
10
|
+
* var re = new RegExp("\\w+");
|
11
|
+
* var re = /\w+/;
|
12
|
+
*
|
13
|
+
* Notice that the parameters to the literal format do not use quotation marks to
|
14
|
+
* indicate strings, while the parameters to the constructor function do use
|
15
|
+
* quotation marks. So the following expressions create the same regular
|
16
|
+
* expression:
|
17
|
+
*
|
18
|
+
* /ab+c/i;
|
19
|
+
* new RegExp("ab+c", "i");
|
20
|
+
*
|
21
|
+
* # Special characters in regular expressions
|
22
|
+
*
|
23
|
+
* | Character | Meaning
|
24
|
+
* |:-----------------|:--------------------------------------------------------------------------------------
|
25
|
+
* | `\` | For characters that are usually treated literally, indicates that the next character
|
26
|
+
* | | is special and not to be interpreted literally.
|
27
|
+
* | | For example, `/b/` matches the character 'b'. By placing a backslash in front of b, that
|
28
|
+
* | | is by using `/\b/`, the character becomes special to mean match a word boundary.
|
29
|
+
* | |
|
30
|
+
* | | _or_
|
31
|
+
* | |
|
32
|
+
* | | For characters that are usually treated specially, indicates that the next character is
|
33
|
+
* | | not special and should be interpreted literally.
|
34
|
+
* | |
|
35
|
+
* | | For example, `*` is a special character that means 0 or more occurrences of the preceding
|
36
|
+
* | | character should be matched; for example, `/a*\/` means match 0 or more "a"s. To match *
|
37
|
+
* | | literally, precede it with a backslash; for example, `/a\*\/` matches 'a*'.
|
38
|
+
* | |
|
39
|
+
* | `^` | Matches beginning of input. If the multiline flag is set to true, also matches
|
40
|
+
* | | immediately after a line break character.
|
41
|
+
* | |
|
42
|
+
* | | For example, `/^A/` does not match the 'A' in "an A", but does match the first 'A' in
|
43
|
+
* | | "An A".
|
44
|
+
* | |
|
45
|
+
* | `$` | Matches end of input. If the multiline flag is set to true, also matches immediately
|
46
|
+
* | | before a line break character.
|
47
|
+
* | |
|
48
|
+
* | | For example, `/t$/` does not match the 't' in "eater", but does match it in "eat".
|
49
|
+
* | |
|
50
|
+
* | `*` | Matches the preceding item 0 or more times.
|
51
|
+
* | |
|
52
|
+
* | | For example, `/bo*\/` matches 'boooo' in "A ghost booooed" and 'b' in "A bird warbled",
|
53
|
+
* | | but nothing in "A goat grunted".
|
54
|
+
* | |
|
55
|
+
* | `+` | Matches the preceding item 1 or more times. Equivalent to `{1,}`.
|
56
|
+
* | |
|
57
|
+
* | | For example, `/a+/` matches the 'a' in "candy" and all the a's in "caaaaaaandy".
|
58
|
+
* | |
|
59
|
+
* | `?` | Matches the preceding item 0 or 1 time.
|
60
|
+
* | |
|
61
|
+
* | | For example, `/e?le?/` matches the 'el' in "angel" and the 'le' in "angle."
|
62
|
+
* | |
|
63
|
+
* | | If used immediately after any of the quantifiers `*`, `+`, `?`, or `{}`, makes the quantifier
|
64
|
+
* | | non-greedy (matching the minimum number of times), as opposed to the default, which is
|
65
|
+
* | | greedy (matching the maximum number of times).
|
66
|
+
* | |
|
67
|
+
* | | Also used in lookahead assertions, described under `(?=)`, `(?!)`, and `(?:)` in this table.
|
68
|
+
* | |
|
69
|
+
* | `.` | (The decimal point) matches any single character except the newline characters: \n \r
|
70
|
+
* | | \u2028 or \u2029. (`[\s\S]` can be used to match any character including new lines.)
|
71
|
+
* | |
|
72
|
+
* | | For example, `/.n/` matches 'an' and 'on' in "nay, an apple is on the tree", but not 'nay'.
|
73
|
+
* | |
|
74
|
+
* | `(x)` | Matches `x` and remembers the match. These are called capturing parentheses.
|
75
|
+
* | |
|
76
|
+
* | | For example, `/(foo)/` matches and remembers 'foo' in "foo bar." The matched substring can
|
77
|
+
* | | be recalled from the resulting array's elements `[1], ..., [n]` or from the predefined RegExp
|
78
|
+
* | | object's properties `$1, ..., $9`.
|
79
|
+
* | |
|
80
|
+
* | `(?:x)` | Matches `x` but does not remember the match. These are called non-capturing parentheses.
|
81
|
+
* | | The matched substring can not be recalled from the resulting array's elements `[1], ..., [n]`
|
82
|
+
* | | or from the predefined RegExp object's properties `$1, ..., $9`.
|
83
|
+
* | |
|
84
|
+
* | `x(?=y)` | Matches `x` only if `x` is followed by `y`. For example, `/Jack(?=Sprat)/` matches 'Jack' only if
|
85
|
+
* | | it is followed by 'Sprat'. `/Jack(?=Sprat|Frost)/` matches 'Jack' only if it is followed by
|
86
|
+
* | | 'Sprat' or 'Frost'. However, neither 'Sprat' nor 'Frost' is part of the match results.
|
87
|
+
* | |
|
88
|
+
* | `x(?!y)` | Matches `x` only if `x` is not followed by `y`. For example, `/\d+(?!\.)/` matches a number only
|
89
|
+
* | | if it is not followed by a decimal point.
|
90
|
+
* | |
|
91
|
+
* | | `/\d+(?!\.)/.exec("3.141")` matches 141 but not 3.141.
|
92
|
+
* | |
|
93
|
+
* | `x|y` | Matches either `x` or `y`.
|
94
|
+
* | |
|
95
|
+
* | | For example, `/green|red/` matches 'green' in "green apple" and 'red' in "red apple."
|
96
|
+
* | |
|
97
|
+
* | `{n}` | Where `n` is a positive integer. Matches exactly n occurrences of the preceding item.
|
98
|
+
* | |
|
99
|
+
* | | For example, `/a{2}/` doesn't match the 'a' in "candy," but it matches all of the a's
|
100
|
+
* | | in "caandy," and the first two a's in "caaandy."
|
101
|
+
* | |
|
102
|
+
* | `{n,}` | Where `n` is a positive integer. Matches at least n occurrences of the preceding item.
|
103
|
+
* | |
|
104
|
+
* | | For example, `/a{2,}/` doesn't match the 'a' in "candy", but matches all of the a's in
|
105
|
+
* | | "caandy" and in "caaaaaaandy."
|
106
|
+
* | |
|
107
|
+
* | `{n,m}` | Where `n` and `m` are positive integers. Matches at least `n` and at most `m` occurrences of the
|
108
|
+
* | | preceding item.
|
109
|
+
* | |
|
110
|
+
* | | For example, `/a{1,3}/` matches nothing in "cndy", the 'a' in "candy," the first two a's
|
111
|
+
* | | in "caandy," and the first three a's in "caaaaaaandy". Notice that when matching
|
112
|
+
* | | "caaaaaaandy", the match is "aaa", even though the original string had more a's in it.
|
113
|
+
* | |
|
114
|
+
* | `[xyz]` | A character set. Matches any one of the enclosed characters. You can specify a range of
|
115
|
+
* | | characters by using a hyphen.
|
116
|
+
* | |
|
117
|
+
* | | For example, `[abcd]` is the same as `[a-d]`. They match the 'b' in "brisket" and the 'c'
|
118
|
+
* | | in "chop".
|
119
|
+
* | |
|
120
|
+
* | `[^xyz]` | A negated or complemented character set. That is, it matches anything that is not
|
121
|
+
* | | enclosed in the brackets. You can specify a range of characters by using a hyphen.
|
122
|
+
* | |
|
123
|
+
* | | For example, `[^abc]` is the same as `[^a-c]`. They initially match 'r' in "brisket" and
|
124
|
+
* | | 'h' in "chop."
|
125
|
+
* | |
|
126
|
+
* | `[\b]` | Matches a backspace. (Not to be confused with `\b`.)
|
127
|
+
* | |
|
128
|
+
* | `\b` | Matches a word boundary, such as a space. (Not to be confused with `[\b]`.)
|
129
|
+
* | |
|
130
|
+
* | | For example, `/\bn\w/` matches the 'no' in "noonday"; `/\wy\b/` matches the 'ly' in
|
131
|
+
* | | "possibly yesterday."
|
132
|
+
* | |
|
133
|
+
* | `\B` | Matches a non-word boundary.
|
134
|
+
* | |
|
135
|
+
* | | For example, `/\w\Bn/` matches 'on' in "noonday", and `/y\B\w/` matches 'ye' in "possibly
|
136
|
+
* | | yesterday."
|
137
|
+
* | |
|
138
|
+
* | `\cX` | Where X is a letter from A - Z. Matches a control character in a string.
|
139
|
+
* | |
|
140
|
+
* | | For example, `/\cM/` matches control-M in a string.
|
141
|
+
* | |
|
142
|
+
* | `\d` | Matches a digit character in the basic Latin alphabet. Equivalent to `[0-9]`.
|
143
|
+
* | |
|
144
|
+
* | | For example, `/\d/` or `/[0-9]/` matches '2' in "B2 is the suite number."
|
145
|
+
* | |
|
146
|
+
* | `\D` | Matches any non-digit character in the basic Latin alphabet. Equivalent to `[^0-9]`.
|
147
|
+
* | |
|
148
|
+
* | | For example, `/\D/` or `/[^0-9]/` matches 'B' in "B2 is the suite number.
|
149
|
+
* | |
|
150
|
+
* | `\f` | Matches a form-feed.
|
151
|
+
* | |
|
152
|
+
* | `\n` | Matches a linefeed.
|
153
|
+
* | |
|
154
|
+
* | `\r` | Matches a carriage return.
|
155
|
+
* | |
|
156
|
+
* | `\s` | Matches a single white space character, including space, tab, form feed, line feed and
|
157
|
+
* | | other unicode spaces. Equivalent to:
|
158
|
+
* | |
|
159
|
+
* | | `[\t\n\v\f\r \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000]`
|
160
|
+
* | |
|
161
|
+
* | | For example, `/\s\w*\/` matches ' bar' in "foo bar."
|
162
|
+
* | |
|
163
|
+
* | `\S` | Matches a single character other than white space. Equivalent to:
|
164
|
+
* | |
|
165
|
+
* | | `[^\t\n\v\f\r \u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000]`
|
166
|
+
* | |
|
167
|
+
* | | For example, `/\S\w*\/` matches 'foo' in "foo bar."
|
168
|
+
* | |
|
169
|
+
* | `\t` | Matches a tab.
|
170
|
+
* | |
|
171
|
+
* | `\v` | Matches a vertical tab.
|
172
|
+
* | |
|
173
|
+
* | `\w` | Matches any alphanumeric character from the basic Latin alphabet, including the
|
174
|
+
* | | underscore. Equivalent to `[A-Za-z0-9_]`.
|
175
|
+
* | |
|
176
|
+
* | | For example, `/\w/` matches 'a' in "apple," '5' in "$5.28," and '3' in "3D."
|
177
|
+
* | |
|
178
|
+
* | `\W` | Matches any character that is not a word character from the basic Latin alphabet. Equivalent
|
179
|
+
* | | to `[^A-Za-z0-9_]`.
|
180
|
+
* | |
|
181
|
+
* | | For example, `/\W/` or `/[^A-Za-z0-9_]/` matches '%' in "50%."
|
182
|
+
* | |
|
183
|
+
* | `\n` | Where `n` is a positive integer. A back reference to the last substring matching the n
|
184
|
+
* | | parenthetical in the regular expression (counting left parentheses).
|
185
|
+
* | |
|
186
|
+
* | | For example, `/apple(,)\sorange\1/` matches 'apple, orange,' in "apple, orange, cherry,
|
187
|
+
* | | peach." A more complete example follows this table.
|
188
|
+
* | |
|
189
|
+
* | `\0` | Matches a NULL character. Do not follow this with another digit.
|
190
|
+
* | |
|
191
|
+
* | `\xhh` | Matches the character with the code `hh` (two hexadecimal digits)
|
192
|
+
* | |
|
193
|
+
* | `\uhhhh` | Matches the character with the Unicode value `hhhh` (four hexadecimal digits)
|
194
|
+
*
|
195
|
+
* The literal notation provides compilation of the regular expression when the expression is evaluated. Use
|
196
|
+
* literal notation when the regular expression will remain constant. For example, if you use literal notation
|
197
|
+
* to construct a regular expression used in a loop, the regular expression won't be recompiled on each iteration.
|
198
|
+
*
|
199
|
+
* The constructor of the regular expression object, for example, new RegExp("ab+c"), provides runtime
|
200
|
+
* compilation of the regular expression. Use the constructor function when you know the regular expression
|
201
|
+
* pattern will be changing, or you don't know the pattern and are getting it from another source, such as user input.
|
202
|
+
*
|
203
|
+
* <div class="notice">
|
204
|
+
* Documentation for this class comes from <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp">MDN</a>
|
205
|
+
* and is available under <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons: Attribution-Sharealike license</a>.
|
206
|
+
* </div>
|
207
|
+
*/
|
208
|
+
|
209
|
+
/**
|
210
|
+
* @method constructor
|
211
|
+
* Creates new regular expression object.
|
212
|
+
*
|
213
|
+
* @param {String} pattern
|
214
|
+
* The text of the regular expression.
|
215
|
+
* @param {String} flags
|
216
|
+
* If specified, flags can have any combination of the following values:
|
217
|
+
*
|
218
|
+
* - "g" - global match
|
219
|
+
* - "i" - ignore case
|
220
|
+
* - "m" - Treat beginning and end characters (^ and $) as working over multiple lines
|
221
|
+
* (i.e., match the beginning or end of _each_ line (delimited by \n or \r), not
|
222
|
+
* only the very beginning or end of the whole input string)
|
223
|
+
*/
|
224
|
+
|
225
|
+
//Methods
|
226
|
+
|
227
|
+
/**
|
228
|
+
* @method exec
|
229
|
+
* Executes a search for a match in its string parameter.
|
230
|
+
*
|
231
|
+
* If the match succeeds, the `exec` method returns an array and updates properties of the regular
|
232
|
+
* expression object. The returned array has the matched text as the first item, and then one item for
|
233
|
+
* each capturing parenthesis that matched containing the text that was captured. If the match fails,
|
234
|
+
* the `exec` method returns `null`.
|
235
|
+
*
|
236
|
+
* If you are executing a match simply to find true or false, use the `test` method or the `String
|
237
|
+
* search` method.
|
238
|
+
*
|
239
|
+
* Consider the following example:
|
240
|
+
*
|
241
|
+
* // Match one d followed by one or more b's followed by one d
|
242
|
+
* // Remember matched b's and the following d
|
243
|
+
* // Ignore case
|
244
|
+
* var re = /d(b+)(d)/ig;
|
245
|
+
* var result = re.exec("cdbBdbsbz");
|
246
|
+
*
|
247
|
+
* The following table shows the results for this script:
|
248
|
+
*
|
249
|
+
* | Object | Property/Index | Description | Example
|
250
|
+
* |:-----------------|:---------------|:---------------------------------------------------------------------|:---------------------
|
251
|
+
* | `result` | | The content of myArray. | `["dbBd", "bB", "d"]`
|
252
|
+
* | | `index` | The 0-based index of the match in the string | `1`
|
253
|
+
* | | `input` | The original string. | `cdbDdbsbz`
|
254
|
+
* | | `[0]` | The last matched characters. | `dbBd`
|
255
|
+
* | | `[1], ...[n]` | The parenthesized substring matches, if any. The number of possible | `[1] = bB`
|
256
|
+
* | | | parenthesized substrings is unlimited. | `[2] = d`
|
257
|
+
* | `re` | `lastIndex` | The index at which to start the next match. | `5`
|
258
|
+
* | | `ignoreCase` | Indicates the "`i`" flag was used to ignore case. | `true`
|
259
|
+
* | | `global` | Indicates the "`g`" flag was used for a global match. | `true`
|
260
|
+
* | | `multiline` | Indicates the "`m`" flag was used to search in strings across | `false`
|
261
|
+
* | | | multiple lines. |
|
262
|
+
* | | `source` | The text of the pattern. | d(b+)(d)
|
263
|
+
*
|
264
|
+
* If your regular expression uses the "`g`" flag, you can use the `exec` method multiple times to find
|
265
|
+
* successive matches in the same string. When you do so, the search starts at the substring of `str`
|
266
|
+
* specified by the regular expression's `lastIndex` property (`test` will also advance the `lastIndex`
|
267
|
+
* property). For example, assume you have this script:
|
268
|
+
*
|
269
|
+
* var myRe = /ab*\/g;
|
270
|
+
* var str = "abbcdefabh";
|
271
|
+
* var myArray;
|
272
|
+
* while ((myArray = myRe.exec(str)) != null)
|
273
|
+
* {
|
274
|
+
* var msg = "Found " + myArray[0] + ". ";
|
275
|
+
* msg += "Next match starts at " + myRe.lastIndex;
|
276
|
+
* print(msg);
|
277
|
+
* }
|
278
|
+
*
|
279
|
+
* This script displays the following text:
|
280
|
+
*
|
281
|
+
* Found abb. Next match starts at 3
|
282
|
+
* Found ab. Next match starts at 9
|
283
|
+
*
|
284
|
+
* You can also use `exec()` without creating a RegExp object:
|
285
|
+
*
|
286
|
+
* var matches = /(hello \S+)/.exec('This is a hello world!');
|
287
|
+
* alert(matches[1]);
|
288
|
+
*
|
289
|
+
* This will display an alert containing 'hello world!';
|
290
|
+
*
|
291
|
+
* @param {String} str The string against which to match the regular expression.
|
292
|
+
* @return {Array} Array of results or `NULL`.
|
293
|
+
*/
|
294
|
+
|
295
|
+
/**
|
296
|
+
* @method test
|
297
|
+
* Tests for a match in its string parameter.
|
298
|
+
*
|
299
|
+
* When you want to know whether a pattern is found in a string use the test method (similar to the
|
300
|
+
* `String.search` method); for more information (but slower execution) use the exec method (similar to
|
301
|
+
* the `String.match` method). As with exec (or in combination with it), test called multiple times on
|
302
|
+
* the same global regular expression instance will advance past the previous match.
|
303
|
+
*
|
304
|
+
* The following example prints a message which depends on the success of the test:
|
305
|
+
*
|
306
|
+
* function testinput(re, str){
|
307
|
+
* if (re.test(str))
|
308
|
+
* midstring = " contains ";
|
309
|
+
* else
|
310
|
+
* midstring = " does not contain ";
|
311
|
+
* document.write (str + midstring + re.source);
|
312
|
+
* }
|
313
|
+
*
|
314
|
+
* @param {String} str The string against which to match the regular expression.
|
315
|
+
* @return {Boolean} true if string contains any matches, otherwise returns false.
|
316
|
+
*/
|
317
|
+
|
318
|
+
/**
|
319
|
+
* @method toString
|
320
|
+
* Returns a string representing the specified object. Overrides the `Object.prototype.toString`
|
321
|
+
* method.
|
322
|
+
*
|
323
|
+
* The RegExp object overrides the `toString` method of the `Object` object; it does not inherit
|
324
|
+
* `Object.toString`. For RegExp objects, the `toString` method returns a string representation of the
|
325
|
+
* regular expression.
|
326
|
+
*
|
327
|
+
* The following example displays the string value of a RegExp object:
|
328
|
+
*
|
329
|
+
* myExp = new RegExp("a+b+c");
|
330
|
+
* alert(myExp.toString()); // displays "/a+b+c/"
|
331
|
+
*
|
332
|
+
* @return {String} Regular expression as a string.
|
333
|
+
*/
|
334
|
+
|
335
|
+
//Properties
|
336
|
+
|
337
|
+
// Note that several of the RegExp properties have both long and short (Perl-like) names.
|
338
|
+
// Both names always refer to the same value. Perl is the programming language from which
|
339
|
+
// JavaScript modeled its regular expressions.
|
340
|
+
|
341
|
+
/**
|
342
|
+
* @property {Boolean} global
|
343
|
+
* Whether to test the regular expression against all possible matches in a
|
344
|
+
* string, or only against the first.
|
345
|
+
*
|
346
|
+
* `global` is a property of an individual regular expression object.
|
347
|
+
*
|
348
|
+
* The value of `global` is true if the "`g`" flag was used; otherwise, `false`. The "`g`" flag
|
349
|
+
* indicates that the regular expression should be tested against all possible matches in a string.
|
350
|
+
*
|
351
|
+
* You cannot change this property directly.
|
352
|
+
*/
|
353
|
+
|
354
|
+
/**
|
355
|
+
* @property {Boolean} ignoreCase
|
356
|
+
* Whether to ignore case while attempting a match in a string.
|
357
|
+
*
|
358
|
+
* `ignoreCase` is a property of an individual regular expression object.
|
359
|
+
*
|
360
|
+
* The value of `ignoreCase` is true if the "`i`" flag was used; otherwise, false. The "`i`" flag indicates
|
361
|
+
* that case should be ignored while attempting a match in a string.
|
362
|
+
*
|
363
|
+
* You cannot change this property directly.
|
364
|
+
*/
|
365
|
+
|
366
|
+
/**
|
367
|
+
* @property {Number} lastIndex
|
368
|
+
* The index at which to start the next match. A read/write integer property that specifies the index
|
369
|
+
* at which to start the next match.
|
370
|
+
*
|
371
|
+
* `lastIndex` is a property of an individual regular expression object.
|
372
|
+
*
|
373
|
+
* This property is set only if the regular expression used the "`g`" flag to indicate a global search.
|
374
|
+
* The following rules apply:
|
375
|
+
*
|
376
|
+
* - If `lastIndex` is greater than the length of the string, `regexp.test` and `regexp.exec` fail,
|
377
|
+
* and `lastIndex` is set to 0.
|
378
|
+
* - If `lastIndex` is equal to the length of the string and if the regular expression matches the
|
379
|
+
* empty string, then the regular expression matches input starting at `lastIndex`.
|
380
|
+
* - If `lastIndex` is equal to the length of the string and if the regular expression does not match
|
381
|
+
* the empty string, then the regular expression mismatches input, and `lastIndex` is reset to 0.
|
382
|
+
* - Otherwise, `lastIndex` is set to the next position following the most recent match.
|
383
|
+
*
|
384
|
+
* For example, consider the following sequence of statements:
|
385
|
+
*
|
386
|
+
* - `re = /(hi)?/g` Matches the empty string.
|
387
|
+
* - `re("hi")` Returns `["hi", "hi"]` with `lastIndex` equal to 2.
|
388
|
+
* - `re("hi")` Returns `[""]`, an empty array whose zeroth element is the match string. In this
|
389
|
+
* case, the empty string because `lastIndex` was 2 (and still is 2) and "`hi`" has length 2.
|
390
|
+
*/
|
391
|
+
|
392
|
+
/**
|
393
|
+
* @property {Boolean} multiline
|
394
|
+
* Whether or not to search in strings across multiple lines.
|
395
|
+
*
|
396
|
+
* `multiline` is a property of an individual regular expression object..
|
397
|
+
*
|
398
|
+
* The value of `multiline` is true if the "`m`" flag was used; otherwise, `false`. The "`m`" flag
|
399
|
+
* indicates that a multiline input string should be treated as multiple lines. For example, if "`m`"
|
400
|
+
* is used, "`^`" and "`$`" change from matching at only the start or end of the entire string to the
|
401
|
+
* start or end of any line within the string.
|
402
|
+
*
|
403
|
+
* You cannot change this property directly.
|
404
|
+
*/
|
405
|
+
|
406
|
+
/**
|
407
|
+
* @property {String} source
|
408
|
+
* The text of the pattern.
|
409
|
+
*
|
410
|
+
* A read-only property that contains the text of the pattern, excluding the forward slashes.
|
411
|
+
*
|
412
|
+
* `source` is a property of an individual regular expression object.
|
413
|
+
*
|
414
|
+
* You cannot change this property directly.
|
415
|
+
*/
|