UNPKG

@nodesecure/js-x-ray

Version:
30 lines 885 B
// Import Third-party Dependencies import isStringSvg from "is-svg"; // Import Internal Dependencies import { toValue } from "../estree/index.js"; // CONSTANTS const kSvgPathStartRegex = /^[mzlhvcsqta]\s*[-+.0-9][^mlhvzcsqta]+/i; const kSvgPathEndRegex = /[\dz]$/i; export function isSvg(strOrLiteral) { try { const value = toValue(strOrLiteral); const trimmed = value.trimStart(); return (trimmed.startsWith("<") && 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 && kSvgPathStartRegex.test(trimStr) && kSvgPathEndRegex.test(trimStr); } //# sourceMappingURL=isSvg.js.map