@mocanvas/mocanvas · function

sanitizeSvg

declare function sanitizeSvg(svgText: string): string | null

Sanitize an SVG document, returning the cleaned markup — or null when the input was not SVG at all, or when nothing survived.

null rather than an empty string on purpose: a caller has to be able to tell "there was nothing to draw" from "here is an empty drawing", and the former should not create a shape.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.