cssEscape
This tag provides CSS escapes and decoding
Created by: hackvertor
Installed 1 times
Viewed: 157
Category: Convert
Created on: Tuesday, October 22, 2024 at 6:44:49 PM
Updated on: Wednesday, September 17, 2025 at 8:33:49 AM
Tag arguments
[
{
"type": "number",
"help": "This provides the number of characters to pad",
"defaultValue": "2"
}
]
Code
class cssEscape {
encode(input, padding = 2) {
return [...input]
.map((chr) =>
chr.codePointAt(0) <= 0xffffff
? "\\" + chr.codePointAt(0).toString(16).padStart(padding, "0")
: chr,
)
.join("");
}
decode(input) {
return input.replaceAll(/\\([a-fA-F0-9]{2,6})/g, ($0, hex) =>
String.fromCodePoint(parseInt(hex, 16)),
);
}
matches(input) {
return /^(?:(?:\\[a-fA-F0-9]{2,6}){4,})/.exec(input);
}
}