|
1 | 1 | /*! |
2 | | - * VerbalExpressions JavaScript Library v0.2.1 |
| 2 | + * VerbalExpressions JavaScript Library v0.3.0 |
3 | 3 | * https://github.com/VerbalExpressions/JSVerbalExpressions |
4 | 4 | * |
5 | 5 | * |
|
104 | 104 | startOfLine: function startOfLine(enable) { |
105 | 105 | enable = (enable !== false); |
106 | 106 | this._prefixes = enable ? '^' : ''; |
107 | | - this.add(); |
108 | | - |
109 | | - return this; |
| 107 | + return this.add(); |
110 | 108 | }, |
111 | 109 |
|
112 | 110 | /** |
|
117 | 115 | endOfLine: function endOfLine(enable) { |
118 | 116 | enable = (enable !== false); |
119 | 117 | this._suffixes = enable ? '$' : ''; |
120 | | - this.add(); |
121 | | - |
122 | | - return this; |
| 118 | + return this.add(); |
123 | 119 | }, |
124 | 120 |
|
125 | 121 | /** |
|
129 | 125 | */ |
130 | 126 | then: function then(value) { |
131 | 127 | value = this.sanitize(value); |
132 | | - this.add('(?:' + value + ')'); |
133 | | - |
134 | | - return this; |
| 128 | + return this.add('(?:' + value + ')'); |
135 | 129 | }, |
136 | 130 |
|
137 | 131 | /** |
|
150 | 144 | */ |
151 | 145 | maybe: function maybe(value) { |
152 | 146 | value = this.sanitize(value); |
153 | | - this.add('(?:' + value + ')?'); |
154 | | - |
155 | | - return this; |
| 147 | + return this.add('(?:' + value + ')?'); |
156 | 148 | }, |
157 | 149 |
|
158 | 150 | /** |
|
161 | 153 | * @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining |
162 | 154 | */ |
163 | 155 | anything: function anything() { |
164 | | - this.add('(?:.*)'); |
165 | | - return this; |
| 156 | + return this.add('(?:.*)'); |
166 | 157 | }, |
167 | 158 |
|
168 | 159 | /** |
|
172 | 163 | */ |
173 | 164 | anythingBut: function anythingBut(value) { |
174 | 165 | value = this.sanitize(value); |
175 | | - this.add('(?:[^' + value + ']*)'); |
176 | | - |
177 | | - return this; |
| 166 | + return this.add('(?:[^' + value + ']*)'); |
178 | 167 | }, |
179 | 168 |
|
180 | 169 | /** |
181 | 170 | * Any character at least one time |
182 | 171 | * @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining |
183 | 172 | */ |
184 | 173 | something: function something() { |
185 | | - this.add('(?:.+)'); |
186 | | - return this; |
| 174 | + return this.add('(?:.+)'); |
187 | 175 | }, |
188 | 176 |
|
189 | 177 | /** |
|
193 | 181 | */ |
194 | 182 | somethingBut: function somethingBut(value) { |
195 | 183 | value = this.sanitize(value); |
196 | | - this.add('(?:[^' + value + ']+)'); |
197 | | - |
198 | | - return this; |
| 184 | + return this.add('(?:[^' + value + ']+)'); |
199 | 185 | }, |
200 | 186 |
|
201 | 187 | /** |
|
217 | 203 | * @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining |
218 | 204 | */ |
219 | 205 | lineBreak: function lineBreak() { |
220 | | - this.add('(?:\\r\\n|\\r|\\n)'); // Unix + Windows CRLF |
221 | | - return this; |
| 206 | + return this.add('(?:\\r\\n|\\r|\\n)'); // Unix + Windows CRLF |
222 | 207 | }, |
223 | 208 |
|
224 | 209 | /** |
|
234 | 219 | * @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining |
235 | 220 | */ |
236 | 221 | tab: function tab() { |
237 | | - this.add('\\t'); |
238 | | - return this; |
| 222 | + return this.add('\\t'); |
239 | 223 | }, |
240 | 224 |
|
241 | 225 | /** |
242 | 226 | * Any alphanumeric |
243 | 227 | * @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining |
244 | 228 | */ |
245 | 229 | word: function word() { |
246 | | - this.add('\\w+'); |
| 230 | + return this.add('\\w+'); |
| 231 | + }, |
| 232 | + |
| 233 | + /** |
| 234 | + * Any digit |
| 235 | + * @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining |
| 236 | + */ |
| 237 | + digit: function digit() { |
| 238 | + this.add('\\d'); |
247 | 239 | return this; |
248 | 240 | }, |
249 | 241 |
|
|
252 | 244 | * @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining |
253 | 245 | */ |
254 | 246 | whitespace: function whitespace() { |
255 | | - this.add('\\s'); |
256 | | - return this; |
| 247 | + return this.add('\\s'); |
257 | 248 | }, |
258 | 249 |
|
259 | 250 | /** |
|
263 | 254 | */ |
264 | 255 | anyOf: function anyOf(value) { |
265 | 256 | value = this.sanitize(value); |
266 | | - this.add('[' + value + ']'); |
267 | | - |
268 | | - return this; |
| 257 | + return this.add('[' + value + ']'); |
269 | 258 | }, |
270 | 259 |
|
271 | 260 | /** |
|
301 | 290 |
|
302 | 291 | buffer[index++] = ']'; |
303 | 292 |
|
304 | | - this.add(buffer.join('')); |
305 | | - |
306 | | - return this; |
| 293 | + return this.add(buffer.join('')); |
307 | 294 | }, |
308 | 295 |
|
309 | 296 | /// Modifiers /// |
|
318 | 305 | this._modifiers += modifier; |
319 | 306 | } |
320 | 307 |
|
321 | | - this.add(); |
322 | | - |
323 | | - return this; |
| 308 | + return this.add(); |
324 | 309 | }, |
325 | 310 |
|
326 | 311 | /** |
|
330 | 315 | */ |
331 | 316 | removeModifier: function removeModifier(modifier) { |
332 | 317 | this._modifiers = this._modifiers.replace(modifier, ''); |
333 | | - this.add(); |
334 | | - |
335 | | - return this; |
| 318 | + return this.add(); |
336 | 319 | }, |
337 | 320 |
|
338 | 321 | /** |
|
341 | 324 | * @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining |
342 | 325 | */ |
343 | 326 | withAnyCase: function withAnyCase(enable) { |
344 | | - if (enable !== false) { |
345 | | - this.addModifier('i'); |
346 | | - } else { |
347 | | - this.removeModifier('i'); |
348 | | - } |
349 | | - |
350 | | - this.add(); |
351 | | - |
352 | | - return this; |
| 327 | + return enable !== false ? this.addModifier('i') : this.removeModifier('i'); |
353 | 328 | }, |
354 | 329 |
|
355 | 330 | /** |
|
358 | 333 | * @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining |
359 | 334 | */ |
360 | 335 | stopAtFirst: function stopAtFirst(enable) { |
361 | | - if (enable !== false) { |
362 | | - this.removeModifier('g'); |
363 | | - } else { |
364 | | - this.addModifier('g'); |
365 | | - } |
366 | | - |
367 | | - this.add(); |
368 | | - |
369 | | - return this; |
| 336 | + return enable !== false ? this.removeModifier('g') : this.addModifier('g'); |
370 | 337 | }, |
371 | 338 |
|
372 | 339 | /** |
|
375 | 342 | * @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining |
376 | 343 | */ |
377 | 344 | searchOneLine: function searchOneLine(enable) { |
378 | | - if (enable !== false) { |
379 | | - this.removeModifier('m'); |
380 | | - } else { |
381 | | - this.addModifier('m'); |
382 | | - } |
383 | | - |
384 | | - this.add(); |
385 | | - |
386 | | - return this; |
| 345 | + return enable !== false ? this.removeModifier('m') : this.addModifier('m'); |
387 | 346 | }, |
388 | 347 |
|
389 | 348 | /** |
|
410 | 369 | } |
411 | 370 |
|
412 | 371 |
|
413 | | - this.add(value); |
414 | | - |
415 | | - return (this); |
| 372 | + return this.add(value); |
416 | 373 | }, |
417 | 374 |
|
418 | 375 | /** |
419 | 376 | * Repeats the previous at least once |
420 | 377 | * @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining |
421 | 378 | */ |
422 | 379 | oneOrMore: function oneOrMore() { |
423 | | - this.add('+'); |
424 | | - return (this); |
| 380 | + return this.add('+'); |
425 | 381 | }, |
426 | 382 |
|
427 | 383 | /// Loops /// |
|
470 | 426 | beginCapture: function beginCapture() { |
471 | 427 | // Add the end of the capture group to the suffixes for now so compilation continues to work |
472 | 428 | this._suffixes += ')'; |
473 | | - this.add('('); |
474 | | - |
475 | | - return this; |
| 429 | + return this.add('('); |
476 | 430 | }, |
477 | 431 |
|
478 | 432 | /** |
|
482 | 436 | endCapture: function endCapture() { |
483 | 437 | // Remove the last parentheses from the _suffixes and add to the regex itself |
484 | 438 | this._suffixes = this._suffixes.substring(0, this._suffixes.length - 1); |
485 | | - this.add(')'); |
486 | | - |
487 | | - return this; |
| 439 | + return this.add(')'); |
488 | 440 | }, |
489 | 441 |
|
490 | 442 | /** |
|
0 commit comments