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

vsvg-paths

v1.0.0

Published

A simple encoder decoder of svgs paths

Downloads

193

Readme

vsvg-paths ( virtual SVG path ) Build Status

vsvg path is a small lib to abstract the path data syntax for svgs into an json object. This help with manipulating points on the fly in javascript with ease. If you have an exsisting path data you can decode it into the structure as well.

Install

$ npm install vsvg-paths 

Usage

encode

Encode a array with objects, aka points, into path data for svg path d attributes.


var paths = require( 'vsvg-paths' ),
    path = document.getElementsByTagName( 'path' )[0],
    data = paths.encode( [
        {
            x: 0,
            y: 0
        },
        {
            x: 10,
            y: 10
        },
        {
            x: 1,
            y: 1,
            relative: true 
        }
    ]); // M0 0 L10 10 l1 1

path.setAttribute( 'd', data );

see point types to see what point types are supported

decode

Decode an existing set of path data into the JSON tree that you can pass to encode.


var paths = require( 'vsvg-paths' ),
    path = 'M0 0 L10 10 l1 1',
    data = paths.decode( path )

console.log( data ) 
/*  
    [
        {
            x: 0,
            y: 0
        },
        {
            x: 10,
            y: 10
        },
        {
            x: 1,
            y: 1,
            rel: true // same as relative: true
        }
    ]
*/

Points types

Very closely based off of Path Data Spec. Please referance there for more specifics of what points represent. Also if the key rel or relative is set to true the path with encoded with a lower case instruction making the point relative to the last point.

  • Move To: The first point in an array of points that has only a x and y value eg.
{
    "x": 0,
    "y": 0
}
  • Line To: A point that is not the first of the array that has only a x and y value eg.
{
    "x": 100,
    "y": 50
}
  • Horizontal Line: a point that only has an x value eg.
{
    "x": 100
}
  • Vertical Line: a point that only has an y value eg.
{
    "y": 150
}
  • Curve To: A point that has a x1, y1, x2, y2, x, and y value eg.
{
    "x1": 500,
    "y1": 500,
    "x2": 250,
    "y2": 250,
    "x": 100,
    "y": 50
}
  • Curve Sorthand: A point that has a x2, y2, x, and y also must for a full curve to point eg.
{
    "x2": 250,
    "y2": 250,
    "x": 100,
    "y": 50
}
  • Quadratic Bézier Curve To: a point that has a x1, y1, x, and y value. eg
{
    "x1": 250,
    "y1": 250,
    "x": 100,
    "y": 50
}
  • Elliptical Arc: a point that has a rx, ry, xrotate, largearc, sweep, x, and y value. eg.
{
    "rx": 25,
    "ry": 25,
    "xrotate": -30,
    "largearc": 0,
    "sweep": 1,
    "x": 250,
    "y": 250
}
  • Close Path
{}

What this needs

  • shorthand quadratic Bézier
  • decoder
  • support for absolute and relative positioning in same path