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

svg-content

v0.1.4

Published

Provide custom content to svg template

Downloads

19

Readme

SVG content

This tool provides features helping add custom data to svg-based templates.

Support & Donation

Our team creates fully open-source tools and solutions for developers, designers, and those who teach these subjects. You can help us: share this tool, contribute to it, or donate to us to support future work.

Donate

What's new

v. 0.1.4

  • Add ESM support
  • Add base types for TypeScript

Install

Just add the NPM package to your program:

npm i svg-content

Use

Import buildSvg function to your module:

const { buildSvg } = require("svg-content")

or

import { buildSvg } from "svg-content"

Then call the function with two arguments: svg, values:

const newSvg = buildSvg(svg, values)

Parameters

svg

SVG element, represented by a string. You can read your local template (for example with the fs module), or fetch data from an external server.

Any formats, besides string, for now, are unsupported

values

An object with custom data. The keys of the object must be the same, as the variables in your template. Values can be a string or an array, which contains objects too.

The deep of nesting is 1. You can't add an array as a value inside the array's item value.

SVG template

Any data inside the template can be replaced. You can turn to variable any tag params, content, or even tag name if you need. Just put a variable name into a couple of curly braces. Like this:

<tspan>{{variable}}</tspan>

If you change a tag param, make sure, that you save the quotes around

fill="{{color}}"

When you need to multiply some repeated content, put it between special tags with key names, such as this:

<text>
    <!--array-->
    <tspan>{key1}</tspan>
    <tspan>{key2}</tspan>
    <!--array-->
</text>

It can be used for multiline text, lists, or tables.

Multiline

There are two ways to make multiline content.

New line

The parser can find a new line symbol \n and make several substrings with the same tag, that contain the variable.

Please, don't use multiline content for a tag or tag parameter variables. It can be not working (and mostly will not).

For example, it will replace this (multiline = "Multiline\nexample")

<text>
    <tspan>{{multiline}}</tspan>
</text>

to this

<text>
    <tspan>Multiline</tspan>
    <tspan>example</tspan>
</text>

Array variable

You can also use an array with objects and a special tag <!-- -->, as described before.

Best practice for multiline content is using the relative position of the element (dx, dy) inside the parent container.

Return

The function returns an updated SVG string with replaced data. Now you can use it to respond, export it as a file or paste it into a page.

Error handling

The module provides an error, when something goes wrong. You cat catch this error in handling the pattern you choose for the project.