MCPcopy
hub / github.com/tailwindlabs/tailwindcss / toKeyPath

Function toKeyPath

packages/tailwindcss/src/utils/to-key-path.ts:18–54  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

16 * @param {string} path
17 **/
18export function toKeyPath(path: string) {
19 let keypath: string[] = []
20
21 for (let part of segment(path, '.')) {
22 if (!part.includes('[')) {
23 keypath.push(part)
24 continue
25 }
26
27 let currentIndex = 0
28
29 while (true) {
30 let bracketL = part.indexOf('[', currentIndex)
31 let bracketR = part.indexOf(']', bracketL)
32
33 if (bracketL === -1 || bracketR === -1) {
34 break
35 }
36
37 // Add the part before the bracket as a key
38 if (bracketL > currentIndex) {
39 keypath.push(part.slice(currentIndex, bracketL))
40 }
41
42 // Add the part inside the bracket as a key
43 keypath.push(part.slice(bracketL + 1, bracketR))
44 currentIndex = bracketR + 1
45 }
46
47 // Add the part after the last bracket as a key
48 if (currentIndex <= part.length - 1) {
49 keypath.push(part.slice(currentIndex))
50 }
51 }
52
53 return keypath
54}

Callers 9

pathToVariableNameFunction · 0.90
toVarFunction · 0.90
configFunction · 0.90
createThemeFnFunction · 0.90
canResolveThemeValueFunction · 0.90
pathToVariableNameFunction · 0.90
toVarFunction · 0.90

Calls 1

segmentFunction · 0.90

Tested by

no test coverage detected