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

svg-shapes-pack

v1.0.2

Published

Random SVG shapes generator for use in apps and websites.

Downloads

6

Readme

Svg-Shapes-Pack

Svg-Shapes-Pack is a utility library for getting random SVG shape icons. It allows you to generate random or customized SVG icons based on provided options.


Table of contents

Installation

To install the package, use npm:

npm install svg-shapes-pack

Usage

Importing the Library

import { getRandomSvg, getSvgById, getAllSvgs } from 'svg-shapes-pack';

Generating a Random SVG

You can generate a random SVG with customizable options:

const options: SVGOptions = {
  color: 'red',
  size: 24,
  gradient: true,
  gradientStartColor: 'red',
  gradientStopColor: 'yellow',
};

const randomSvg = getRandomSvg(options);
console.log(randomSvg);

Getting an SVG by ID

You can get a specific SVG by its ID and customize it. Useful if you need same svg everytime you call this function.

const options: SingleSVGOption = {
  id: '1',
  color: 'blue',
  size: 32,
  gradient: true,
  gradientStartColor: 'blue',
  gradientStopColor: 'green',
};

const svgById = getSvgById(options);
console.log(svgById);

Getting All SVGs

You can get all SVGs with customizable options:

const options: SVGOptions = {
  color: 'purple',
  gradient: true,
  gradientStartColor: 'purple',
  gradientStopColor: 'pink',
};

const allSvgs = getAllSvgs(options);
console.log(allSvgs);

Examples

Reactjs - Basic example

import { useState, useEffect } from 'react'
import { getRandomSvg } from "svg-shapes-pack"

function RandomIcon() {
  const [svg, setSvg] = useState('')
  
  useEffect(() => {
    setSvg(getRandomSvg({
      color: "orange",
      size: 32,
      gradient: true,
      gradientStartColor: "red",
      gradientStopColor: "white"
    }))
  }, [])
  
  if (!svg) return null // or loading state
  
  return <span dangerouslySetInnerHTML={{ __html: svg }} />
}

Reactjs - Dynamic svg

function DynamicSvg({ color, size }) {
  const [svg, setSvg] = useState('')
  
  useEffect(() => {
    setSvg(getRandomSvg({ color, size }))
  }, [color, size]) // SVG updates when props change
  
  return <span dangerouslySetInnerHTML={{ __html: svg }} />
}

// Usage:
<DynamicSvg color="blue" size={24} />

Reactjs - Performance optimization (memoization)

const CachedSvg = memo(function CachedSvg({ id, options }) {
  const [svg, setSvg] = useState('')
  
  useEffect(() => {
    setSvg(getSvgById({ id, ...options }))
  }, [id, JSON.stringify(options)])
  
  return <span dangerouslySetInnerHTML={{ __html: svg }} />
})

Nextjs with App router

Note - Direct usage without useEffect will cause hydration mismatches. Also initialize state with empty string to avoid hydration errors.

'use client'
import { useState, useEffect } from 'react'
import { getRandomSvg, getSvgById, getAllSvgs } from "svg-shapes-pack"

// As a reusable component
export function ShuffleSvg({ color = "blue", size = 32 }) {
  const [svg, setSvg] = useState('')
  
  useEffect(() => {
    setSvg(getRandomSvg({ color, size }))
  }, [color, size])
  
  return <span dangerouslySetInnerHTML={{ __html: svg }} />
}

// Usage with getAllSvgs
export function SvgGallery({ options = {} }) {
  const [svgs, setSvgs] = useState<string[]>([])
  
  useEffect(() => {
    setSvgs(getAllSvgs(options))
  }, [options])
  
  return (
    <div className="flex gap-2">
      {svgs.map((svg, i) => (
        <span key={i} dangerouslySetInnerHTML={{ __html: svg }} />
      ))}
    </div>
  )
}

// Usage with getSvgById
export function SpecificSvg({ id, options = {} }) {
  const [svg, setSvg] = useState('')
  
  useEffect(() => {
    setSvg(getSvgById({ id, ...options }))
  }, [id, options])
  
  return <span dangerouslySetInnerHTML={{ __html: svg }} />
}

API

getRandomSvg(options: SVGOptions): string - Generates a random SVG image based on the provided options.

  • options (optional): An object containing customizable options for the SVG image generation:
    • color: The color (string) of the SVG icon. (Optional).
    • size: A number used for size of the SVG icon. (Optional).
    • gradient: A boolean indicating if gradient is applied to the SVG icon. (Optional)
    • gradientStartColor: The start color (string) of the gradient. (Optional)
    • gradientStopColor: The stop color (string) of the gradient. (Optional)

getSvgById(options: SingleSVGOption): string | null - Processes an SVG template based on provided options to generate a customized SVG icon.

  • options: An object containing customization options for the SVG icon:
    • id: The unique identifier (string between 1 to 120) of the SVG icon.
    • color: The color (string) of the SVG icon. (Optional)
    • size: A number used for size of the SVG icon. (Optional)
    • gradient: A boolean indicating if gradient is applied to the SVG icon. (Optional)
    • gradientStartColor: The start color (string) of the gradient. (Optional)
    • gradientStopColor: The stop color (string) of the gradient. (Optional)

getAllSvgs(options?: SVGOptions): string[] Takes an optional SVGOptions object and returns an array of modified SVG strings based on the provided options. If no color option is provided, it randomly selects colors and applies gradients to the SVGs.

  • options (optional): An object containing customizable options for the SVG image generation:
    • color: The color (string) of the SVG icon. (Optional)
    • size: A number used for size of the SVG icon. (Optional)
    • gradient: A boolean indicating if gradient is applied to the SVG icon. (Optional)
    • gradientStartColor: The start color (string) of the gradient. (Optional)
    • gradientStopColor: The stop color (string) of the gradient. (Optional)

License

This project is licensed under the MIT License.