Skip to content

Commit 70afa5b

Browse files
authored
feat: implement letter.lowercase and letter.uppercase (#77)
1 parent 736c4b9 commit 70afa5b

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

docs/content/2.getting-started/2.usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ There are a range of helpers that can be used to activate pattern matching, and
3939
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
4040
| `charIn`, `charNotIn` | this matches or doesn't match any character in the string provided. |
4141
| `anyOf` | this takes an array of inputs and matches any of them. |
42-
| `char`, `word`, `wordChar`, `wordBoundary`, `digit`, `whitespace`, `letter`, `tab`, `linefeed` and `carriageReturn` | these are helpers for specific RegExp characters. |
43-
| `not` | this can prefix `word`, `wordChar`, `wordBoundary`, `digit`, `whitespace`, `letter`, `tab`, `linefeed` or `carriageReturn`. For example `createRegExp(not.letter)`. |
42+
| `char`, `word`, `wordChar`, `wordBoundary`, `digit`, `whitespace`, `letter`, `letter.lowercase`, `letter.uppercase`, `tab`, `linefeed` and `carriageReturn` | these are helpers for specific RegExp characters. |
43+
| `not` | this can prefix `word`, `wordChar`, `wordBoundary`, `digit`, `whitespace`, `letter`, `letter.lowercase`, `letter.uppercase`, `tab`, `linefeed` or `carriageReturn`. For example `createRegExp(not.letter)`. |
4444
| `maybe` | equivalent to `?` - this marks the input as optional. |
4545
| `oneOrMore` | Equivalent to `+` - this marks the input as repeatable, any number of times but at least once. |
4646
| `exactly` | This escapes a string input to match it exactly. |

src/core/inputs.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ export const wordChar = createInput('\\w')
3737
export const wordBoundary = createInput('\\b')
3838
export const digit = createInput('\\d')
3939
export const whitespace = createInput('\\s')
40-
export const letter = createInput('[a-zA-Z]')
40+
export const letter = Object.assign(createInput('[a-zA-Z]'), {
41+
lowercase: createInput('[a-z]'),
42+
uppercase: createInput('[A-Z]'),
43+
})
4144
export const tab = createInput('\\t')
4245
export const linefeed = createInput('\\n')
4346
export const carriageReturn = createInput('\\r')
@@ -47,7 +50,10 @@ export const not = {
4750
wordBoundary: createInput('\\B'),
4851
digit: createInput('\\D'),
4952
whitespace: createInput('\\S'),
50-
letter: createInput('[^a-zA-Z]'),
53+
letter: Object.assign(createInput('[^a-zA-Z]'), {
54+
lowercase: createInput('[^a-z]'),
55+
uppercase: createInput('[^A-Z]'),
56+
}),
5157
tab: createInput('[^\\t]'),
5258
linefeed: createInput('[^\\n]'),
5359
carriageReturn: createInput('[^\\r]'),

test/inputs.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ describe('inputs', () => {
120120
expect(new RegExp(input as any)).toMatchInlineSnapshot('/\\[a-zA-Z\\]/')
121121
expectTypeOf(extractRegExp(input)).toEqualTypeOf<'[a-zA-Z]'>()
122122
})
123+
it('letter.lowercase', () => {
124+
const input = letter.lowercase
125+
expect(new RegExp(input as any)).toMatchInlineSnapshot('/\\[a-z\\]/')
126+
expectTypeOf(extractRegExp(input)).toEqualTypeOf<'[a-z]'>()
127+
})
128+
it('letter.uppercase', () => {
129+
const input = letter.uppercase
130+
expect(new RegExp(input as any)).toMatchInlineSnapshot('/\\[A-Z\\]/')
131+
expectTypeOf(extractRegExp(input)).toEqualTypeOf<'[A-Z]'>()
132+
})
123133
it('tab', () => {
124134
const input = tab
125135
expect(new RegExp(input as any)).toMatchInlineSnapshot('/\\\\t/')
@@ -146,6 +156,10 @@ describe('inputs', () => {
146156
expectTypeOf(extractRegExp(not.whitespace)).toEqualTypeOf<'\\S'>()
147157
expect(not.letter.toString()).toMatchInlineSnapshot('"[^a-zA-Z]"')
148158
expectTypeOf(extractRegExp(not.letter)).toEqualTypeOf<'[^a-zA-Z]'>()
159+
expect(not.letter.lowercase.toString()).toMatchInlineSnapshot('"[^a-z]"')
160+
expectTypeOf(extractRegExp(not.letter.lowercase)).toEqualTypeOf<'[^a-z]'>()
161+
expect(not.letter.uppercase.toString()).toMatchInlineSnapshot('"[^A-Z]"')
162+
expectTypeOf(extractRegExp(not.letter.uppercase)).toEqualTypeOf<'[^A-Z]'>()
149163
expect(not.tab.toString()).toMatchInlineSnapshot('"[^\\\\t]"')
150164
expectTypeOf(extractRegExp(not.tab)).toEqualTypeOf<'[^\\t]'>()
151165
expect(not.linefeed.toString()).toMatchInlineSnapshot('"[^\\\\n]"')

0 commit comments

Comments
 (0)