@nodesecure/js-x-ray
Version:
JavaScript AST XRay analysis
26 lines • 710 B
JavaScript
// Import Third-party Dependencies
import isStringSvg from "is-svg";
// Import Internal Dependencies
import { toValue } from "../estree/index.js";
export function isSvg(strOrLiteral) {
try {
const value = toValue(strOrLiteral);
return isStringSvg(value) || isSvgPath(value);
}
catch {
return false;
}
}
/**
* @description detect if a given string is a svg path or not.
*/
export function isSvgPath(str) {
if (typeof str !== "string") {
return false;
}
const trimStr = str.trim();
return trimStr.length > 4
&& /^[mzlhvcsqta]\s*[-+.0-9][^mlhvzcsqta]+/i.test(trimStr)
&& /[\dz]$/i.test(trimStr);
}
//# sourceMappingURL=isSvg.js.map