.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / utils / functionArgumentsSearch.js
1 /* @flow */
2 "use strict";
3
4 const balancedMatch = require("balanced-match");
5 const styleSearch = require("style-search");
6
7 /**
8  * Search a CSS string for functions by name.
9  * For every match, invoke the callback, passing the function's
10  * "argument(s) string" (whatever is inside the parentheses)
11  * as an argument.
12  *
13  * Callback will be called once for every matching function found,
14  * with the function's "argument(s) string" and its starting index
15  * as the arguments.
16  */
17 module.exports = function(
18   source /*: string*/,
19   functionName /*: string*/,
20   callback /*: Function*/
21 ) {
22   styleSearch(
23     {
24       source,
25       target: functionName,
26       functionNames: "check"
27     },
28     match => {
29       if (source[match.endIndex] !== "(") {
30         return;
31       }
32       const parensMatch = balancedMatch(
33         "(",
34         ")",
35         source.substr(match.startIndex)
36       );
37       callback(parensMatch.body, match.endIndex + 1);
38     }
39   );
40 };