Skip to content

Commit f9af296

Browse files
committed
refactor: rename notWord, etc
1 parent 39f4cda commit f9af296

File tree

5 files changed

+72
-54
lines changed

5 files changed

+72
-54
lines changed

src/constructs/__tests__/anchors.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
buildRegExp,
33
digit,
44
endOfString,
5-
notWhitespace,
5+
nonWhitespace,
66
notWordBoundary,
77
oneOrMore,
88
startOfString,
@@ -35,11 +35,11 @@ test('`wordBoundary` pattern', () => {
3535

3636
test('`wordBoundary` matching', () => {
3737
expect(
38-
buildRegExp([wordBoundary, 'a', zeroOrMore(notWhitespace)], { global: true }),
38+
buildRegExp([wordBoundary, 'a', zeroOrMore(nonWhitespace)], { global: true }),
3939
).toMatchGroups('a ba ab aa', ['a', 'ab', 'aa']);
4040

4141
expect(
42-
buildRegExp([zeroOrMore(notWhitespace), 'a', wordBoundary], { global: true }),
42+
buildRegExp([zeroOrMore(nonWhitespace), 'a', wordBoundary], { global: true }),
4343
).toMatchGroups('a ba ab aa', ['a', 'ba', 'aa']);
4444
});
4545

src/constructs/__tests__/character-class.test.ts

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
charRange,
77
digit,
88
inverted,
9-
notDigit,
10-
notWhitespace,
11-
notWord,
9+
nonDigit,
10+
nonWhitespace,
11+
nonWord,
1212
oneOrMore,
1313
optional,
1414
whitespace,
@@ -30,12 +30,12 @@ test('`digit` character class', () => {
3030
expect(digit).not.toMatchString('A');
3131
});
3232

33-
test('`notDigit` character class', () => {
34-
expect(notDigit).toEqualRegex(/\D/);
35-
expect(['x', notDigit]).toEqualRegex(/x\D/);
36-
expect(['x', notDigit, 'x']).toEqualRegex(/x\Dx/);
37-
expect(notDigit).not.toMatchString('1');
38-
expect(notDigit).toMatchString('A');
33+
test('`nonDigit` character class', () => {
34+
expect(nonDigit).toEqualRegex(/\D/);
35+
expect(['x', nonDigit]).toEqualRegex(/x\D/);
36+
expect(['x', nonDigit, 'x']).toEqualRegex(/x\Dx/);
37+
expect(nonDigit).not.toMatchString('1');
38+
expect(nonDigit).toMatchString('A');
3939
});
4040

4141
test('`word` character class', () => {
@@ -47,13 +47,13 @@ test('`word` character class', () => {
4747
expect(word).not.toMatchString('$');
4848
});
4949

50-
test('`notWord` character class', () => {
51-
expect(notWord).toEqualRegex(/\W/);
52-
expect(['x', notWord]).toEqualRegex(/x\W/);
53-
expect(['x', notWord, 'x']).toEqualRegex(/x\Wx/);
54-
expect(notWord).not.toMatchString('A');
55-
expect(notWord).not.toMatchString('1');
56-
expect(notWord).toMatchString('$');
50+
test('`nonWord` character class', () => {
51+
expect(nonWord).toEqualRegex(/\W/);
52+
expect(['x', nonWord]).toEqualRegex(/x\W/);
53+
expect(['x', nonWord, 'x']).toEqualRegex(/x\Wx/);
54+
expect(nonWord).not.toMatchString('A');
55+
expect(nonWord).not.toMatchString('1');
56+
expect(nonWord).toMatchString('$');
5757
});
5858

5959
test('`whitespace` character class', () => {
@@ -66,14 +66,14 @@ test('`whitespace` character class', () => {
6666
expect(whitespace).not.toMatchString('1');
6767
});
6868

69-
test('`notWhitespace` character class', () => {
70-
expect(notWhitespace).toEqualRegex(/\S/);
71-
expect(['x', notWhitespace]).toEqualRegex(/x\S/);
72-
expect(['x', notWhitespace, 'x']).toEqualRegex(/x\Sx/);
73-
expect(notWhitespace).not.toMatchString(' ');
74-
expect(notWhitespace).not.toMatchString('\t');
75-
expect(notWhitespace).toMatchString('A');
76-
expect(notWhitespace).toMatchString('1');
69+
test('`nonWhitespace` character class', () => {
70+
expect(nonWhitespace).toEqualRegex(/\S/);
71+
expect(['x', nonWhitespace]).toEqualRegex(/x\S/);
72+
expect(['x', nonWhitespace, 'x']).toEqualRegex(/x\Sx/);
73+
expect(nonWhitespace).not.toMatchString(' ');
74+
expect(nonWhitespace).not.toMatchString('\t');
75+
expect(nonWhitespace).toMatchString('A');
76+
expect(nonWhitespace).toMatchString('1');
7777
});
7878

7979
test('`charClass` base cases', () => {
@@ -173,22 +173,22 @@ test('`encodeCharacterClass` throws on empty text', () => {
173173
});
174174

175175
test('showcase: negated character classes', () => {
176-
expect(notDigit).toEqualRegex(/\D/);
177-
expect(notWord).toEqualRegex(/\W/);
178-
expect(notWhitespace).toEqualRegex(/\S/);
179-
180-
expect(notDigit).toMatchString('A');
181-
expect(notDigit).not.toMatchString('1');
182-
expect(notDigit).toMatchString(' ');
183-
expect(notDigit).toMatchString('#');
184-
185-
expect(notWord).not.toMatchString('A');
186-
expect(notWord).not.toMatchString('1');
187-
expect(notWord).toMatchString(' ');
188-
expect(notWord).toMatchString('#');
189-
190-
expect(notWhitespace).toMatchString('A');
191-
expect(notWhitespace).toMatchString('1');
192-
expect(notWhitespace).not.toMatchString(' ');
193-
expect(notWhitespace).toMatchString('#');
176+
expect(nonDigit).toEqualRegex(/\D/);
177+
expect(nonWord).toEqualRegex(/\W/);
178+
expect(nonWhitespace).toEqualRegex(/\S/);
179+
180+
expect(nonDigit).toMatchString('A');
181+
expect(nonDigit).not.toMatchString('1');
182+
expect(nonDigit).toMatchString(' ');
183+
expect(nonDigit).toMatchString('#');
184+
185+
expect(nonWord).not.toMatchString('A');
186+
expect(nonWord).not.toMatchString('1');
187+
expect(nonWord).toMatchString(' ');
188+
expect(nonWord).toMatchString('#');
189+
190+
expect(nonWhitespace).toMatchString('A');
191+
expect(nonWhitespace).toMatchString('1');
192+
expect(nonWhitespace).not.toMatchString(' ');
193+
expect(nonWhitespace).toMatchString('#');
194194
});

src/constructs/character-class.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const digit: CharacterClass = {
3333
encode: encodeCharacterClass,
3434
};
3535

36-
export const notDigit: CharacterClass = {
36+
export const nonDigit: CharacterClass = {
3737
type: 'characterClass',
3838
chars: ['\\D'],
3939
ranges: [],
@@ -49,7 +49,7 @@ export const word: CharacterClass = {
4949
encode: encodeCharacterClass,
5050
};
5151

52-
export const notWord: CharacterClass = {
52+
export const nonWord: CharacterClass = {
5353
type: 'characterClass',
5454
chars: ['\\W'],
5555
ranges: [],
@@ -65,14 +65,29 @@ export const whitespace: CharacterClass = {
6565
encode: encodeCharacterClass,
6666
};
6767

68-
export const notWhitespace: CharacterClass = {
68+
export const nonWhitespace: CharacterClass = {
6969
type: 'characterClass',
7070
chars: ['\\S'],
7171
ranges: [],
7272
isInverted: false,
7373
encode: encodeCharacterClass,
7474
};
7575

76+
/**
77+
* @deprecated Renamed to `nonDigit`.
78+
*/
79+
export const notDigit = nonDigit;
80+
81+
/**
82+
* @deprecated Renamed to `nonWord`.
83+
*/
84+
export const notWord = nonWord;
85+
86+
/**
87+
* @deprecated Renamed to `nonWhitespace`.
88+
*/
89+
export const notWhitespace = nonWhitespace;
90+
7691
export function charClass(...elements: CharacterClass[]): CharacterClass {
7792
elements.forEach((element) => {
7893
if (element.isInverted) {

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ export {
1111
charRange,
1212
digit,
1313
inverted,
14+
nonDigit,
15+
nonWhitespace,
16+
nonWord,
1417
notDigit,
1518
notWhitespace,
1619
notWord,

website/docs/api/character-classes.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ Character classes are a set of characters that match any one of the characters i
1010
```ts
1111
const any: CharacterClass;
1212
const word: CharacterClass;
13-
const notWord: CharacterClass;
13+
const nonWord: CharacterClass;
1414
const digit: CharacterClass;
15-
const notDigit: CharacterClass;
15+
const nonDigit: CharacterClass;
1616
const whitespace: CharacterClass;
17-
const notWhitespace: CharacterClass;
17+
const nonWhitespace: CharacterClass;
1818
```
1919

2020
- `any` matches any character except newline characters. Regex syntax: `*`.
2121
- `word` matches any word character (letters, digits & underscore). Regex syntax: `\w`.
22-
- `notWord` matches any character **except** word characters (letters, digits & underscore). Regex syntax: `\W`.
22+
- `nonWord` matches any character **except** word characters (letters, digits & underscore). Regex syntax: `\W`.
2323
- `digit` matches any digit. Regex syntax: `\d`.
24-
- `notDigit` matches any character **except** digits. Regex syntax: `\D`.
24+
- `nonDigit` matches any character **except** digits. Regex syntax: `\D`.
2525
- `whitespace` matches any whitespace character (spaces, tabs, line breaks). Regex syntax: `\s`.
26-
- `notWhitespace` matches any character **except** whitespace characters (spaces, tabs, line breaks). Regex syntax: `\S`.
26+
- `nonWhitespace` matches any character **except** whitespace characters (spaces, tabs, line breaks). Regex syntax: `\S`.
2727

2828
### `anyOf()`
2929

0 commit comments

Comments
 (0)