Skip to content

Commit db1d020

Browse files
refactor: raname RegexComponentResult (#44)
1 parent 871002e commit db1d020

File tree

7 files changed

+23
-19
lines changed

7 files changed

+23
-19
lines changed

src/components/anchors.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { EncodeOutput } from '../encoder/types';
2-
import type { RegexEncodable } from '../types';
2+
import type { RegexComponentResult } from '../types';
33

4-
export interface Anchor extends RegexEncodable {
4+
export interface Anchor extends RegexComponentResult {
55
type: 'anchor';
66
symbol: string;
77
}

src/components/capture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { encodeSequence } from '../encoder/encoder';
22
import type { EncodeOutput } from '../encoder/types';
33
import { asNodeArray } from '../utils/nodes';
4-
import type { RegexElement, RegexEncodable, RegexSequence } from '../types';
4+
import type { RegexComponentResult, RegexElement, RegexSequence } from '../types';
55

6-
export interface Capture extends RegexEncodable {
6+
export interface Capture extends RegexComponentResult {
77
type: 'capture';
88
children: RegexElement[];
99
}

src/components/choice-of.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { encodeSequence } from '../encoder/encoder';
22
import type { EncodeOutput } from '../encoder/types';
33
import { asNodeArray } from '../utils/nodes';
4-
import type { RegexElement, RegexEncodable, RegexSequence } from '../types';
4+
import type { RegexComponentResult, RegexElement, RegexSequence } from '../types';
55

6-
export interface ChoiceOf extends RegexEncodable {
6+
export interface ChoiceOf extends RegexComponentResult {
77
type: 'choiceOf';
88
alternatives: RegexElement[][];
99
}

src/components/quantifiers.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { encodeAtom } from '../encoder/encoder';
22
import type { EncodeOutput } from '../encoder/types';
33
import { asNodeArray } from '../utils/nodes';
4-
import type { RegexElement, RegexEncodable, RegexSequence } from '../types';
4+
import type { RegexComponentResult, RegexElement, RegexSequence } from '../types';
55

6-
export interface OneOrMore extends RegexEncodable {
6+
export interface OneOrMore extends RegexComponentResult {
77
type: 'oneOrMore';
88
children: RegexElement[];
99
}
1010

11-
export interface Optionally extends RegexEncodable {
11+
export interface Optionally extends RegexComponentResult {
1212
type: 'optionally';
1313
children: RegexElement[];
1414
}
1515

16-
export interface ZeroOrMore extends RegexEncodable {
16+
export interface ZeroOrMore extends RegexComponentResult {
1717
type: 'zeroOrMore';
1818
children: RegexElement[];
1919
}

src/components/repeat.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { encodeAtom } from '../encoder/encoder';
22
import type { EncodeOutput } from '../encoder/types';
33
import { asNodeArray } from '../utils/nodes';
4-
import type { RegexElement, RegexEncodable, RegexSequence } from '../types';
4+
import type { RegexComponentResult, RegexElement, RegexSequence } from '../types';
55

6-
export interface Repeat extends RegexEncodable {
6+
export interface Repeat extends RegexComponentResult {
77
type: 'repeat';
88
options: RepeatOptions;
99
children: RegexElement[];

src/types.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import type { EncodeOutput } from './encoder/types';
22

33
/**
4-
* Sequence of `RegexElements` that can be encoded into a regular expression.
4+
* Sequence of regex elements that can be encoded into a regular expression.
5+
*
6+
* Typically passed as an array of elements but can be a single element to
7+
* improve readability.
58
*/
69
export type RegexSequence = RegexElement[] | RegexElement;
710

811
/**
9-
* Represents a result of calling a regex component (`RegexEncodable`) or a string to be matched literally.
12+
* Represents a result of calling a regex component or a string to be matched
13+
* literally.
1014
*/
11-
export type RegexElement = RegexEncodable | string;
15+
export type RegexElement = RegexComponentResult | string;
1216

1317
/**
1418
* Represents result of calling a regex componen.
1519
*/
16-
export interface RegexEncodable {
20+
export interface RegexComponentResult {
1721
type: string;
1822
encode(): EncodeOutput;
1923
}

test-utils/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { buildRegex } from '../src/builders';
2-
import type { RegexElement, RegexEncodable } from '../src/types';
2+
import type { RegexComponentResult, RegexElement } from '../src/types';
33

44
export function isRegexElement(node: unknown): node is RegexElement {
5-
return typeof node === 'string' || isRegexEncodable(node);
5+
return typeof node === 'string' || isRegexComponentResult(node);
66
}
77

8-
export function isRegexEncodable(element: unknown): element is RegexEncodable {
8+
export function isRegexComponentResult(element: unknown): element is RegexComponentResult {
99
return (
1010
typeof element === 'object' &&
1111
element !== null &&

0 commit comments

Comments
 (0)