opticedge-cloud-utils 1.1.2 → 1.1.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/regex.d.ts +1 -1
- package/dist/regex.js +2 -2
- package/package.json +1 -1
- package/src/regex.ts +1 -1
- package/tests/regex.test.ts +5 -5
package/dist/regex.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function escapeForRegex(input: string): string;
|
package/dist/regex.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
function
|
|
3
|
+
exports.escapeForRegex = escapeForRegex;
|
|
4
|
+
function escapeForRegex(input) {
|
|
5
5
|
return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
6
6
|
}
|
package/package.json
CHANGED
package/src/regex.ts
CHANGED
package/tests/regex.test.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { escapeForRegex } from '../src/regex'
|
|
2
2
|
|
|
3
3
|
describe('escapeRegex', () => {
|
|
4
4
|
it('escapes regex special characters', () => {
|
|
5
5
|
const input = 'Pikachu.$^*+?()[]{}|\\'
|
|
6
6
|
const expected = 'Pikachu\\.\\$\\^\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\\\'
|
|
7
|
-
expect(
|
|
7
|
+
expect(escapeForRegex(input)).toBe(expected)
|
|
8
8
|
})
|
|
9
9
|
|
|
10
10
|
it('returns same string if no special characters', () => {
|
|
11
11
|
const input = 'Charmander123'
|
|
12
|
-
expect(
|
|
12
|
+
expect(escapeForRegex(input)).toBe('Charmander123')
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
it('works with empty string', () => {
|
|
16
|
-
expect(
|
|
16
|
+
expect(escapeForRegex('')).toBe('')
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
it('does not escape regular alphanumerics or spaces', () => {
|
|
20
20
|
const input = 'Lt. Surge Pikachu'
|
|
21
21
|
const expected = 'Lt\\. Surge Pikachu'
|
|
22
|
-
expect(
|
|
22
|
+
expect(escapeForRegex(input)).toBe(expected)
|
|
23
23
|
})
|
|
24
24
|
})
|