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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@trailstash/pinhead-js

v1.0.0

Published

Quality public domain sprites for your map

Downloads

44

Readme

Pinhead JS

Pinhead JS is a utility and library for composing Pinhead icons into various shapes, including pins, markers, circles, and squares. It's designed for map developers who need flexible, programmatically generated icons for MapLibre GL JS, Leaflet, or any other web-based mapping platform.

Features

  • Icon Composition: Layer any Pinhead icon onto background shapes.
  • Smart Coloring: Automatically chooses contrasting icon colors based on the background fill.
  • Multiple Shapes: Supports circle, square, map_pin, and marker.
  • Basic transforms: Rotate and flip icons.
  • CLI & API: Use it as a command-line tool for batch processing or as a JavaScript library in your app.
  • Custom Icon SVGs: Pass raw SVG strings as the icon name to use custom icons.
  • Custom Shapes: Use custom SVG strings or PNG data URIs as background shapes.
  • Migration: A function is provided to simplify the usage of Pinhead's changelog.json.

Installation

npm install @trailstash/pinhead-js

Options

These options are common across both the CLI and API.

| Option | Description | Default | | :------------- | :--------------------------------------------------------------------------------------------- | :---------------------------------------------------- | | cornerRadius | Corner radius (applies to square only) | 4 | | fill | Sets the fill color of the icon | black or white (auto-calculated from shapeFill) | | padding | Internal padding between icon and shape edge | Varies by shape | | scale | Scale factor for the output SVG dimensions | 1 | | shape | Background shape: square, circle, map_pin, marker, a raw SVG string, or a PNG data URI | none | | shapeFill | Fill color of the background shape | black | | stroke | Color of the stroke (applies to shape if present, otherwise icon) | Auto-calculated (contrasting or darkened/lightened) | | strokeWidth | Width of the stroke | 1 for marker, else 0 | | flip | Flip the icon: horizontal or vertical | none | | rotate | Rotate the icon | none |


Usage

JavaScript API

Create Icons

Ideal for dynamic icon generation in the browser or on the server.

import { getIcon } from "@trailstash/pinhead-js";

// Simple icon
const svg = getIcon("cargobike");

// Icon with background and custom colors
const marker = getIcon("jeep", {
  shape: "map_pin",
  shapeFill: "#6486f5",
  strokeWidth: 1,
});
Examples

| Result | Code | | :---------------------------------------- | :------------------------------------------------------------------------------------------------ | | | getIcon("cargobike") | | | getIcon("cup_and_saucer", { strokeWidth: 1 }) | | | getIcon("bicycle", { shape: "circle", shapeFill: "white", fill: "#6dad6f", stroke: "#6dad6f" }) | | | getIcon("burger", { shape: "marker", shapeFill: "#3FB1CE" }) | | | getIcon("ice_cream_on_cone", { shape: "circle", shapeFill: "pink" }) | | | getIcon("rocketship", { shape: "map_pin", shapeFill: "purple" }) |

Custom Icon SVGs

You can pass a raw SVG string as the icon name to use a custom icon.

import { getIcon } from "@trailstash/pinhead-js";

const customIcon = getIcon(
  '<svg viewBox="0 0 15 15"><path d="M7.5 10a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5z" fill="red"/></svg>',
  {
    shape: "circle",
    shapeFill: "white",
  },
);

Custom Shapes

You can provide your own background shapes as SVG strings or PNG data URIs. Use the padding option as an array [x, y] to precisely position the 15x15 icon within your custom shape.

import { getIcon } from "@trailstash/pinhead-js";

// Custom SVG shape
const customSvg = getIcon("bicycle", {
  shape:
    '<svg viewBox="0 0 25 25"><circle cx="12.5" cy="12.5" r="10" fill="green"/></svg>',
  padding: [5, 5],
});

// Custom PNG shape (base64 data URI)
const customPng = getIcon("bus", {
  shape:
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAjCAYAAABhCKGo...",
  padding: [5, 10],
});

Migrate an icon name

import { migrateName } from "@trailstash/pinhead-js";

// Migrate a name previously used by Pinhead. If a name was used more than once, the more recent name is returned.
let name = migrateName("pedestrian"); // -> "person_walking"

// Migrate from a specific version (treasure_map was renamed, in v13, but a new treasure_map was introduced then too)
migrateName("treasure_map", "pinhead@10"); // -> "bifold_map_with_dotted_line_to_x"
migrateName("treasure_map", "pinhead@13"); // -> "treasure_map"

// Migrate from a seed source
migrateName("maps", "nps"); // -> "bifold_map_with_dotted_line_to_x"

Command Line Interface (CLI)

1. Generate a single icon

Outputs the SVG string directly to stdout.

npx pinhead get-icon cargobike --shape=square --shapeFill='#6486f5' > icon.svg

2. Batch build from configuration

The build-icons command creates a collection of SVG files based on a JSON configuration file. By default, it looks for pinhead.json and writes results to a ./svgs/ directory.

npx pinhead build-icons --config my-icons.json --outdir ./assets/icons

pinhead.json structure:

{
  "groups": [
    {
      "icons": {
        "bicycle": "bike-icon",
        "bus": "bus-marker"
      },
      "options": {
        "shape": "circle",
        "shapeFill": "#6486f5"
      }
    }
  ]
}

Custom Icon SVG requirements

To work with Pinhead JS as a custom icon (passed as the name argument), custom SVG strings must follow these constraints:

  • Use only <path> elements.
  • Path elements should only contain the d attribute.
  • The viewBox should be "0 0 15 15", or height and width should be set to 15.

Integrations

MapLibre GL JS

To use Pinhead JS dynamically with MapLibre:

const svg = getIcon("greek_cross", { shape: "circle", shapeFill: "red" });

const img = new Image();
const blob = new Blob([svgString], { type: "image/svg+xml;charset=utf-8" });
img.src = URL.createObjectURL(blob);
await img.decode();

map.addImage("hospital-icon", img);

URL.revokeObjectURL(url);

Inspiration

Pinhead JS is inspired by the Maki Icon Editor and makiwich

License

Pinhead JS is distributed under the WTFPL.