Created
February 20, 2013 22:42
-
-
Save fastdivision/5000379 to your computer and use it in GitHub Desktop.
Scouter snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for selector in str.split(/[\s,+~>]+/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IDs | |
a = selectors.filter((element) -> element.indexOf('#') != -1) | |
# Classes, Attributes, Pseudo-Classes | |
b = selectors.filter((element) -> | |
element.match(/\[.+\]|(\.|:)[_a-zA-Z0-9-]/)?.length && element.indexOf('::') == -1 | |
) | |
selectors = selectors.filter (i) -> !(a.concat(b).indexOf(i) > -1) | |
# Type Selectors, Pseudo-Elements | |
c = selectors |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matches = selector.match(/\[.+\]|(#|\.|::|:)[_a-zA-Z0-9-]*|[_a-zA-Z0-9-]*/gi) | |
if matches | |
for match in matches | |
match = match.replace(/:not|\(|\)/gi, '') | |
selectors.push(match) if match.length | |
else | |
selectors.push(selector) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
score = parseInt("#{a.length}#{b.length}#{c.length}", 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment