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 🙏

© 2025 – Pkg Stats / Ryan Hefner

vectorithm

v1.0.7

Published

Algorithm for vector graphics

Downloads

5

Readme

Vectorithm

Vectorithm is a Node.js module to automate a logical structure of a vector graphic, algorithmic repeating and draw the vector graphic in a PDF file, so often as indicated.

Install

npm install vectorithm

What?! Give me an example!

Look at this vector graphic "source":

Source

We want to create 100 pieces of this graphic but the number (Nr. X) needs to be different. In addition, we want that the stroke color of the line on the bottom is different, in a way that every third time the stroke color is red, blue & green. And this logic in a loop.

That means:

  1. "#f00"
  2. "#00f"
  3. "#0f0"
  4. "#f00"
  5. "#00f"
  6. "#0f0"
  7. "#f00"
  8. [...]

Syntax

That's exactly what the module does. Therefore, you pass variables into the SVG context. A variable is declared by the syntax "{{xxx}}". A variable is an array, with the items to repeat.

There is one special variable. That is the variable "count". In difference to a normal one, in every repeat of "count" 1 is added. Of course "count" is also an array, 1 is added to every item if it's the current one of the loop.

Variables

Variable Items

For example, if "color" is:

["#f00", "#00f", "#0f0"]

And if "count" is:

[0, 0]
  1. [1, 0]
  2. [1, 1]
  3. [2, 1]
  4. [2, 2]
  5. [3, 2]
  6. [3, 3]
  7. [...]

Variables Syntax

The variables are stored in the simple object "variables". For our example:

{
  "color": [
    "#f00", // Red
    "#00f", // Blue
    "#0f0" // Green
  ],
  "count": [0]
}

Module

Require

var vectorithm = require("vectorithm")

console.log(vectorithm)

Parameters & Options

Pass the options (settings) into the "options" object of the vectorithm instance (vectorithm.options)

vectorithm.options = {
  output: __dirname + "/result.pdf", // PDF file to export
  max: 100, // Count of repeats
  border: true, // If there is a border between the items
  width: "9cm", // Width of an item
  //height: "3cm", // Height of an item (Use only, if you don't set a width)
  source: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 50"><!--SVG Content--></svg>', // Source File
  variables: {
    "variable1": ["value1", "value2"],
    "variable2": ["valueA", "valueB"],
    "count": [0]
  } // Object containing the variables (arrays)
}

Width & Height

As you saw, you can pass the width and height of your items in the options. The values are in centimeters. If you just pass the width or height, the other value will used from the "viewBox" attribute. For example, if you set the width to "9cm" and your "viewBox" is "0 0 100 50", the height will be 4.5cm.

Create!

The method "create" will create the PDF using the options.

To see a complete, working example with file reading of the SVG Source, look at the "example.js" file!

vectorithm.create(function(result) {
  console.log(result);
})

SVG Syntax

To declare a variable in the SVG context, use {{variableName}}.

For our example:

If you set the all the options like this, your SVG context looks like this and you run the create() method, your result would be:

Result

The animation is because, your browser wants to show you every site!

Working example

If you are confused about everything, look at the "example.js" file on the GitHub Repository ;-)