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