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

svg-path-reverse

v1.7.0

Published

Reverse an SVG path (or subpath)

Downloads

4,207

Readme

An SVG path reversal library

This is a simple SVG path reversal library, with a terribly simple API.

installation

Install with npm:

$> npm install svg-path-reverse

Using the library

This is a universal library, you can load it through require.js, UMD, commonjs, browser, whatever, it doesn't care. You probably know how to use the technology you've chosen to use. Once you've loaded it in, however that might be, the API is as follows:

var utils = ... // load however you know to load libraries
var reverse = utils.reverse,
    normalize = utils.normalize;

var path ="m0 0l10 0 0 10 -10 0z";

var normalized = normalize(path);
var reversed = reverse(path);
var reversed2 = reverse(reversed);

console.log("reversing is idempotent:", normalized === reversed2);

The reverse function can take an optional second argument to reverse a specific subpath in a compound SVG path:

var utils = ... // load however you know to load libraries
var reverse = utils.reverse,
    normalize = utils.normalize;

var path ="m0 0l10 0 0 10 -10 0z m10 10l10 0 0 10 -10 0z";

var normalized = normalize(path);
var reversed = reverse(path, 1);
var reversed2 = reverse(reversed, 1);

console.log("subpath reversing is also idempotent:", normalized === reversed2);

Working on the code

There's no fancy build system here: update the code, update test.js, then run your tests using node test.js.

LICENSE

This code is in the public domain, except in jurisdictions that do not recognise the public domain, where this code is MIT licensed.

demo?

live demo (sort of): https://pomax.github.io/svg-path-reverse