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-pizzabase

v1.1.1

Published

give JS, receive valid SVG with doctype decorations and all that

Downloads

17

Readme

svg-pizzabase

Script to help create SVG visualisations from JavaScript code; headlessly and server-side. Like a ready-made pizza-base: add toppings and bake.

npm i -g svg-pizzabase

How

Pass client JavaScript on stdin. In that script, append stuff to the svg#vis element present on the page.

When that script finishes running, the SVG element is extracted, the proper doctype stuff added, and the finished SVG is printed on stdout.

For example:

vis.js:

var vis = document.getElementById('vis')
var rect = vis.appendChild(document.createElement('rect'))
rect.setAttribute('width', 50)
rect.setAttribute('height', 50)

Run in a terminal:

svg-pizzabase < vis.js > output.svg

output.svg:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg id="vis"><rect width="50" height="50"></rect></svg>

If you need the SVG element to be a particular size, just change select it and change its width and height attributes it in your code.

Works brilliantly with browserify (or webpack, or another bundler) to get D3 (or whatever other JS library you want to use) into the same file for writing to stdin.

Why

I often draw stuff to clarify my Game Development SE answers. Sometimes it's convenient to draw with D3 code. This eases that. Give it code and it will give you a picture.

Bonus tip: PNG conversion

To convert an SVG into a PNG image, I recommend Inkscape's command line:

inkscape picture.svg --export-png=picture.png --export-area-drawing

I tried ImageMagick's command line, but it tends to crop stuff all funky and renders text badly. YMMV.