JSFiddle - React, Tailwind, and code Playground
by amindunited
JavaScript
const decode = (subject) => {
const b64Decoded = atob(subject);
let uriDecoded;
try {
uriDecoded = decodeURIComponent(b64Decoded);
} catch (err) {
console.log('err', err);
uriDecoded = b64Decoded;
}
return uriDecoded;
}
const noURI = btoa('This string is not URI');
const isURI = btoa(encodeURIComponent('This string is URI'));
const fakeURI = btoa('This string is not URI%');
console.log('noURI', decode(noURI));
console.log('isURI', decode(isURI));
console.log('fakeURI', decode(fakeURI));