base64Copy
This tag encodes and decodes base64 using browser APIs atob and btoa.
Created by: lpf-2001
Installed 1 times
Viewed: 2
Category: Convert
Created on: Saturday, July 26, 2025 at 3:08:25 AM
Updated on: Saturday, July 26, 2025 at 3:08:25 AM
Tag arguments
[]
Code
class base64 {
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;
}
}
}