base64Copy
This tag encodes and decodes base64 using browser APIs atob and btoa.
Created by: seacord
Installed 1 times
Category: Convert
Created on: Tuesday, April 8, 2025 at 6:27:59 PM
Updated on: Friday, April 18, 2025 at 4:50:03 PM
Tag arguments
[]
Code
class base64Copy {
encode(input) {
return btoa(input);
}
decode(input) {
return atob(input);
}
matches(input) {
const base64Regex = /^(?:(?:[A-Za-z0-9+/]{8,}={0,2}$)|[A-Za-z0-9+/]{8,}={0,2})/;
const result = base64Regex.exec(input);
if(result && result[0].length % 4 === 0) {
return result;
} else {
return null;
}
}
}