Introducing shieldcn — README badges, shadcn style.

Check it out

Download Sparkline

Tiny inline SVG sparkline showing npm download trends over time.

Loading...

Installation

$ shadcn add @jalco/download-sparkline

Usage

import { DownloadSparkline } from "@/components/download-sparkline"
<DownloadSparkline package="react" />

Async server component — fetches daily download data from the npm API at build time, cached 1 hour via ISR. Pure SVG, zero charting dependencies.

Variants

Chart types

Three chart types: line (default), area, and bar.

Line

640.6M/30d

Area

640.6M/30d

Bar

640.6M/30d

Time ranges

Three time ranges: last week, last month (default), and last year.

Last week

152.8M/7d

Last month

640.6M/30d

Last year

5061.3M/1y

Examples

With trend indicator

Shows percentage change comparing the first half vs second half of the time range, with a colored arrow.

Trend + label

640.6M/30d+12.9%

Area with trend

205.4M/30d-2.6%

With baseline and date range

Baseline shows a faint dashed line at the average. Date range labels the time period below the chart.

Baseline + dates

640.6M/30d
Aug 8Sep 6

Everything

640.6M/30d+12.9%
Aug 8Sep 6

Custom sizing

Wide

640.6M/30d

Compact

640.6M/30d

API Reference

DownloadSparkline

PropType

Notes

  • ISR caching. Download data is cached for 1 hour via next.revalidate. No API key required.
  • Pure SVG. Zero charting library dependencies. The sparkline is rendered as a single inline SVG element.
  • Trend calculation. The trend percentage compares the average daily downloads in the first half of the range to the second half. Green arrow = increasing, red arrow = decreasing.
  • Pre-fetched data. Pass the data prop to skip the API call — useful for static builds or when fetching data separately.
  • Scoped packages. Supports scoped names like @tanstack/react-query.