Skip to content

Commit ca7498b

Browse files
authored
Merge pull request #155 from ronfroy/master
add digit method + editor.config file
2 parents 715b25c + 4b5f4cf commit ca7498b

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*.js]
4+
end_of_line = LF
5+
indent_style = space
6+
indent_size = 4
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
/docs/
44
/dist/docs/verbal-expressions/*
55
!/dist/docs/verbal-expressions/0.2.1/
6+
.idea/

VerbalExpressions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@
230230
return this.add('\\w+');
231231
},
232232

233+
/**
234+
* Any digit
235+
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
236+
*/
237+
digit: function digit() {
238+
this.add('\\d');
239+
return this;
240+
},
241+
233242
/**
234243
* Any whitespace
235244
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining

test/tests.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,32 @@ test('multiple', function multipleTest() {
217217
testString = 'foo';
218218
ok(!testRegex.test(testString), 'Should be \'foo\' repeated two to five times');
219219
});
220+
221+
222+
test('word', function multipleTest() {
223+
var testRegex = VerEx().word();
224+
var testString = 'azertyuiopqsdfghjklmwxcvbn0123456789_';
225+
var i;
226+
var len;
227+
228+
ok(testRegex.test(testString), 'Should match word');
229+
230+
testString = '. @[]|,&~-';
231+
for (i = 0, len = testString.length; i < len; i++) {
232+
ok(!testRegex.test(testString[i]), 'Should not match word (' + testString[i] + ')');
233+
}
234+
});
235+
236+
test('digit', function multipleTest() {
237+
var testRegex = VerEx().digit();
238+
var testString = '0123456789';
239+
var i;
240+
var len;
241+
242+
ok(testRegex.test(testString), 'Should match digit');
243+
244+
testString = '-.azertyuiopqsdfghjklmwxcvbn @[]|,_&~';
245+
for (i = 0, len = testString.length; i < len; i++) {
246+
ok(!testRegex.test(testString[i]), 'Should not match digit (' + testString[i] + ')');
247+
}
248+
});

0 commit comments

Comments
 (0)