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-path-gradient

v0.2.0

Published

Create beautiful, flowing stroke gradients that follow your SVG paths. svg-path-gradient is an open-source library without dependency to create gradient paths in seconds.

Downloads

14

Readme

svg-path-gradient

Create beautiful, flowing stroke gradients that follow your SVG paths. svg-path-gradient is an open-source library without dependency to create gradient paths in seconds.

Open on npmx.dev License GitHub issues GitHub Repo stars

Installation

npm install svg-path-gradient
pnpm add svg-path-gradient
yarn add svg-path-gradient
bun add svg-path-gradient
deno add npm:svg-path-gradient

Usage

import { SvgPathGradient } from "svg-path-gradient";

const splinePath = "M 50 250 C 150 50, 350 50, 450 250 S 750 450, 850 250";

const gradientPath = SvgPathGradient(
  splinePath,
  ["#FF0000", "#00ff88", "#0066ff"],
  {
    segments: 48,
    attrs: {
      "stroke-width": "12",
      "stroke-linecap": "round",
      "stroke-linejoin": "round",
    },
    groupAttrs: { id: "spline-path" },
  },
);

/*
 * gradientPath can now be injected inside a svg group element.
 * In vue, this would be for example:
 *
 *   <svg width="100%" viewBox="0 0 1000 1000">
 *       <g v-html="gradientPath"/>
 *   </svg>
 */

API

Function signature

| KEY | TYPE | DEFAULT | DESCRIPTION | | -------- | --------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | pathData | string | - | SVG path "d" string. Must be a non-empty string. Throws if empty or not a string. | | colors | string[] or null | - | Array of gradient stop colors, evenly distributed from 0 → 1. Any CSS color format supported by the browser is accepted. Can be null if temperatureMode is enabled. | | options | GradientStrokePathOptions | {} | Configuration object controlling segmentation, sampling, interpolation, attributes, and return mode. |

Options

| KEY | TYPE | DEFAULT | DESCRIPTION | | -------------------------- | ------------------------------------ | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | returnMode | "string" or "dom" | "string" | Output format: SVG markup string or DOM nodes you can append to an . DOM mode returns: { group, segments, startCap?, endCap? }. | | segments | number | (computed) | Fixed number of segments to generate. If omitted, derived from maxSegmentLength. Go easy if you care about DOM nodes count | | temperatureMode | null or "vertical" or "horizontal" | null | Directional temperature gradient, enabled when not null, and when temperatureColors are set. | | temperatureColors | [string, string] | undefined | Pair of colors for the temperature mode. | | maxSegmentLength | number | (heuristic) | Maximum arc-length of each segment (user units). Used only if segments is not provided. Heuristic is based on stroke width, clamped, and never exceeds half the total length. | | flattenTolerance | number | 0.25 | Sampling step (user units) when approximating each segment with a polyline. Lower values increase fidelity but increase CPU cost and output size. | | samplePointLimitPerSegment | number | 250 | Safety cap for maximum sampled points per segment. Must be > 10 to override. | | decimalPlaces | number | 3 | Rounding precision for generated coordinates. Lower values reduce output size. | | decimalPlaces | number | 3 | Rounding precision for generated coordinates. Lower values reduce output size. | | colorSpace | "srgb" or "linearRGB" | "linearRGB" | Color interpolation space used when sampling between stops. "linearRGB" gives smoother-looking gradients. | | overlap | number | strokeWidth * 0.5 | Overlap (arc-length user units) applied at segment boundaries to reduce visible seams. Clamped to at most 45% of a base segment length. | | strokeWidth | number | 1 (fallback) | Used only to compute defaults (overlap / maxSegmentLength) if not provided elsewhere. If attrs["stroke-width"] is present and valid, it can be used as a fallback. | | attrs | Record<string, string> | {} | Attributes applied to each generated segment. stroke is always overwritten per segment; fill defaults to "none" if not provided. | | groupAttrs | Record<string, string> | {} | Attributes applied to the wrapping <g> element. | | colorReferenceElement | Element or null | undefined | Optional element used to resolve "currentColor" when converting colors to RGBA. Only relevant if your colors include currentColor. |

Return value

| KEY | TYPE | DESCRIPTION | | ----------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- | | string mode | string | Returns a ... string containing many segments. | | dom mode | { group: SVGGElement; segments: SVGPathElement[]; startCap?; endCap? } | Returns a group node containing the segment path nodes, ready to append into an existing . |