Skip to content

Instantly share code, notes, and snippets.

@dhwang
Created November 7, 2018 04:42
Show Gist options
  • Save dhwang/2fdd51375762b3bfc52c971fa127ae28 to your computer and use it in GitHub Desktop.
Save dhwang/2fdd51375762b3bfc52c971fa127ae28 to your computer and use it in GitHub Desktop.
import _ from 'lodash';
/**
* Check to see if a particular SVG tag is supported in the browser.
* <code> console.log('foreignObject', canUseSVG('foreignObject')); </code>
* @returns Boolean
*/
export const canUseSVG = (tagStr) => {
if (!_.isEmpty(tagStr)) {
const lowerCaseTag = tagStr.toLowerCase();
return document.createElementNS('http://www.w3.org/2000/svg', tagStr)
.toString()
.toLowerCase()
.indexOf(lowerCaseTag) !== -1;
}
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment