Registry / serialization / d-path-parser

d-path-parser

JSON →
library1.0.0jsnpmunverified

d-path-parser is a JavaScript library designed to parse the 'd' attribute of SVG `<path>` elements. Its current and only stable version is 1.0.0, released in 2016. The package is lightweight (under 1KB minified and gzipped) and engineered for performance, distinguishing itself from alternatives like `svg-path-parser` by being significantly smaller and faster (6-10x faster depending on input length) while maintaining 100% test coverage. It provides a structured breakdown of SVG path commands, facilitating easier debugging, reading, and manipulation of complex path data. The library supports CommonJS, AMD, and exposes a global function if no module loader is detected. Due to its last update being in 2016, the project is considered abandoned.

npm install d-path-parser
INSTALL
IMPORT
SIG · D-PATH-PARSER
D
d-path-parser
serializationjavascriptv1.0.0
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.

parse
const parse = require('d-path-parser');
import parse from 'd-path-parser';
This package is CommonJS-only, published in 2016. Modern ESM imports will require a build step, a dynamic import, or a CommonJS compatibility wrapper, which might lead to `ERR_REQUIRE_ESM` errors in pure ESM environments.

This example demonstrates how to import and use the `d-path-parser` library to parse an SVG path string, showing the resulting array of command objects.

const parse = require('d-path-parser'); const path1 = "M0,0 l10,10 A14.142 14.142 0 1 1 10,-10 Z"; const commands1 = parse(path1); console.log('Parsed Path 1:', JSON.stringify(commands1, null, 2)); const path2 = "m10 10c10-10 20-10 30 0"; const commands2 = parse(path2); console.log('\nParsed Path 2:', JSON.stringify(commands2, null, 2)); /* Example of output for path1: [ { "code": "M", "relative": false, "end": { "x": 0, "y": 0 } }, { "code": "l", "relative": true, "end": { "x": 10, "y": 10 } }, { "code": "A", "relative": false, "radii": { "x": 14.142, "y": 14.142 }, "rotation": 0, "large": true, "clockwise": true, "end": { "x": 10, "y": -10 } }, { "code": "Z" } ]*/
Debug
Known issues
gotchaThe parser does not enforce SVG path strictness. It will not throw an error if the input string is not a complete SVG `d` attribute or if the first command is not a `moveTo`. This allows parsing of partial path segments.
fix
Always validate or sanitize SVG path strings independently if strict adherence to the SVG specification is required for your application.
affects: >=1.0.0
breakingThe project is abandoned, with the last release (v1.0.0) and code update occurring in 2016. This means there will be no further updates, bug fixes, or compatibility improvements for newer JavaScript versions or browser environments.
fix
Consider migrating to a more actively maintained SVG path parsing library if long-term support, security updates, or modern JavaScript feature compatibility are crucial for your project. Alternatives like `path-data-parser` (ESM native) or `svg-path-parser` (though noted as larger/slower by `d-path-parser`'s author) exist.
affects: >=1.0.0
gotchaThe package is a CommonJS module and does not natively support ES Modules (ESM) `import` syntax. Attempting to use `import parse from 'd-path-parser'` directly in a pure ESM Node.js environment or a modern browser build without proper transpilation may lead to errors.
fix
In CommonJS environments, use `const parse = require('d-path-parser');`. In ESM environments, you might need to use a dynamic import (`const parse = await import('d-path-parser').then(mod => mod.default);`) or configure your build system (e.g., Webpack, Rollup, Parcel) to handle CJS interoperability.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ...d-path-parser/index.js require() of ES modules is not supported.
Attempting to `require()` an ES Module or using `import` for a CommonJS module in an incompatible environment or build configuration.
fix
This specific error likely occurs if a build process attempts to treat `d-path-parser` (a CJS module) as an ESM module when being `require`d by another CJS module, or if a newer Node.js environment tries to `require` it in an ESM context. Ensure your `package.json` `type` field is correctly set, or use dynamic `import()` for CJS modules in ESM contexts: `const parse = await import('d-path-parser').then(mod => mod.default);`
TypeError: parse is not a function
The imported `parse` symbol is not recognized as a function, often due to incorrect import syntax or a broken package installation.
fix
Verify that `const parse = require('d-path-parser');` is used in a CommonJS context. If using a bundler, ensure it correctly handles CommonJS modules. Reinstall the package (`npm install d-path-parser`) to rule out corruption.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Bingbot
1
Resources
d-path-parser — npm install d-path-parser · libregistry