rregex 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -2
- package/babel.config.js +0 -7
- package/jest.transform.js +0 -3
- package/test/rregex.test.ts +0 -235
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rregex",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Rust Regex binding for Javascript",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "./lib/commonjs.js",
|
|
@@ -30,7 +30,19 @@
|
|
|
30
30
|
"release": {
|
|
31
31
|
"ci": false,
|
|
32
32
|
"branches": [
|
|
33
|
-
|
|
33
|
+
{
|
|
34
|
+
"name": "1.0.x",
|
|
35
|
+
"range": "1.0.x",
|
|
36
|
+
"channel": "1.0.x"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "1.1.x",
|
|
40
|
+
"range": "1.1.x",
|
|
41
|
+
"channel": "1.1.x"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "master"
|
|
45
|
+
}
|
|
34
46
|
]
|
|
35
47
|
},
|
|
36
48
|
"repository": {
|
package/babel.config.js
DELETED
package/jest.transform.js
DELETED
package/test/rregex.test.ts
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { RRegex, RRegexSet } from '../lib/commonjs'
|
|
2
|
-
|
|
3
|
-
describe(`RRegex`, () => {
|
|
4
|
-
test(`toString`, () => {
|
|
5
|
-
expect(new RRegex('a').toString()).toBe('a')
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
test(`isMatch`, () => {
|
|
9
|
-
const regex = new RRegex('a')
|
|
10
|
-
expect(regex.isMatch('abc')).toBe(true)
|
|
11
|
-
expect(regex.isMatch('def')).toBe(false)
|
|
12
|
-
|
|
13
|
-
const text = 'I categorically deny having triskaidekaphobia.';
|
|
14
|
-
const re = new RRegex('\\b\\w{13}\\b')
|
|
15
|
-
expect(re.isMatch(text)).toEqual(true);
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test(`isMatchAt`, () => {
|
|
19
|
-
const regex = new RRegex('a')
|
|
20
|
-
expect(regex.isMatchAt('ab', 0)).toBe(true)
|
|
21
|
-
expect(regex.isMatchAt('ab', 1)).toBe(false)
|
|
22
|
-
expect(regex.isMatchAt('ab', 1)).toBe(false)
|
|
23
|
-
expect(regex.isMatchAt('ab', 100)).toBe(false)
|
|
24
|
-
expect(regex.isMatchAt('aba', 0)).toBe(true)
|
|
25
|
-
expect(regex.isMatchAt('aba', 1)).toBe(true)
|
|
26
|
-
expect(regex.isMatchAt('aba', 2)).toBe(true)
|
|
27
|
-
expect(regex.isMatchAt('aba', 3)).toBe(false)
|
|
28
|
-
expect(regex.isMatchAt('aba', 100)).toBe(false)
|
|
29
|
-
expect(regex.isMatchAt('def', 0)).toBe(false)
|
|
30
|
-
|
|
31
|
-
const text = 'I categorically deny having triskaidekaphobia.'
|
|
32
|
-
const re = new RRegex('\\b\\w{13}\\b')
|
|
33
|
-
expect(re.isMatchAt(text, 1)).toBe(true)
|
|
34
|
-
expect(re.isMatchAt(text, 5)).toBe(false)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
test(`find`, () => {
|
|
38
|
-
const regex = new RRegex('a')
|
|
39
|
-
expect(regex.find('abc')).toEqual({ value: 'a', start: 0, end: 1 })
|
|
40
|
-
expect(regex.find('def')).toBeUndefined()
|
|
41
|
-
|
|
42
|
-
const text = 'I categorically deny having triskaidekaphobia.'
|
|
43
|
-
const re = new RRegex('\\b\\w{13}\\b')
|
|
44
|
-
expect(re.find(text)).toEqual({
|
|
45
|
-
value: 'categorically',
|
|
46
|
-
start: 2,
|
|
47
|
-
end: 15,
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
test(`findAt`, () => {
|
|
52
|
-
const regex = new RRegex('a')
|
|
53
|
-
expect(regex.find('abc')).toEqual({ value: 'a', start: 0, end: 1 })
|
|
54
|
-
expect(regex.findAt('abc', 1)).toBeUndefined()
|
|
55
|
-
expect(regex.findAt('abc', 100)).toBeUndefined()
|
|
56
|
-
expect(regex.find('def')).toBeUndefined()
|
|
57
|
-
|
|
58
|
-
const text = 'I categorically deny having triskaidekaphobia.'
|
|
59
|
-
const re = new RRegex('\\b\\w{13}\\b')
|
|
60
|
-
expect(re.findAt(text, 1)).toEqual({
|
|
61
|
-
value: 'categorically',
|
|
62
|
-
start: 2,
|
|
63
|
-
end: 15,
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
expect(re.findAt(text, 5)).toEqual(undefined)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
test(`findAll`, () => {
|
|
70
|
-
const regex = new RRegex('a')
|
|
71
|
-
expect(regex.findAll('abcabcabc')).toEqual([
|
|
72
|
-
{ value: 'a', start: 0, end: 1 },
|
|
73
|
-
{ value: 'a', start: 3, end: 4 },
|
|
74
|
-
{ value: 'a', start: 6, end: 7 },
|
|
75
|
-
])
|
|
76
|
-
expect(regex.findAll('def')).toEqual([])
|
|
77
|
-
|
|
78
|
-
const text = 'Retroactively relinquishing remunerations is reprehensible.'
|
|
79
|
-
const re = new RRegex('\\b\\w{13}\\b')
|
|
80
|
-
expect(re.findAll(text)).toEqual([
|
|
81
|
-
{
|
|
82
|
-
"end": 13,
|
|
83
|
-
"start": 0,
|
|
84
|
-
"value": "Retroactively",
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"end": 27,
|
|
88
|
-
"start": 14,
|
|
89
|
-
"value": "relinquishing",
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
"end": 41,
|
|
93
|
-
"start": 28,
|
|
94
|
-
"value": "remunerations",
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
"end": 58,
|
|
98
|
-
"start": 45,
|
|
99
|
-
"value": "reprehensible",
|
|
100
|
-
},
|
|
101
|
-
])
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
test(`replace`, () => {
|
|
105
|
-
const regex = new RRegex('a')
|
|
106
|
-
expect(regex.replace('abcabcabc', 'z')).toEqual('zbcabcabc')
|
|
107
|
-
expect(regex.replace('defdefdef', 'z')).toEqual('defdefdef')
|
|
108
|
-
|
|
109
|
-
{
|
|
110
|
-
const re = new RRegex('[^01]+')
|
|
111
|
-
expect(re.replace('1078910', '')).toBe('1010')
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
{
|
|
115
|
-
const re = new RRegex('(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)')
|
|
116
|
-
const result = re.replace('Springsteen, Bruce', '$first $last')
|
|
117
|
-
expect(result).toEqual('Bruce Springsteen')
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
{
|
|
121
|
-
const re = new RRegex('(?P<first>\\w+)\\s+(?P<second>\\w+)')
|
|
122
|
-
const result = re.replace("deep fried", "${first}_$second");
|
|
123
|
-
expect(result).toEqual('deep_fried')
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
test(`replaceAll`, () => {
|
|
128
|
-
const regex = new RRegex('a')
|
|
129
|
-
expect(regex.replaceAll('abcabcabc', 'z')).toEqual('zbczbczbc')
|
|
130
|
-
expect(regex.replaceAll('defdefdef', 'z')).toEqual('defdefdef')
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
test(`replacen`, () => {
|
|
134
|
-
const regex = new RRegex('a')
|
|
135
|
-
expect(regex.replacen('abcabcabc', 2, 'z')).toEqual('zbczbcabc')
|
|
136
|
-
expect(regex.replacen('defdefdef', 2, 'z')).toEqual('defdefdef')
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
test(`split`, () => {
|
|
140
|
-
const regex = new RRegex('a')
|
|
141
|
-
expect(regex.split('abcabcabc')).toEqual(['', 'bc', 'bc', 'bc'])
|
|
142
|
-
expect(regex.split('defdefdef')).toEqual(['defdefdef'])
|
|
143
|
-
|
|
144
|
-
const re = new RRegex('[ \\t]+')
|
|
145
|
-
const fields = re.split('a b \t c\td e');
|
|
146
|
-
expect(fields).toEqual(['a', 'b', 'c', 'd', 'e']);
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
test(`splitn`, () => {
|
|
150
|
-
const regex = new RRegex(',')
|
|
151
|
-
expect(regex.splitn('a,b,c', 0)).toEqual([])
|
|
152
|
-
expect(regex.splitn('a,b,c', 1)).toEqual(['a,b,c'])
|
|
153
|
-
expect(regex.splitn('a,b,c', 2)).toEqual(['a', 'b,c'])
|
|
154
|
-
expect(regex.splitn('a,b,c', 3)).toEqual(['a', 'b', 'c'])
|
|
155
|
-
expect(regex.splitn('a,b,c', 4)).toEqual(['a', 'b', 'c', ''])
|
|
156
|
-
expect(regex.splitn('a,b,c', 5)).toEqual(['a', 'b', 'c'])
|
|
157
|
-
expect(regex.splitn('abc', 0)).toEqual([])
|
|
158
|
-
expect(regex.splitn('abc', 1)).toEqual(['abc'])
|
|
159
|
-
expect(regex.splitn('abc', 2)).toEqual(['abc', ''])
|
|
160
|
-
expect(regex.splitn('abc', 3)).toEqual(['abc'])
|
|
161
|
-
|
|
162
|
-
const re = new RRegex('\\W+')
|
|
163
|
-
const fields = re.splitn('Hey! How are you?', 3)
|
|
164
|
-
expect(fields).toEqual(['Hey', 'How', 'are you?'])
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
test(`shortestMatch`, () => {
|
|
168
|
-
const regex = new RRegex('a')
|
|
169
|
-
expect(regex.shortestMatch('abcabcabc')).toEqual(1)
|
|
170
|
-
expect(regex.shortestMatch('bcabcabc')).toEqual(3)
|
|
171
|
-
expect(regex.shortestMatch('cabcabc')).toEqual(2)
|
|
172
|
-
expect(regex.shortestMatch('defdefdef')).toBeUndefined()
|
|
173
|
-
|
|
174
|
-
const text = 'aaaaa'
|
|
175
|
-
const pos = new RRegex('a+')
|
|
176
|
-
expect(pos.shortestMatch(text)).toBe(1)
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
test(`shortestMatchAt`, () => {
|
|
180
|
-
const regex = new RRegex('a')
|
|
181
|
-
expect(regex.shortestMatchAt('abcabca', 0)).toEqual(1)
|
|
182
|
-
expect(regex.shortestMatchAt('abcabca', 1)).toEqual(4)
|
|
183
|
-
expect(regex.shortestMatchAt('abcabca', 2)).toEqual(4)
|
|
184
|
-
expect(regex.shortestMatchAt('abcabca', 3)).toEqual(4)
|
|
185
|
-
expect(regex.shortestMatchAt('abcabca', 4)).toEqual(7)
|
|
186
|
-
expect(regex.shortestMatchAt('abcabca', 5)).toEqual(7)
|
|
187
|
-
expect(regex.shortestMatchAt('abcabca', 6)).toEqual(7)
|
|
188
|
-
expect(regex.shortestMatchAt('abcabca', 7)).toBeUndefined()
|
|
189
|
-
expect(regex.shortestMatchAt('abcabca', 100)).toBeUndefined()
|
|
190
|
-
expect(regex.shortestMatchAt('defdefdef', 0)).toBeUndefined()
|
|
191
|
-
expect(regex.shortestMatchAt('defdefdef', 1)).toBeUndefined()
|
|
192
|
-
expect(regex.shortestMatchAt('defdefdef', 2)).toBeUndefined()
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
test(`syntax`, () => {
|
|
196
|
-
const regex = new RRegex('a')
|
|
197
|
-
expect(regex.syntax()).toEqual({
|
|
198
|
-
"@name": "regex_syntax::hir::Hir",
|
|
199
|
-
"@type": "struct",
|
|
200
|
-
"kind": {
|
|
201
|
-
"@name": "regex_syntax::hir::HirKind",
|
|
202
|
-
"@type": "enum",
|
|
203
|
-
"@variant": "Literal",
|
|
204
|
-
"value": {
|
|
205
|
-
"@name": "regex_syntax::hir::Literal",
|
|
206
|
-
"@type": "enum",
|
|
207
|
-
"@variant": "Unicode",
|
|
208
|
-
"value": "a"
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
})
|
|
212
|
-
})
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
describe(`RRegexSet`, () => {
|
|
217
|
-
test(`isMatch`, () => {
|
|
218
|
-
let set = new RRegexSet(['\\w+', '\\d+'])
|
|
219
|
-
expect(set.isMatch('foo')).toBe(true)
|
|
220
|
-
expect(set.isMatch('☃')).toBe(false)
|
|
221
|
-
})
|
|
222
|
-
|
|
223
|
-
test(`matches`, () => {
|
|
224
|
-
let set = new RRegexSet([
|
|
225
|
-
'\\w+',
|
|
226
|
-
'\\d+',
|
|
227
|
-
'\\pL+',
|
|
228
|
-
'foo',
|
|
229
|
-
'bar',
|
|
230
|
-
'barfoo',
|
|
231
|
-
'foobar',
|
|
232
|
-
])
|
|
233
|
-
expect(set.matches('foobar')).toEqual([0, 2, 3, 4, 6])
|
|
234
|
-
})
|
|
235
|
-
})
|