Registry / serialization / vsvg-parser

vsvg-parser

JSON →
library0.3.1jsnpmunverified

vsvg-parser is a lightweight JavaScript library designed for parsing SVG (Scalable Vector Graphics) markup into a structured JavaScript object, suitable for both server-side (Node.js) and client-side (browser) environments. It was initially released in December 2014 and last updated in May 2019. The library is described by its original maintainers as being in 'early development,' and users should expect bugs and file issues. Its primary use case was to power the related `vsvg` library for SVG creation. The current stable version is 0.3.1. Due to its age and lack of recent updates, the project is no longer actively maintained. It focuses on providing a minimal, direct representation of SVG elements, attributes, and their hierarchical structure, without extensive manipulation capabilities, differentiating it from more feature-rich or actively developed SVG parsing solutions.

npm install vsvg-parser
INSTALL
IMPORT
SIG · VSVG-PARSER
V
vsvg-parser
serializationjavascriptv0.3.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parser
import parser from 'vsvg-parser';
import { parse } from 'vsvg-parser';
The primary export is a default object with a 'parse' method. Named imports like `{ parse }` will not work as it's a CommonJS module by default, often bridged to ESM via CDNs like Skypack.
parser
const parser = require('vsvg-parser');
This package primarily supports CommonJS modules, as indicated by its documentation and last update date.
parser.parse
parser.parse('<svg><circle /></svg>');
parse('<svg><circle /></svg>');
The parsing functionality is accessed via the 'parse' method on the imported 'parser' object, not as a top-level function.

This quickstart demonstrates how to import `vsvg-parser` using CommonJS and parse a simple SVG string, then log the resulting structured object and access elements.

const parser = require('vsvg-parser'); const svgString = '<svg width="100" height="100">\n <rect x="10" y="10" width="80" height="80" fill="blue" />\n <circle cx="50" cy="50" r="30" fill="red" stroke="black" stroke-width="2" />\n <text x="20" y="60" font-family="Arial" font-size="16" fill="white">Hello</text>\n</svg>'; try { const parsedSvg = parser.parse(svgString); console.log(JSON.stringify(parsedSvg, null, 2)); // Example of accessing a parsed element if (parsedSvg.length > 0 && parsedSvg[0].children.length > 0) { console.log(`\nFirst child tag name: ${parsedSvg[0].children[0].tagName}`); console.log(`First child attributes:`, parsedSvg[0].children[0].attributes); } } catch (error) { console.error('Error parsing SVG:', error.message); }
Debug
Known issues
breakingThe project is explicitly marked as 'still in early development' and is no longer actively maintained. Users should expect bugs, unpatched security vulnerabilities, and a lack of support for newer SVG specifications or browser features.
fix
For production or critical applications, consider using a more actively maintained and robust SVG parsing library. If you must use `vsvg-parser`, thoroughly audit its code and apply necessary patches.
affects: >=0.1.0
gotchaThe library primarily ships as a CommonJS module. Direct ES module imports (`import ... from 'vsvg-parser'`) will fail in pure ESM environments without a transpilation step or a CDN like Skypack providing an ESM shim.
fix
For CommonJS, use `const parser = require('vsvg-parser');`. For ES modules in modern Node.js or browser environments, consider using a bundler (e.g., Webpack, Rollup) or a CDN that provides an ES module wrapper.
affects: >=0.1.0
gotchaThe library does not ship with TypeScript type definitions, leading to potential type-related errors and a lack of IntelliSense support in TypeScript projects.
fix
You may need to create a custom declaration file (`vsvg-parser.d.ts`) to define types for the `parser` object and its `parse` method, or disable type checking for its usage.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: parser.parse is not a function
Attempting to destructure `parse` directly from the module or calling `parse` as a global function, rather than as a method on the imported `parser` object.
fix
Ensure you are calling `parser.parse(svgString)` after importing the default export: `const parser = require('vsvg-parser');` or `import parser from 'vsvg-parser';`
ReferenceError: require is not defined in ES module scope
Using `require()` syntax within an ES module file (e.g., a `.mjs` file or a `.js` file in a package with `"type": "module"` in `package.json`).
fix
Convert your import statement to `import parser from 'vsvg-parser';` and ensure your environment supports ES modules, possibly through a bundler or a shim service like Skypack for older CJS packages.
TS2307: Cannot find module 'vsvg-parser' or its corresponding type declarations.
The `vsvg-parser` package does not include TypeScript type definitions.
fix
Create a `vsvg-parser.d.ts` file in your project with `declare module 'vsvg-parser';` or more detailed type definitions. Alternatively, install `@types/vsvg-parser` if it existed (which it doesn't for this package) or suppress the error using `@ts-ignore` (not recommended for production).
Upgrade
Version history
0.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources
vsvg-parser — npm install vsvg-parser · libregistry