css-selector-tokenizer
Advanced tools
@@ -26,4 +26,8 @@ "use strict"; | ||
| function unescapeString(content) { | ||
| return content.replace(/\\./g, function(escaped) { | ||
| return escaped.substr(1); | ||
| return content.replace(/\\([a-fA-F0-9]{4}|.)/g, function(escaped) { | ||
| if(escaped.length > 2) { | ||
| return String.fromCharCode(parseInt(escaped.substr(1), 16)); | ||
| } else { | ||
| return escaped.substr(1); | ||
| } | ||
| }); | ||
@@ -91,2 +95,3 @@ } | ||
| this.root = this.stack.pop(); | ||
| this.value = this.root.nodes[this.root.nodes.length - 1]; | ||
| } | ||
@@ -130,3 +135,3 @@ } | ||
| "url\\((\\s*)((?:[^\\\\)'\"]|\\\\.)*)(\\s*)\\)": urlMatch, | ||
| "(\\w+)\\((\\s*)": nestedItemMatch, | ||
| "([\\w\-]+)\\((\\s*)": nestedItemMatch, | ||
| "(\\s*)(\\))": nestedItemEndMatch, | ||
@@ -133,0 +138,0 @@ ",(\\s*)": commaMatch, |
@@ -5,2 +5,23 @@ "use strict"; | ||
| function escape(str, stringType) { | ||
| return str.replace(/["'\\\x80-\uFFFF]/g, function(match) { | ||
| switch(match) { | ||
| case "\"": | ||
| if(stringType === "\"") { | ||
| return "\\\""; | ||
| } | ||
| return match; | ||
| case "'": | ||
| if(stringType === "'") { | ||
| return "\\'"; | ||
| } | ||
| return match; | ||
| case "\\": | ||
| return "\\\\"; | ||
| default: | ||
| return "\\" + (0x10000 + match.charCodeAt(0)).toString(16).substr(1); | ||
| } | ||
| }); | ||
| } | ||
| function stringifyWithoutBeforeAfter(tree) { | ||
@@ -23,5 +44,5 @@ switch(tree.type) { | ||
| case "'": | ||
| return "'" + tree.value.replace(/'/g, "\\'") + "'"; | ||
| return "'" + escape(tree.value, "'") + "'"; | ||
| case "\"": | ||
| return "\"" + tree.value.replace(/"/g, "\\\"") + "\""; | ||
| return "\"" + escape(tree.value, "\"") + "\""; | ||
| } | ||
@@ -28,0 +49,0 @@ /* istanbul ignore next */ |
+1
-1
| { | ||
| "name": "css-selector-tokenizer", | ||
| "version": "0.5.1", | ||
| "version": "0.5.2", | ||
| "description": "Parses and stringifies CSS selectors", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
15452
4.05%466
5.67%