unicode
This tag provides unicode escapes and decoding
Created by: hackvertor
Installed 1 times
Category: Convert
Created on: Friday, September 20, 2024 at 11:28:45 AM
Updated on: Friday, September 20, 2024 at 11:28:45 AM
Tag arguments
[]
Code
class unicode {
encode(input) {
return input.split('').map(chr => "\\u"+chr.charCodeAt(0).toString(16).padStart(4, "0")).join('');
}
decode(input) {
return input.replaceAll(/\\u([a-fA-F0-9]{4})/g,($0,hex) => String.fromCharCode(parseInt(hex,16)));
}
matches(input) {
return /^(?:\\u[a-fA-F0-9]{4})+/.exec(input);
}
}