Skip to content

Commit 14512bd

Browse files
committed
Lean into package name regex by renaming the lib (and tag make) as regex (#1)
1 parent edffdc0 commit 14512bd

18 files changed

+456
-445
lines changed

README.md

+82-77
Large diffs are not rendered by default.

dist/regex.min.js

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/regex.min.js.map

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/atomic-groups-spec.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
describe('atomic groups', () => {
22
it('should not remember backtracking positions within atomic groups', () => {
3-
expect('abcc').toMatch(Regex.make`a(?>bc|b)c`);
4-
expect('abc').not.toMatch(Regex.make`a(?>bc|b)c`);
3+
expect('abcc').toMatch(regex`a(?>bc|b)c`);
4+
expect('abc').not.toMatch(regex`a(?>bc|b)c`);
55
});
66

77
it('should work when named capturing groups present', () => {
8-
expect('abcc').toMatch(Regex.make`(?<n>)a(?>bc|b)c`);
9-
expect('abc').not.toMatch(Regex.make`(?<n>)a(?>bc|b)c`);
8+
expect('abcc').toMatch(regex`(?<n>)a(?>bc|b)c`);
9+
expect('abc').not.toMatch(regex`(?<n>)a(?>bc|b)c`);
1010
});
1111

1212
it('should work when unnamed capturing groups present', () => {
13-
expect('abcc').toMatch(Regex.make({__flagN: false})`()a(?>bc|b)c`);
14-
expect('abc').not.toMatch(Regex.make({__flagN: false})`()a(?>bc|b)c`);
13+
expect('abcc').toMatch(regex({__flagN: false})`()a(?>bc|b)c`);
14+
expect('abc').not.toMatch(regex({__flagN: false})`()a(?>bc|b)c`);
1515
});
1616

1717
it('should work when capturing groups present via interpolation', () => {
18-
expect('abcc').toMatch(Regex.make`${/()/}a(?>bc|b)c`);
19-
expect('abc').not.toMatch(Regex.make`${/()/}a(?>bc|b)c`);
18+
expect('abcc').toMatch(regex`${/()/}a(?>bc|b)c`);
19+
expect('abc').not.toMatch(regex`${/()/}a(?>bc|b)c`);
2020
});
2121

2222
it('should allow nested atomic groups', () => {
23-
expect('integerrr+').toMatch(Regex.make`\b(?>int(?>eger+)?|insert)\b(?>.)`);
24-
expect('integerrr+').not.toMatch(Regex.make`\b(?>int(?>eger+)??|insert)\b(?>.)`);
23+
expect('integerrr+').toMatch(regex`\b(?>int(?>eger+)?|insert)\b(?>.)`);
24+
expect('integerrr+').not.toMatch(regex`\b(?>int(?>eger+)??|insert)\b(?>.)`);
2525
});
2626

2727
it('should allow quantifying atomic groups', () => {
28-
expect('one two').toMatch(Regex.make`^(?>\w+\s?)+$`);
28+
expect('one two').toMatch(regex`^(?>\w+\s?)+$`);
2929
});
3030

3131
it('should not allow numbered backreferences in interpolated regexes when using atomic groups', () => {
32-
expect(() => Regex.make`(?>)${/()\1/}`).toThrow();
33-
expect(() => Regex.make`${/()\1/}(?>)`).toThrow();
34-
expect(() => Regex.make`(?>${/()\1/})`).toThrow();
35-
expect(() => Regex.make`(?>${/()/})`).not.toThrow();
36-
expect(() => Regex.make`(?>${/(?<n>)\k<n>/})`).not.toThrow();
32+
expect(() => regex`(?>)${/()\1/}`).toThrow();
33+
expect(() => regex`${/()\1/}(?>)`).toThrow();
34+
expect(() => regex`(?>${/()\1/})`).toThrow();
35+
expect(() => regex`(?>${/()/})`).not.toThrow();
36+
expect(() => regex`(?>${/(?<n>)\k<n>/})`).not.toThrow();
3737
});
3838
});

spec/flag-n-spec.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
describe('flag n', () => {
22
it('should cause () to be noncapturing', function() {
3-
expect(Regex.make`()`.exec('').length).toBe(1);
3+
expect(regex`()`.exec('').length).toBe(1);
44
});
55

66
it('should continue to treat (?:) as noncapturing', function() {
7-
expect(Regex.make`(?:)`.exec('').length).toBe(1);
7+
expect(regex`(?:)`.exec('').length).toBe(1);
88
});
99

1010
it('should continue to allow (?<name>) for capturing', function() {
11-
expect(Regex.make`(?<name>)`.exec('').length).toBe(2);
12-
expect(Regex.make`(?<name>)()`.exec('').length).toBe(2);
11+
expect(regex`(?<name>)`.exec('').length).toBe(2);
12+
expect(regex`(?<name>)()`.exec('').length).toBe(2);
1313
});
1414

1515
it('should not allow numbered backreferences', function() {
16-
expect(() => Regex.make`()\1`).toThrow();
16+
expect(() => regex`()\1`).toThrow();
1717
});
1818

1919
it('should not allow numbered backreferences within partials', function() {
20-
expect(() => Regex.make`${Regex.partial`()\1`}`).toThrow();
21-
expect(() => Regex.make`()${Regex.partial`\1`}`).toThrow();
22-
expect(() => Regex.make`${Regex.partial`()`}\1`).toThrow();
20+
expect(() => regex`${partial`()\1`}`).toThrow();
21+
expect(() => regex`()${partial`\1`}`).toThrow();
22+
expect(() => regex`${partial`()`}\1`).toThrow();
2323
});
2424

2525
it('should not apply to interpolated regexes', () => {
26-
expect('aa').toMatch(Regex.make`${/(a)\1/}`);
26+
expect('aa').toMatch(regex`${/(a)\1/}`);
2727
});
2828

2929
it('should set flag n status with an experimental option', () => {
30-
expect(() => Regex.make({__flagN: true})`()\1`).toThrow();
31-
expect('aa').toMatch(Regex.make({__flagN: false})`(a)\1`);
30+
expect(() => regex({__flagN: true})`()\1`).toThrow();
31+
expect('aa').toMatch(regex({__flagN: false})`(a)\1`);
3232
});
3333
});

spec/flag-x-spec.js

+44-44
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,38 @@ describe('flag x', () => {
22
describe('in default context', () => {
33
it('should treat whitespace as insignificant', () => {
44
const ws = '\t\n\v\f\r \xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF';
5-
expect('ab').toMatch(Regex.make({raw: [`^a${ws}b$`]}, []));
5+
expect('ab').toMatch(regex({raw: [`^a${ws}b$`]}, []));
66
});
77

88
it('should start line comments with # that continue until the next \\n', () => {
9-
expect('ab').toMatch(Regex.make`^a#comment\nb$`);
9+
expect('ab').toMatch(regex`^a#comment\nb$`);
1010
});
1111

1212
it('should not end line comments with newlines other than \\n', () => {
1313
const newlines = ['\r', '\u2028', '\u2029'];
1414
newlines.forEach(n => {
15-
expect('ab').not.toMatch(Regex.make({raw: [`^a#comment${n}b\n$`]}, []));
15+
expect('ab').not.toMatch(regex({raw: [`^a#comment${n}b\n$`]}, []));
1616
});
1717
});
1818

1919
it('should start line comments with # that continue until the end of the string if there are no following newlines', () => {
20-
expect('ac').toMatch(Regex.make`^a#comment b$`);
20+
expect('ac').toMatch(regex`^a#comment b$`);
2121
});
2222

2323
it('should allow mixing whitespace and line comments', function() {
24-
expect('ab').toMatch(Regex.make({raw: ['\f^ a \t\n ##comment\n #\nb $ # ignored']}, []));
24+
expect('ab').toMatch(regex({raw: ['\f^ a \t\n ##comment\n #\nb $ # ignored']}, []));
2525
});
2626

2727
it('should apply a quantifier following whitespace or line comments to the preceding token', function() {
28-
expect('aaa').toMatch(Regex.make`^a +$`);
29-
expect('aaa').toMatch(Regex.make({raw: ['^a#comment\n+$']}, []));
30-
expect('aaa').toMatch(Regex.make({raw: ['^a #comment\n +$']}, []));
28+
expect('aaa').toMatch(regex`^a +$`);
29+
expect('aaa').toMatch(regex({raw: ['^a#comment\n+$']}, []));
30+
expect('aaa').toMatch(regex({raw: ['^a #comment\n +$']}, []));
3131
});
3232

3333
it('should not let the token following whitespace or line comments modify the preceding token', () => {
34-
expect('\u{0}0').toMatch(Regex.make`\0 0`);
35-
expect('\u{0}1').toMatch(Regex.make`\0 1`);
36-
expect('\u{0}1').toMatch(Regex.make({raw: ['\0#\n1']}, []));
34+
expect('\u{0}0').toMatch(regex`\0 0`);
35+
expect('\u{0}1').toMatch(regex`\0 1`);
36+
expect('\u{0}1').toMatch(regex({raw: ['\0#\n1']}, []));
3737
});
3838

3939
it('should preserve the error status of incomplete tokens separated from their completing chars by whitespace', () => {
@@ -47,47 +47,47 @@ describe('flag x', () => {
4747
'\\x0 0',
4848
];
4949
values.forEach(v => {
50-
expect(() => Regex.make({raw: [v]}, [])).withContext(v).toThrow();
50+
expect(() => regex({raw: [v]}, [])).withContext(v).toThrow();
5151
});
5252
});
5353

5454
it('should allow escaping whitespace to make it significant', () => {
55-
expect(' ').toMatch(Regex.make`\ `);
56-
expect(' ').toMatch(Regex.make` \ \ `);
55+
expect(' ').toMatch(regex`\ `);
56+
expect(' ').toMatch(regex` \ \ `);
5757
});
5858

5959
it('should allow escaping # to make it significant', () => {
60-
expect('#').toMatch(Regex.make`\#`);
61-
expect('##').toMatch(Regex.make` \# \# `);
60+
expect('#').toMatch(regex`\#`);
61+
expect('##').toMatch(regex` \# \# `);
6262
});
6363
});
6464

6565
describe('in character class context', () => {
6666
it('should treat space and tab characters as insignificant', () => {
67-
expect(' ').not.toMatch(Regex.make`[ a]`);
68-
expect('\t').not.toMatch(Regex.make({raw: ['[\ta]']}, []));
67+
expect(' ').not.toMatch(regex`[ a]`);
68+
expect('\t').not.toMatch(regex({raw: ['[\ta]']}, []));
6969
});
7070

7171
it('should not treat whitespace characters apart from space and tab as insignificant', () => {
72-
expect('\n').toMatch(Regex.make({raw: ['[\na]']}, []));
73-
expect('\xA0').toMatch(Regex.make({raw: ['[\xA0a]']}, []));
74-
expect('\u2028').toMatch(Regex.make({raw: ['[\u2028a]']}, []));
72+
expect('\n').toMatch(regex({raw: ['[\na]']}, []));
73+
expect('\xA0').toMatch(regex({raw: ['[\xA0a]']}, []));
74+
expect('\u2028').toMatch(regex({raw: ['[\u2028a]']}, []));
7575
});
7676

7777
it('should not start comments with #', () => {
78-
expect('#').toMatch(Regex.make`[#a]`);
78+
expect('#').toMatch(regex`[#a]`);
7979
});
8080

8181
it ('should not let a leading ^ following whitespace change the character class type', () => {
82-
expect('^').toMatch(Regex.make`[ ^]`);
83-
expect('_').not.toMatch(Regex.make`[ ^]`);
84-
expect('^').toMatch(Regex.make`[ ^a]`);
85-
expect('_').not.toMatch(Regex.make`[ ^a]`);
82+
expect('^').toMatch(regex`[ ^]`);
83+
expect('_').not.toMatch(regex`[ ^]`);
84+
expect('^').toMatch(regex`[ ^a]`);
85+
expect('_').not.toMatch(regex`[ ^a]`);
8686
});
8787

8888
it('should not let the token following whitespace modify the preceding token', () => {
89-
expect('0').toMatch(Regex.make`[\0 0]`);
90-
expect('1').toMatch(Regex.make`[\0 1]`);
89+
expect('0').toMatch(regex`[\0 0]`);
90+
expect('1').toMatch(regex`[\0 1]`);
9191
});
9292

9393
it('should preserve the error status of incomplete tokens separated from their completing chars by whitespace', () => {
@@ -101,7 +101,7 @@ describe('flag x', () => {
101101
'[\\x0 0]',
102102
];
103103
values.forEach(v => {
104-
expect(() => Regex.make({raw: [v]}, [])).withContext(v).toThrow();
104+
expect(() => regex({raw: [v]}, [])).withContext(v).toThrow();
105105
});
106106
});
107107

@@ -121,17 +121,17 @@ describe('flag x', () => {
121121
'[a - - b]',
122122
];
123123
values.forEach(v => {
124-
expect(() => Regex.make({raw: [v]}, [])).withContext(v).toThrow();
124+
expect(() => regex({raw: [v]}, [])).withContext(v).toThrow();
125125
});
126126
});
127127

128128
it('should allow set operators to be offset by whitespace', () => {
129-
expect('a').toMatch(Regex.make`[\w -- _]`);
130-
expect('a').toMatch(Regex.make`[\w-- _]`);
131-
expect('a').toMatch(Regex.make`[\w --_]`);
132-
expect('a').toMatch(Regex.make`[\w && [a-z]]`);
133-
expect('a').toMatch(Regex.make`[\w&& [a-z]]`);
134-
expect('a').toMatch(Regex.make`[\w &&[a-z]]`);
129+
expect('a').toMatch(regex`[\w -- _]`);
130+
expect('a').toMatch(regex`[\w-- _]`);
131+
expect('a').toMatch(regex`[\w --_]`);
132+
expect('a').toMatch(regex`[\w && [a-z]]`);
133+
expect('a').toMatch(regex`[\w&& [a-z]]`);
134+
expect('a').toMatch(regex`[\w &&[a-z]]`);
135135
});
136136

137137
it('should match (as a literal character) a lone double-punctuator character separated from its partner by whitespace', () => {
@@ -157,21 +157,21 @@ describe('flag x', () => {
157157
'~',
158158
];
159159
doublePunctuatorChars.forEach(c => {
160-
expect(c).withContext(`[a${c} ${c}b]`).toMatch(Regex.make({raw: [`[a${c} ${c}b]`]}, []));
161-
expect(c).withContext(`[a${c} ${c} b]`).toMatch(Regex.make({raw: [`[a${c} ${c} b]`]}, []));
162-
expect(c).withContext(`[a ${c} ${c}b]`).toMatch(Regex.make({raw: [`[a ${c} ${c}b]`]}, []));
163-
expect(c).withContext(`[a ${c} ${c} b]`).toMatch(Regex.make({raw: [`[a ${c} ${c} b]`]}, []));
160+
expect(c).withContext(`[a${c} ${c}b]`).toMatch(regex({raw: [`[a${c} ${c}b]`]}, []));
161+
expect(c).withContext(`[a${c} ${c} b]`).toMatch(regex({raw: [`[a${c} ${c} b]`]}, []));
162+
expect(c).withContext(`[a ${c} ${c}b]`).toMatch(regex({raw: [`[a ${c} ${c}b]`]}, []));
163+
expect(c).withContext(`[a ${c} ${c} b]`).toMatch(regex({raw: [`[a ${c} ${c} b]`]}, []));
164164
});
165165
});
166166

167167
it('should allow escaping whitespace to make it significant', () => {
168-
expect(' ').toMatch(Regex.make`[ \ ]`);
169-
expect(' ').toMatch(Regex.make`[\q{ \ }]`);
168+
expect(' ').toMatch(regex`[ \ ]`);
169+
expect(' ').toMatch(regex`[\q{ \ }]`);
170170
});
171171
});
172172

173173
it('should set flag x status with an experimental option', () => {
174-
expect('a b').not.toMatch(Regex.make({__flagX: true})`a b`);
175-
expect('a b').toMatch(Regex.make({__flagX: false})`a b`);
174+
expect('a b').not.toMatch(regex({__flagX: true})`a b`);
175+
expect('a b').toMatch(regex({__flagX: false})`a b`);
176176
});
177177
});

spec/helpers/browsers.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (globalThis.Regex) {
2+
Object.assign(globalThis, {...Regex});
3+
}

spec/helpers/global.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import Regex from '../../src/index.js';
1+
import {regex, partial} from '../../src/index.js';
22

3-
globalThis.Regex = Regex;
3+
Object.assign(globalThis, {regex, partial});

spec/index.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
</script>
1616
<script src="https://cdn.jsdelivr.net/gh/jasmine/[email protected]/lib/jasmine-core/boot1.js"></script>
1717

18-
<!-- Lib -->
18+
<!-- Library -->
1919
<script src="../dist/regex.min.js"></script>
2020

21+
<!-- Helpers -->
22+
<script src="./helpers/browsers.js"></script>
23+
2124
<!-- Specs -->
2225
<script src="./make-spec.js"></script>
2326
<script src="./partial-spec.js"></script>

0 commit comments

Comments
 (0)