Skip to content

Commit 0ac8420

Browse files
committed
refactor: rename reference to ref
1 parent 8ff0632 commit 0ac8420

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

src/__tests__/example-html-tags.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import {
66
charRange,
77
digit,
88
oneOrMore,
9-
reference,
9+
ref,
1010
zeroOrMore,
1111
} from '..';
1212

1313
test('example: html tag matching', () => {
1414
const tagName = oneOrMore(charClass(charRange('a', 'z'), digit));
1515
const tagContent = zeroOrMore(any, { greedy: false });
1616

17-
const tagRef = reference('tag');
17+
const tagRef = ref('tag');
1818
const tagMatcher = buildRegExp(
1919
[
2020
'<',

src/constructs/__tests__/capture.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
digit,
77
inverted,
88
oneOrMore,
9-
reference,
9+
ref,
1010
word,
1111
wordBoundary,
1212
} from '../..';
@@ -50,21 +50,21 @@ test('named `capture` matching', () => {
5050
});
5151

5252
// Should have `ref0` as name.
53-
const firstRef = reference();
53+
const firstRef = ref();
5454

5555
test('`reference` pattern', () => {
5656
expect([firstRef]).toEqualRegex(/\k<ref0>/);
57-
expect([reference('xyz')]).toEqualRegex(/\k<xyz>/);
57+
expect([ref('xyz')]).toEqualRegex(/\k<xyz>/);
5858
expect([capture(any, { name: firstRef }), ' ', firstRef]).toEqualRegex('(?<ref0>.) \\k<ref0>');
5959

60-
const otherRef = reference('r123');
60+
const otherRef = ref('r123');
6161
expect(['xx', capture(any, { name: otherRef }), ' ', otherRef, 'xx']).toEqualRegex(
6262
'xx(?<r123>.) \\k<r123>xx',
6363
);
6464
});
6565

6666
test('`reference` matching basic case', () => {
67-
const someRef = reference();
67+
const someRef = ref();
6868
expect([capture(word, { name: someRef }), someRef]).toMatchString('aa');
6969
expect([capture(digit, { name: someRef }), someRef]).toMatchString('11');
7070

@@ -75,7 +75,7 @@ test('`reference` matching basic case', () => {
7575
});
7676

7777
test('`reference` matching HTML attributes', () => {
78-
const quoteRef = reference('quote');
78+
const quoteRef = ref('quote');
7979
const quote = anyOf('"\'');
8080
const htmlAttributeRegex = buildRegExp([
8181
wordBoundary,

src/constructs/capture.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface Capture extends RegexConstruct {
1111

1212
export type CaptureOptions = {
1313
/**
14-
* Name to be given to the capturing group can either by a string or {@link reference} instance.
14+
* Name to be given to the capturing group can either by a string or {@link ref} instance.
1515
*/
1616
name: string | Reference;
1717
};
@@ -24,7 +24,7 @@ export interface Reference extends RegexConstruct {
2424
/**
2525
* Creates a capturing group which allows the matched pattern to be available:
2626
* - in the match results (`String.match`, `String.matchAll`, or `RegExp.exec`)
27-
* - in the regex itself, through {@link reference}
27+
* - in the regex itself, through {@link ref}
2828
*/
2929
export function capture(sequence: RegexSequence, options?: CaptureOptions): Capture {
3030
return {
@@ -44,7 +44,7 @@ let counter = 0;
4444
*
4545
* @param name - Name to be given to the capturing group which receives this reference. If not provided, a unique name will be generated.
4646
*/
47-
export function reference(name?: string): Reference {
47+
export function ref(name?: string): Reference {
4848
return {
4949
type: 'reference',
5050
name: name ?? `ref${counter++}`,

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export {
1515
startOfString,
1616
wordBoundary,
1717
} from './constructs/anchors';
18-
export { capture, reference } from './constructs/capture';
18+
export { capture, ref } from './constructs/capture';
1919
export {
2020
any,
2121
anyOf,

website/docs/api/captures.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ TS Regex Builder does not have a construct for non-capturing groups. Such groups
3535

3636
:::
3737

38-
### `reference()`
38+
### `ref()`
3939

4040
```ts
41-
function reference(
41+
function ref(
4242
name?: string;
4343
): Reference;
4444
```
@@ -53,13 +53,13 @@ Usage with `capture()`:
5353

5454
```ts
5555
// Define reference with name "some".
56-
const someRef = reference('some');
56+
const someRef = ref('some');
5757

5858
const regex = buildRegExp([
5959
// Create a named capture using name from `someRef`.
60-
capture(..., { name: someRef}),
60+
capture(..., { name: someRef }),
6161
// ... some other elements ...
62-
// Match the same text as captured in capture using `someRef`.
62+
// Match the same text as captured in a `capture` using `someRef`.
6363
someRef,
6464
])
6565
```

0 commit comments

Comments
 (0)