Skip to content

Commit 9ef5cbb

Browse files
docs: proof-read docs (#50)
1 parent 93742a3 commit 9ef5cbb

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ A user-friendly regular expression builder for TypeScript and JavaScript.
66

77
## Goal
88

9-
Regular expressions are a powerful tool for matching simple and complex text patterns, yet they are notorious for their hard-to-parse syntax.
9+
Regular expressions are a powerful tool for matching text patterns, yet they are notorious for their hard-to-parse syntax, especially in the case of more complex patterns.
1010

11-
This library allows users to create regular expressions in a structured way, making them ease to understand.
11+
This library allows users to create regular expressions in a structured way, making them easy to write and review. It provides a domain-specific langauge for defining regular expressions, which are finally turned into JavaScript-native `RegExp` objects for fast execution.
1212

1313
```ts
1414
// Before
@@ -61,8 +61,8 @@ TS Regex Builder allows you to build complex regular expressions using domain-sp
6161

6262
Terminology:
6363
- regex construct (`RegexConstruct`) - common name for all regex constructs like character classes, quantifiers, and anchors.
64-
- regex element (`RegexElement`) - fundamental building block of a regular expression, defined as either a regex construct or a string.
65-
- regex sequence (`RegexSequence`) - a sequence of regex elements forming a regular expression. For developer convenience it also accepts a single element instead of array.
64+
- regex element (`RegexElement`) - a fundamental building block of a regular expression, defined as either a regex construct or a string.
65+
- regex sequence (`RegexSequence`) - a sequence of regex elements forming a regular expression. For developer convenience, it also accepts a single element instead of an array.
6666

6767
Most of the regex constructs accept a regex sequence as their argument.
6868

@@ -87,7 +87,7 @@ const currencyAmount = buildRegExp([
8787
]);
8888
```
8989

90-
Comprehensive API document is available [here](./API.md).
90+
See [API document](./docs/API.md).
9191

9292
### Regex Builders
9393

@@ -129,15 +129,19 @@ Comprehensive API document is available [here](./API.md).
129129

130130
### Anchors
131131

132-
| Anchor | Regex Syntax | Description |
133-
| --------------- | ------------- | ---------------------------------------------------------------- |
134-
| `startOfString` | `^` | Match start of the string (or start of a line in multiline mode) |
135-
| `endOfString` | `$` | Match end of the string (or end of a line in multiline mode) |
132+
| Anchor | Regex Syntax | Description |
133+
| --------------- | ------------- | ------------------------------------------------------------------------ |
134+
| `startOfString` | `^` | Match the start of the string (or the start of a line in multiline mode) |
135+
| `endOfString` | `$` | Match the end of the string (or the end of a line in multiline mode) |
136136

137137
## Examples
138138

139139
See [Examples document](./docs/Examples.md).
140140

141+
## Performance
142+
143+
Regular expressions created with this library are executed at runtime, so you should avoid creating them in a context where they would need to be executed multiple times, e.g., inside loops or functions. We recommend that you create a top-level object for each required regex.
144+
141145
## Contributing
142146

143147
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

docs/API.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### `RegexSequence`
66

7-
The sequence of regex elements forming a regular expression. For developer convenience it also accepts a single element instead of array.
7+
The sequence of regex elements forming a regular expression. For developer convenience, it also accepts a single element instead of an array.
88

99
### `RegexElement`
1010

@@ -14,7 +14,7 @@ Fundamental building blocks of a regular expression, defined as either a regex c
1414

1515
The common type for all regex constructs like character classes, quantifiers, and anchors. You should not need to use this type directly, it is returned by all regex construct functions.
1616

17-
Note: the shape of the `RegexConstruct` is considered private, and may change in a breaking way without a major release. We will focus on maintaining the compatibility of regexes built with
17+
Note: the shape of the `RegexConstruct` is considered private and may change in a breaking way without a major release. We will focus on maintaining the compatibility of regexes built with
1818

1919

2020
## Builder
@@ -33,14 +33,14 @@ function buildRegExp(
3333
): RegExp;
3434
```
3535

36-
The `buildRegExp` is a top-level function responsible for build JavaScript-native `RegExp` object from passed regex sequence.
36+
The `buildRegExp` is a top-level function responsible for building a JavaScript-native `RegExp` object from passed regex sequence.
3737

3838
It optionally accepts a list of regex flags:
3939

40-
- `global` - find all matches in a string, instead of just the first one.
40+
- `global` - find all matches in a string instead of just the first one.
4141
- `ignoreCase` - perform case-insensitive matching.
4242
- `multiline` - treat the start and end of each line in a string as the beginning and end of the string.
43-
- `hasIndices` - provide the start and end indices of each captured group in a match.
43+
- `hasIndices` - provide each captured group's start and end indices in a match.
4444

4545
## Constructs
4646

@@ -56,7 +56,7 @@ function capture(
5656

5757
Regex syntax: `(...)`.
5858

59-
Captures, also known as capturing groups, are used to extract and store parts of the matched string for later use.
59+
Captures, also known as capturing groups, extract and store parts of the matched string for later use.
6060

6161
### `choiceOf()`
6262

@@ -68,7 +68,7 @@ function choiceOf(
6868

6969
Regex syntax: `a|b|c`.
7070

71-
The `choiceOf` (disjunction) construct is used to match one out of several possible sequences. It functions similarly to a logical OR operator in programming. It can match simple string options as well as complex patterns.
71+
The `choiceOf` (disjunction) construct matches one out of several possible sequences. It functions similarly to a logical OR operator in programming. It can match simple string options as well as complex patterns.
7272

7373
Example: `choiceOf("color", "colour")` matches either `color` or `colour` pattern.
7474

@@ -86,7 +86,7 @@ function zeroOrMore(
8686

8787
Regex syntax: `x*`;
8888

89-
The `zeroOrMore` quantifier matches zero or more occurrences of given pattern, allowing a flexible number of repetitions of that element.
89+
The `zeroOrMore` quantifier matches zero or more occurrences of a given pattern, allowing a flexible number of repetitions of that element.
9090

9191
### `oneOrMore()`
9292

@@ -98,7 +98,7 @@ function oneOrMore(
9898

9999
Regex syntax: `x+`;
100100

101-
The `oneOrMore` quantifier matches one or more occurrences of given pattern, allowing a flexible number of repetitions of that element.
101+
The `oneOrMore` quantifier matches one or more occurrences of a given pattern, allowing a flexible number of repetitions of that element.
102102

103103
### `optional()`
104104

@@ -110,7 +110,7 @@ function optional(
110110

111111
Regex syntax: `x?`;
112112

113-
The `optional` quantifier matches zero or one occurrence of given pattern, making it optional.
113+
The `optional` quantifier matches zero or one occurrence of a given pattern, making it optional.
114114

115115
### `repeat()`
116116

@@ -123,13 +123,13 @@ function repeat(
123123

124124
Regex syntax: `x{n}`, `x{min,}`, `x{min, max}`.
125125

126-
The `repeat` quantifier in regex matches either exactly `count` times or between `min` and `max` times. If only `min` is provided it matches at least `min` times.
126+
The `repeat` quantifier in regex matches either exactly `count` times or between `min` and `max` times. If only `min` is provided, it matches at least `min` times.
127127

128128
## Character classes
129129

130130
Character classes are a set of characters that match any one of the characters in the set.
131131

132-
### Common character classess
132+
### Common character classes
133133

134134
```ts
135135
const any: CharacterClass;
@@ -153,7 +153,7 @@ function anyOf(
153153

154154
Regex syntax: `[abc]`.
155155

156-
The `anyOf` class matches any character present in the `character` string.
156+
The `anyOf` class matches any character in the `character` string.
157157

158158
Example: `anyOf('aeiou')` will match either `a`, `e`, `i` `o` or `u` characters.
159159

@@ -168,7 +168,7 @@ function charRange(
168168

169169
Regex syntax: `[a-z]`.
170170

171-
The `charRange` class matches any character present in the range from `start` to `end` (inclusive).
171+
The `charRange` class matches any characters in the range from `start` to `end` (inclusive).
172172

173173
Examples:
174174

@@ -191,7 +191,7 @@ The `charClass` construct creates a new character class that includes all passed
191191
Examples:
192192

193193
- `charClass(charRange('a', 'f'), digit)` will match all lowercase hex digits (`0` to `9` and `a` to `f`).
194-
- `charClass(charRange('a', 'z'), digit, anyOf("._-"))` will match any digit, lowercase latin lettet from `a` to `z`, and either of `.`, `_`, and `-` characters.
194+
- `charClass(charRange('a', 'z'), digit, anyOf("._-"))` will match any digit, lowercase Latin letter from `a` to `z`, and either of `.`, `_`, and `-` characters.
195195

196196
### `inverted()`
197197

@@ -203,7 +203,7 @@ function inverted(
203203

204204
Regex syntax: `[^...]`.
205205

206-
The `inverted` construct creates a new character class that matches any character that is not present in the passed character class.
206+
The `inverted` construct creates a new character class that matches any character not present in the passed character class.
207207

208208
Examples:
209209

@@ -212,7 +212,7 @@ Examples:
212212

213213
## Anchors
214214

215-
Anchors are special characters or sequences that specify positions in the input string, rather than matching specific characters.
215+
Anchors are special characters or sequences that specify positions in the input string rather than matching specific characters.
216216

217217
### Start and end of string
218218

docs/Examples.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ See tests: [example-hashtags.ts](../src/__tests__/example-hashtags.ts).
2222

2323
## Hex color validation
2424

25-
This regex validate whether given string is a valid hex color, with 6 or 3 hex digits.
25+
This regex validates whether a given string is a valid hex color, with 6 or 3 hex digits.
2626

2727
```ts
2828
const hexDigit = charClass(digit, charRange('a', 'f'));
@@ -47,7 +47,7 @@ See tests: [example-hex-color.ts](../src/__tests__/example-hex-color.ts).
4747

4848
## Simple URL validation
4949

50-
This regex validates (in simplified way) whether given string is a URL.
50+
This regex validates (in a simplified way) whether a given string is a URL.
5151

5252
```ts
5353
const protocol = [choiceOf('http', 'https'), '://'];
@@ -75,7 +75,7 @@ See tests: [example-url.ts](../src/__tests__/example-url.ts).
7575

7676
## Email address validation
7777

78-
This regex validates whether given string is a properly formatted email address.
78+
This regex validates whether a given string is a properly formatted email address.
7979

8080
```ts
8181
const hostnameChars = charClass(charRange('a', 'z'), digit, anyOf('-.'));
@@ -103,7 +103,7 @@ See tests: [example-email.ts](../src/__tests__/example-email.ts).
103103

104104
## JavaScript number validation
105105

106-
This regex validates if given string is a valid JavaScript number.
106+
This regex validates if a given string is a valid JavaScript number.
107107

108108

109109
```ts

0 commit comments

Comments
 (0)