.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / utils / containsString.js
1 /* @flow */
2 "use strict";
3
4 /**
5  * Checks if a string contains a value. The comparison value can be a string or
6  * an array of strings.
7  *
8  * Any strings starting and ending with `/` are ignored. Use the
9  * matchesStringOrRegExp() util to match regexes.
10  */
11 module.exports = function containsString(
12   input /*: string*/,
13   comparison /*: string | Array<string>*/
14 ) /*: false | { match: string, pattern: string }*/ {
15   if (!Array.isArray(comparison)) {
16     return testAgainstString(input, comparison);
17   }
18
19   for (const comparisonItem of comparison) {
20     const testResult = testAgainstString(input, comparisonItem);
21     if (testResult) {
22       return testResult;
23     }
24   }
25   return false;
26 };
27
28 function testAgainstString(value, comparison) {
29   if (!comparison) return false;
30   if (comparison[0] === "/" && comparison[comparison.length - 1] === "/") {
31     return false;
32   }
33
34   if (value.indexOf(comparison) >= 0) {
35     return { match: value, pattern: comparison };
36   }
37
38   return false;
39 }