cssEscape
This tag provides CSS escapes and decoding
Created by: hackvertor
Installed 1 times
Category: Convert
Created on: Tuesday, October 22, 2024 at 6:44:49 PM
Updated on: Wednesday, November 20, 2024 at 5:32:26 PM
Tag arguments
[]
Code
class cssEscape {
encode(input) {
return input
.split("")
.map((chr) =>
chr.charCodeAt(0) <= 0xffff
? "\\" + chr.charCodeAt(0).toString(16).padStart(6, "0")
: chr,
)
.join("");
}
decode(input) {
return input.replaceAll(/\\([a-fA-F0-9]{2,6})/g, ($0, hex) =>
String.fromCharCode(parseInt(hex, 16)),
);
}
matches(input) {
return /^(?:(?:\\[a-fA-F0-9]{2,6}){4,})/.exec(input);
}
}