Skip to content

feat: implement letter.lowercase and letter.uppercase #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/content/2.getting-started/2.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ There are a range of helpers that can be used to activate pattern matching, and
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `charIn`, `charNotIn` | this matches or doesn't match any character in the string provided. |
| `anyOf` | this takes an array of inputs and matches any of them. |
| `char`, `word`, `wordChar`, `wordBoundary`, `digit`, `whitespace`, `letter`, `tab`, `linefeed` and `carriageReturn` | these are helpers for specific RegExp characters. |
| `not` | this can prefix `word`, `wordChar`, `wordBoundary`, `digit`, `whitespace`, `letter`, `tab`, `linefeed` or `carriageReturn`. For example `createRegExp(not.letter)`. |
| `char`, `word`, `wordChar`, `wordBoundary`, `digit`, `whitespace`, `letter`, `letter.lowercase`, `letter.uppercase`, `tab`, `linefeed` and `carriageReturn` | these are helpers for specific RegExp characters. |
| `not` | this can prefix `word`, `wordChar`, `wordBoundary`, `digit`, `whitespace`, `letter`, `letter.lowercase`, `letter.uppercase`, `tab`, `linefeed` or `carriageReturn`. For example `createRegExp(not.letter)`. |
| `maybe` | equivalent to `?` - this marks the input as optional. |
| `oneOrMore` | Equivalent to `+` - this marks the input as repeatable, any number of times but at least once. |
| `exactly` | This escapes a string input to match it exactly. |
Expand Down
10 changes: 8 additions & 2 deletions src/core/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export const wordChar = createInput('\\w')
export const wordBoundary = createInput('\\b')
export const digit = createInput('\\d')
export const whitespace = createInput('\\s')
export const letter = createInput('[a-zA-Z]')
export const letter = Object.assign(createInput('[a-zA-Z]'), {
lowercase: createInput('[a-z]'),
uppercase: createInput('[A-Z]'),
})
export const tab = createInput('\\t')
export const linefeed = createInput('\\n')
export const carriageReturn = createInput('\\r')
Expand All @@ -47,7 +50,10 @@ export const not = {
wordBoundary: createInput('\\B'),
digit: createInput('\\D'),
whitespace: createInput('\\S'),
letter: createInput('[^a-zA-Z]'),
letter: Object.assign(createInput('[^a-zA-Z]'), {
lowercase: createInput('[^a-z]'),
uppercase: createInput('[^A-Z]'),
}),
tab: createInput('[^\\t]'),
linefeed: createInput('[^\\n]'),
carriageReturn: createInput('[^\\r]'),
Expand Down
14 changes: 14 additions & 0 deletions test/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ describe('inputs', () => {
expect(new RegExp(input as any)).toMatchInlineSnapshot('/\\[a-zA-Z\\]/')
expectTypeOf(extractRegExp(input)).toEqualTypeOf<'[a-zA-Z]'>()
})
it('letter.lowercase', () => {
const input = letter.lowercase
expect(new RegExp(input as any)).toMatchInlineSnapshot('/\\[a-z\\]/')
expectTypeOf(extractRegExp(input)).toEqualTypeOf<'[a-z]'>()
})
it('letter.uppercase', () => {
const input = letter.uppercase
expect(new RegExp(input as any)).toMatchInlineSnapshot('/\\[A-Z\\]/')
expectTypeOf(extractRegExp(input)).toEqualTypeOf<'[A-Z]'>()
})
it('tab', () => {
const input = tab
expect(new RegExp(input as any)).toMatchInlineSnapshot('/\\\\t/')
Expand All @@ -146,6 +156,10 @@ describe('inputs', () => {
expectTypeOf(extractRegExp(not.whitespace)).toEqualTypeOf<'\\S'>()
expect(not.letter.toString()).toMatchInlineSnapshot('"[^a-zA-Z]"')
expectTypeOf(extractRegExp(not.letter)).toEqualTypeOf<'[^a-zA-Z]'>()
expect(not.letter.lowercase.toString()).toMatchInlineSnapshot('"[^a-z]"')
expectTypeOf(extractRegExp(not.letter.lowercase)).toEqualTypeOf<'[^a-z]'>()
expect(not.letter.uppercase.toString()).toMatchInlineSnapshot('"[^A-Z]"')
expectTypeOf(extractRegExp(not.letter.uppercase)).toEqualTypeOf<'[^A-Z]'>()
expect(not.tab.toString()).toMatchInlineSnapshot('"[^\\\\t]"')
expectTypeOf(extractRegExp(not.tab)).toEqualTypeOf<'[^\\t]'>()
expect(not.linefeed.toString()).toMatchInlineSnapshot('"[^\\\\n]"')
Expand Down