MCPcopy Create free account
hub / github.com/purifycss/purifycss / getAllWordsInSelector

Function getAllWordsInSelector

src/utils/ExtractWordsUtil.js:18–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18export const getAllWordsInSelector = selector => {
19 // Remove attr selectors. "a[href...]"" will become "a".
20 selector = selector.replace(/\[(.+?)\]/g, "").toLowerCase()
21 // If complex attr selector (has a bracket in it) just leave
22 // the selector in. ¯\_(ツ)_/¯
23 if (selector.includes("[") || selector.includes("]")) {
24 return []
25 }
26 let skipNextWord = false,
27 word = "",
28 words = []
29
30 for (let letter of selector) {
31 if (skipNextWord && !(/[ #.]/).test(letter)) continue
32 // If pseudoclass or universal selector, skip the next word
33 if (/[:*]/.test(letter)) {
34 addWord(words, word)
35 word = ""
36 skipNextWord = true
37 continue
38 }
39 if (/[a-z]/.test(letter)) {
40 word += letter
41 } else {
42 addWord(words, word)
43 word = ""
44 skipNextWord = false
45 }
46 }
47
48 addWord(words, word)
49 return words
50}

Callers 2

parseWhitelistMethod · 0.90
filterSelectorsMethod · 0.90

Calls 1

addWordFunction · 0.70

Tested by

no test coverage detected