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

powercost

v0.0.1

Published

Browser/Node SDK that converts electricity consumption into actual cost (spot + grid + tax + VAT). Sweden-first, lazy-loadable tariff data packs, zero runtime dependencies.

Downloads

171

Readme

⚡ powercost

Convert electricity consumption → actual cost — spot energy, grid fees, energy tax and VAT, itemised. A tiny, dependency-free SDK that runs in the browser or Node, with tariff data as lazy-loaded packs. Sweden-first; calibrated to real tariffs.

▶ Playground · 📖 Docs

MIT · zero runtime dependencies · ~9 kB

Install

npm i powercost

Or use it with no build step on a static site:

<script type="module">
  import { price } from 'https://esm.sh/powercost';
</script>

Quick start

import { price } from 'powercost';
import { swedenDb } from 'powercost/data/se';   // lazy data pack

const cost = await price({
  consumption: [
    { start: '2026-04-15T18:00:00+02:00', end: '2026-04-15T18:15:00+02:00', kwh: 0.40 },
  ],
  config: {
    zone: 'SE3',
    providerPlanId: 'tibber-kvartspris',
    gridOperatorId: 'vattenfall-e4-25a',
    reportCurrency: 'USD',
  },
  db: swedenDb,
  live: true,                    // fetch spot + FX live, client-side
});

cost.total.format();             // "1.23 SEK"
cost.marginalInclVat.format();   // "0.92 SEK"  — what these kWh actually cost
cost.presentation.total;         // { amount: 0.13, currency: 'USD' }

The cost model

A Swedish bill is two companies plus the state, modelled as composable tariff components:

| Piece | Billed by | What it is | |---|---|---| | Spot energy | Provider (elhandel) | Day-ahead market price per bidding zone, 15-min | | Provider påslag / fees | Provider | Markup + variable costs + monthly fee | | Grid transfer + fixed | Grid operator (elnät) | Per-kWh transfer + fixed subscription per fuse | | Energy tax | State, via the grid invoice | Energiskatt per kWh | | VAT (moms) | State | 25% on top of everything — including the tax |

Every response separates marginalInclVat (the per-kWh cost that scales with use — what load-shifting / net-profit decisions need) from total (the full bill incl. amortised fixed fees). Money is exact integer arithmetic, never floats.

Live data, serverless

With live: true, prices are fetched directly from the browser — no proxy, no backend:

Prefer your own prices? Pass spot / fx sources instead of live.

Data packs

Tariff data is separate from the engine and loaded on demand:

const { swedenDb } = await import('powercost/data/se');

A pack is just a module exporting a TariffDb built from the component grammar (fixed, per_kwh incl. spot-linked, tiered, demand, vat) — all temporal. New countries / operators are new packs — PRs welcome.

Develop

npm test           # engine + clients (offline)
npm run build      # → dist/ (esbuild ESM + .d.ts types)
npm run example    # worked example (Node, via tsx)
npm run build:site # build + copy into public/dist for the static site

The site (public/) deploys to GitHub Pages via .github/workflows/pages.yml.

License

MIT © warting