kld-path-parser
raw JSON → 0.2.1 verified Sat Apr 25 auth: no javascript
An event-driven SVG path data parser for Node.js and browsers. Version 0.2.1 is the latest stable release (no cadence documented). It parses SVG path 'd' attribute strings and emits events for each command (moveto, lineto, curveto, arc, etc.) via a handler interface. Unlike a full SVG renderer, it focuses solely on parsing, making it lightweight for path analysis, manipulation, or conversion. Supports ES modules, CommonJS, and UMD bundles. Minimal dependencies; compatible with Node >= 10.15.3.
Common errors
error TypeError: PathParser is not a constructor ↓
cause Wrong import style: default import instead of named import in versions >=0.2.0.
fix
Use
import { PathParser } from 'kld-path-parser' error Could not resolve 'kld-path-parser' ↓
cause Package not installed or bundler misconfigured for ESM.
fix
Run
npm install kld-path-parser. If using bundler, ensure it handles node_modules. error Cannot find module 'kld-path-parser' ↓
cause Missing install or incorrect path in Node.js.
fix
Run
npm install kld-path-parser and import from installed package. Warnings
breaking In v0.2.0, imports changed from default to named exports. Older code using 'import PathParser from ...' will break. ↓
fix Update to named imports: import { PathParser } from 'kld-path-parser'
deprecated The version range uses a leading 'v' in the git tag but npm version is just numbers. Ensure you use 'npm install kld-path-parser@0.2.1' not 'v0.2.1'. ↓
fix Use npm install with version exactly as shown: '0.2.1' (no 'v').
gotcha Parser methods (setHandler, parseData) do not return a promise; they execute synchronously. Do not await them. ↓
fix Call setHandler and parseData without await; they are synchronous.
gotcha Handler methods must be exactly named as listed in the documentation (e.g., 'movetoAbs', not 'moveToAbs'). Case-sensitive. ↓
fix Use exact camelCase names from the handler method list.
Install
npm install kld-path-parser yarn add kld-path-parser pnpm add kld-path-parser Imports
- PathParser wrong
import PathParser from 'kld-path-parser'correctimport { PathParser } from 'kld-path-parser' - SampleHandler wrong
const SampleHandler = require('kld-path-parser').SampleHandlercorrectimport { SampleHandler } from 'kld-path-parser' - PathParser wrong
const PathParser = require('kld-path-parser')correctconst { PathParser } = require('kld-path-parser')
Quickstart
import { PathParser, SampleHandler } from 'kld-path-parser';
const parser = new PathParser();
const handler = new SampleHandler();
const pathData = 'M40,70 Q50,150 90,90 T135,130 L160,70 C180,180 280,55 280,140 S400,110 290,100';
parser.setHandler(handler);
parser.parseData(pathData);
console.log(handler.logs.join('\n'));
// Expected output:
// movetoAbs(40,70)
// curvetoQuadraticAbs(50,150,90,90)
// curvetoQuadraticSmoothAbs(135,130)
// linetoAbs(160,70)
// curvetoCubicAbs(180,180,280,55,280,140)
// curvetoCubicSmoothAbs(400,110,290,100)