@atlaskit/editor-wikimarkup-transformer
Version:
Wiki markup transformer for JIRA and Confluence
22 lines • 777 B
JavaScript
/**
* returns a correctly percent-encoded & sanitized url.
* Will fallback to using a DOM based implementation if the `URL` class
* doesn't exist.
*
* @param raw a 'raw' url (possibly mixed percent-encoded).
*/
export function decode(raw) {
if (typeof URL === 'function') {
var decoded = new URL(raw);
// IE11 doesn't support the `href` property in the `URL` class.
// Fallback to the DOM below if it doesn't exist.
if (decoded.href) {
return decoded.href;
}
}
// no `URL` class - pollyfill using the dom to parse and
// decode. This should only be needed for IE11 or lower...
var anchor = document.createElement('a');
anchor.href = raw; // The DOM will parses even mixed %-encoded segments of a url when set.
return anchor.href;
}