MCPcopy
hub / github.com/kuma-ui/kuma-ui / findOperator

Function findOperator

packages/sheet/src/sheet.ts:23–68  ·  view source on GitHub ↗
(operator: string, selector: string, from: number)

Source from the content-addressed store, hash-verified

21 value.replace(/\s+/g, " ").trim();
22
23function findOperator(operator: string, selector: string, from: number) {
24 const start = selector.indexOf(operator, from);
25
26 if (start < 0) {
27 return null;
28 }
29
30 let index = start + operator.length;
31
32 while (whitespaceRegex.test(selector[index] ?? "")) {
33 index += 1;
34 }
35
36 const unmatchedOrMissingParenthesis: OperatorMatch = {
37 start,
38 end: index,
39 value: undefined,
40 };
41
42 if (selector[index] !== "(") {
43 return unmatchedOrMissingParenthesis;
44 }
45
46 let depth = 1;
47 let cursor = index + 1;
48
49 while (cursor < selector.length && depth > 0) {
50 if (selector[cursor] === "(") {
51 depth += 1;
52 } else if (selector[cursor] === ")") {
53 depth -= 1;
54 }
55
56 cursor += 1;
57 }
58
59 if (depth !== 0) {
60 return unmatchedOrMissingParenthesis;
61 }
62
63 return {
64 start,
65 end: cursor,
66 value: selector.slice(index + 1, cursor - 1),
67 };
68}
69
70function extractOperators(operator: string, style: string) {
71 const selectors: string[] = [];

Callers 2

extractOperatorsFunction · 0.85
unwrapGlobalOperatorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected