@webitel/ui-sdk 23.12.33 → 23.12.35
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 +1 -1
- package/src/validators/variableSearchValidator/Readme.md +13 -0
- package/src/validators/variableSearchValidator/__tests__/variableSearchValidator.spec.js +48 -0
- package/src/validators/variableSearchValidator/variableSearchValidator.js +10 -0
- package/src/validators/variableSearchValidator.js +0 -4
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Validator for variable search string
|
|
2
|
+
```javascript
|
|
3
|
+
import variableSearchValidator from '@webitel/ui-sdk/src/validators/variableSearchValidator/variableSearchValidator';
|
|
4
|
+
|
|
5
|
+
isValidKeyValuePair("height=100"); // true
|
|
6
|
+
isValidKeyValuePair("1 1=2 2"); // true
|
|
7
|
+
isValidKeyValuePair("you height=5 feet 5½ inches (166 cm)"); // true
|
|
8
|
+
isValidKeyValuePair("expected_output=valid_number")); // true
|
|
9
|
+
isValidKeyValuePair("height= 100"); // false
|
|
10
|
+
isValidKeyValuePair("height =100"); // false
|
|
11
|
+
isValidKeyValuePair("height = 100"); // false
|
|
12
|
+
isValidKeyValuePair("height=5 feet 5½ inches (166 cm), age=1231, fin=123231"); // false
|
|
13
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import variableSearchValidator from '../variableSearchValidator';
|
|
2
|
+
|
|
3
|
+
describe('Variable search validator', () => {
|
|
4
|
+
it('Ordinary search', () => {
|
|
5
|
+
const searchValue = 'height=100';
|
|
6
|
+
expect(variableSearchValidator(searchValue)).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
it('Search with spacing in value and key', () => {
|
|
9
|
+
const searchValue = 'your height=5 feet 5½ inches (166 cm)';
|
|
10
|
+
expect(variableSearchValidator(searchValue)).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
it('Search with spacing in value', () => {
|
|
13
|
+
const searchValue = 'height=5 feet 5½ inches (166 cm)';
|
|
14
|
+
expect(variableSearchValidator(searchValue)).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
it('Search with spacing in value and spaces before key and after value', () => {
|
|
17
|
+
const searchValue = ' height=5 feet 5½ inches (166 cm) ';
|
|
18
|
+
expect(variableSearchValidator(searchValue)).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
it('Search with snake_case', () => {
|
|
21
|
+
const searchValue = 'expected_output=valid_number';
|
|
22
|
+
expect(variableSearchValidator(searchValue)).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
it('Wrong search with spacing after "=" sign', () => {
|
|
25
|
+
const searchValue = 'height= 100';
|
|
26
|
+
expect(variableSearchValidator(searchValue)).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
it('Wrong search with spacing before "=" sign', () => {
|
|
29
|
+
const searchValue = 'height =100';
|
|
30
|
+
expect(variableSearchValidator(searchValue)).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
it('Wrong search with spacing near "=" sign', () => {
|
|
33
|
+
const searchValue = 'height = 100';
|
|
34
|
+
expect(variableSearchValidator(searchValue)).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
it('Space search', () => {
|
|
37
|
+
const searchValue = ' ';
|
|
38
|
+
expect(variableSearchValidator(searchValue)).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
it('Empty search', () => {
|
|
41
|
+
const searchValue = '';
|
|
42
|
+
expect(variableSearchValidator(searchValue)).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
it('Multiple "=" search', () => {
|
|
45
|
+
const searchValue = 'height=5 feet 5½ inches (166 cm), age=1231, fin=123231';
|
|
46
|
+
expect(variableSearchValidator(searchValue)).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default function variableSearchValidator(input) {
|
|
2
|
+
if (input) {
|
|
3
|
+
const splitInput = input.split('=');
|
|
4
|
+
const [key, value] = splitInput;
|
|
5
|
+
if (key.endsWith(' ') || value.startsWith(' ') || splitInput.length !== 2) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return true;
|
|
10
|
+
}
|