1 | 'use strict';
|
2 |
|
3 | const _ = require('lodash');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | module.exports = function containsString(input, comparison) {
|
20 | if (!Array.isArray(comparison)) {
|
21 | return testAgainstString(input, comparison);
|
22 | }
|
23 |
|
24 | for (const comparisonItem of comparison) {
|
25 | const testResult = testAgainstString(input, comparisonItem);
|
26 |
|
27 | if (testResult) {
|
28 | return testResult;
|
29 | }
|
30 | }
|
31 |
|
32 | return false;
|
33 | };
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | function testAgainstString(value, comparison) {
|
43 | if (!comparison) return false;
|
44 |
|
45 | if (!_.isString(comparison)) return false;
|
46 |
|
47 | if (comparison.startsWith('/') && comparison.endsWith('/')) {
|
48 | return false;
|
49 | }
|
50 |
|
51 | if (value.includes(comparison)) {
|
52 | return { match: value, pattern: comparison };
|
53 | }
|
54 |
|
55 | return false;
|
56 | }
|