Skip to content

Commit cc083f2

Browse files
committed
Add normalize method
1 parent 268f763 commit cc083f2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,21 @@ export default {
168168
return mapped.map((item) => arr[item.index]);
169169
},
170170

171+
/**
172+
* Normalize a selector string by parsing and reassembling.
173+
* Removes extraneous whitespace, unencodes unnecessary unicode escapes,
174+
* removes comments, normalizes nth formulas.
175+
*
176+
* This idea could be expanded upon to sort simple selectors and even
177+
* standardize a preference between identical selectors, e.g. :first-child and :nth-child(1).
178+
*
179+
* @param {String} selector selector string
180+
* @return {String} normalized selector string
181+
*/
182+
normalize(selector) {
183+
return this.parse(selector).map((s) => s.toString()).join(', ');
184+
},
185+
171186
// escape methods
172187
escape: CSS.escape,
173188
escapeString: CSS.escapeString,

0 commit comments

Comments
 (0)