@e22m4u/js-repository 0.6.2 → 0.6.3
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/dist/cjs/index.cjs
CHANGED
|
@@ -330,16 +330,7 @@ function stringToRegexp(pattern, flags = void 0) {
|
|
|
330
330
|
if (pattern instanceof RegExp) {
|
|
331
331
|
return new RegExp(pattern, flags);
|
|
332
332
|
}
|
|
333
|
-
|
|
334
|
-
for (let i = 0, n = pattern.length; i < n; i++) {
|
|
335
|
-
const char = pattern.charAt(i);
|
|
336
|
-
if (char === "%") {
|
|
337
|
-
regex += ".*";
|
|
338
|
-
} else {
|
|
339
|
-
regex += char;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return new RegExp(regex, flags);
|
|
333
|
+
return new RegExp(pattern, flags);
|
|
343
334
|
}
|
|
344
335
|
var init_string_to_regexp = __esm({
|
|
345
336
|
"src/utils/string-to-regexp.js"() {
|
package/package.json
CHANGED
|
@@ -9,14 +9,5 @@ export function stringToRegexp(pattern, flags = undefined) {
|
|
|
9
9
|
if (pattern instanceof RegExp) {
|
|
10
10
|
return new RegExp(pattern, flags);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
for (let i = 0, n = pattern.length; i < n; i++) {
|
|
14
|
-
const char = pattern.charAt(i);
|
|
15
|
-
if (char === '%') {
|
|
16
|
-
regex += '.*';
|
|
17
|
-
} else {
|
|
18
|
-
regex += char;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return new RegExp(regex, flags);
|
|
12
|
+
return new RegExp(pattern, flags);
|
|
22
13
|
}
|
|
@@ -2,34 +2,37 @@ import {expect} from 'chai';
|
|
|
2
2
|
import {stringToRegexp} from './string-to-regexp.js';
|
|
3
3
|
|
|
4
4
|
describe('stringToRegexp', function () {
|
|
5
|
-
it('
|
|
5
|
+
it('should return RegExp from a given string', function () {
|
|
6
6
|
expect(stringToRegexp('value').test('value')).to.be.true;
|
|
7
7
|
expect(stringToRegexp('val.+').test('value')).to.be.true;
|
|
8
|
-
expect(stringToRegexp('%alu%').test('value')).to.be.true;
|
|
9
8
|
expect(stringToRegexp('val*').test('value')).to.be.true;
|
|
10
9
|
});
|
|
11
10
|
|
|
12
|
-
it('uses case-sensitive mode by default', function () {
|
|
11
|
+
it('should uses case-sensitive mode by default', function () {
|
|
13
12
|
expect(stringToRegexp('value').test('VALUE')).to.be.false;
|
|
14
13
|
expect(stringToRegexp('val.+').test('VALUE')).to.be.false;
|
|
15
14
|
expect(stringToRegexp('%alu%').test('VALUE')).to.be.false;
|
|
16
15
|
expect(stringToRegexp('val*').test('VALUE')).to.be.false;
|
|
17
16
|
});
|
|
18
17
|
|
|
19
|
-
it('uses given flags in a new RegExp', function () {
|
|
18
|
+
it('should uses given flags in a new RegExp', function () {
|
|
20
19
|
expect(stringToRegexp('value', 'i').test('VALUE')).to.be.true;
|
|
21
20
|
expect(stringToRegexp('val.+', 'i').test('VALUE')).to.be.true;
|
|
22
|
-
expect(stringToRegexp('%alu%', 'i').test('VALUE')).to.be.true;
|
|
23
21
|
expect(stringToRegexp('val*', 'i').test('VALUE')).to.be.true;
|
|
24
22
|
});
|
|
25
23
|
|
|
26
|
-
it('
|
|
24
|
+
it('should return RegExp from a given RegExp', function () {
|
|
27
25
|
const regExp = new RegExp('value');
|
|
28
26
|
expect(stringToRegexp(regExp).test('value')).to.be.true;
|
|
29
27
|
});
|
|
30
28
|
|
|
31
|
-
it('overrides flags of a given RegExp', function () {
|
|
29
|
+
it('should overrides flags of a given RegExp', function () {
|
|
32
30
|
const regExp = new RegExp('value');
|
|
33
31
|
expect(stringToRegexp(regExp, 'i').test('VALUE')).to.be.true;
|
|
34
32
|
});
|
|
33
|
+
|
|
34
|
+
it('should not replace "%" and "_" symbols as SQL-like wildcard', function () {
|
|
35
|
+
const res = stringToRegexp('%alu_');
|
|
36
|
+
expect(res).to.be.eql(/%alu_/);
|
|
37
|
+
});
|
|
35
38
|
});
|