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: Thursday, December 19, 2024 at 9:22:04 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);
}
}