unicodeEs6
This tag provides ES6 unicode escapes and decoding
Created by: hackvertor
Installed 1 times
Category: Convert
Created on: Sunday, September 22, 2024 at 12:17:44 PM
Updated on: Friday, December 20, 2024 at 8:07:49 PM
Tag arguments
[]
Code
class unicodeEs6 {
encode(input) {
return input.split('').map(chr => "\\u{"+chr.codePointAt(0).toString(16)+"}").join('');
}
decode(input) {
return input.replaceAll(/\\u[{]([0]*[a-fA-F0-9]{1,6})[}]/g,($0,hex) => String.fromCodePoint(parseInt(hex,16)));
}
matches(input) {
return /^(?:\\u[{][0]*[a-fA-F0-9]{1,6}[}])+/.exec(input);
}
}