npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@svg-fns/io

v1.0.1

Published

Simple and fast utilities to parse, serialize, and load SVG strings and elements. Optimized for both browser and Node.js environments.

Readme

@svg-fns/io

test codecov Version Downloads npm bundle size NPM License

Feather-light I/O utilities for working with SVGs in browser and Node.js. Minimal, dev-friendly, and universal.


TL;DR 🚀

| Feature | Browser | Node.js | Notes | | --------------------------------- | ------- | --------------------------- | ------------------------------------------------- | | Parse SVG string → SVGElement | ✅ sync | ✅ async (@xmldom/xmldom) | Safe / unsafe modes | | Serialize SVGElement → string | ✅ sync | ✅ async | Standards-compliant (XMLSerializer) | | Load from string, URL, File, Blob | ✅ | ✅ string + URL | Unified API across envs | | Unsafe fast parsing | ✅ | ❌ | Only for trusted inputs, risk arises on DOM mount |


Why @svg-fns/io?

  • Feather-light: No dependencies unless in Node.js.
  • Universal: Works in browser + Node.
  • Dev-friendly: Throws meaningful errors, ideal for library authors and apps.
  • Secure: Unsafe mode is optional and clearly documented.
  • Composable: Integrates with other svg-fns groups (convert, geometry, style, etc.).
  • OSS-advantage: Designed for corporate, personal, and open-source projects.

Features

  • parseSvgBrowser(svgString, config?) – sync, safe (DOMParser) or unsafe (innerHTML).
  • unsafeParseSvg(svgString, config) – fast, only for trusted inputs.
  • parseSvgNode(svgString, config?) – async Node.js parser.
  • parseSvg(svgString, config?) – universal wrapper.
  • serializeSvgBrowser(svgElement, config?) – sync, standards-compliant.
  • serializeSvgNode(svgElement, config?) – async Node.js serializer.
  • serializeSvg(svgElement, config?) – universal wrapper.
  • loadSvg(input: string | File | Blob | URL, config?) – unified loader.

    • Browser: string, File, Blob, URL
    • Node.js: string, URL (via fetch)

Usage Examples

import { parseSvg, serializeSvg, loadSvg } from "@svg-fns/io";

// parse SVG safely
const svgEl = parseSvg(`<svg><circle cx="5" cy="5" r="5"/></svg>`);

// serialize back to string
const svgString = serializeSvg(svgEl);

// load from URL
const svgFromUrl = await loadSvg("https://example.com/icon.svg");

Browser & Node Compatibility

| Feature | Browser | Node.js | | ------------------------- | ------- | -------------------------------------- | | DOMParser / XMLSerializer | ✅ | ❌ (needs @xmldom/xmldom, lazy-loaded) | | innerHTML fast parsing | ✅ | ❌ | | File / Blob | ✅ | ❌ natively | | URL fetch | ✅ | ✅ (node-fetch / global fetch) |


Security Notes

  • Unsafe mode: parsing itself does not execute scripts.
  • Risk arises only when the parsed SVG is attached to the DOM.
  • Always sanitize untrusted SVGs before mounting in unsafe mode.

Installation

pnpm add @svg-fns/io

or

npm install @svg-fns/io

Configuration (IOConfig)

| Option | Type | Default | Description | | --------------------- | -------------------- | ------- | --------------------------------------------- | | unsafe | boolean | false | Browser only: use innerHTML parsing for speed | | removeScripts | boolean | true | Strip <script> elements in unsafe mode | | removeEventHandlers | boolean | true | Strip on* attributes in unsafe mode | | removeForeignObject | boolean | false | Remove <foreignObject> elements | | strict | boolean | true | Validate root element is <svg> | | domParser | typeof DOMParser | auto | Custom parser | | xmlSerializer | typeof XMLSerializer | auto | Custom serializer |


Contribution & Sponsorship

@svg-fns/io thrives with your feedback, PRs, and sponsorship:

  • ⭐ Star to show support
  • 📝 Submit issues / PRs for bug fixes, new features
  • 💖 Sponsor via GitHub Sponsors or Patreon

We welcome OSS, corporate, and personal project use — MPL 2.0 ensures safe adoption in commercial products.


SEO & AI-Friendly Tips

  • Keywords: SVG utilities, SVG parser, SVG serializer, SVG Node.js, feather-light SVG library, universal SVG library.
  • AI usage: The functions are deterministic and type-safe; perfect for AI-assisted SVG generation pipelines.

Roadmap / Future Enhancements

  • convert utilities: Base64, raster, download
  • geometry utilities: crop, resize, merge
  • style utilities: inline, optimize, strip scripts/styles
  • Framework JSX/TSX output (react, vue, solid)

License

This library is licensed under the MPL-2.0 open-source license.

Please enroll in our courses or sponsor our work.