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 🙏

© 2024 – Pkg Stats / Ryan Hefner

d-path-parser

v1.0.0

Published

JavaScript parser for SVG path's d attribute

Downloads

3,296

Readme

d-path-parser

JavaScript parser for SVG <path>'s d attribute.

Version Build Status

Reason

The syntax for the d attribute is compact and expressive, but unfortunately it's also dramatic to debug/maintain/read. This parser gives you a breakdown of the commands in the string, ready for you to read and manipulate.

There's another library with the same purpose around, maintained by Hugh Kennedy. Its main feature is that's generated from a formal grammar, so that's actually pretty neat. On the down size, there's its... size, and the fact that it's quite slow compared to this one. We're talking about 11x the size minified, 3.5 the size minified and gzipped (d-path-parser is less than 1K), and 6x-10x slower depending on the input (the longer, the slower) and the environment.

One may argue that size and speed aren't usually important features, and they might be right. d-path-parser also has 100% test coverage, by the way.

Installation

Via npm/yarn:

npm install d-path-parser
yarn add d-path-parser

Via bower;

bower install d-path-parser

Usage

As a CommonJS package:

const parse = require("d-path-parser");
const path = "M0,0 l10,10 A14.142 14.142 0 1 1 10,-10 Z";
const commands = parse(path);

This will yield the following result:

[{
    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"
}]

The parser can also be loaded via AMD (define([ "d-path-parser", ... ], function(parse) { ... })) and, if no module loader is detected, a global function dPathParse will be defined.

Gotchas

d-path-parser does not assume the given string is the full path string of a d attribute. In short, it won't throw if the first command is not a moveTo.

Tests

Mocha and Chai are used for tests. Just run npm test (or mocha if it's globally installed).

License

MIT @ Massimo Artizzu 2016. See LICENSE.