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

@agaudeals/premium-calc

v0.1.0

Published

Compute precious-metal dealer premiums (per-oz, percent, per-gram-pure) from spot price, dealer price, weight, and purity. Pure function, zero runtime dependencies.

Downloads

168

Readme

@agaudeals/premium-calc

npm version license CI

Compute precious-metal dealer premiums (per-oz, percent, per-gram-pure, per-oz-pure) from a spot price, dealer price, weight, and purity. Pure function, zero runtime dependencies, full TypeScript types. Part of agaudeals.com.

Install

npm install @agaudeals/premium-calc

Requires Node 20+. ESM and CJS entries.

Quick start

import { computePremium } from '@agaudeals/premium-calc';

// American Silver Eagle: 1 oz, .999 fine, dealer asking $32 over $25 spot.
const r = computePremium({
  spotUsdPerOz: 25,
  dealerPriceUsd: 32,
  weightTroyOz: 1,
  purity: 0.999,
});

console.log(r);
// {
//   premiumPerOz: 7.032...,
//   premiumPct: 28.13...,
//   pricePerGramPure: 1.029...,
//   pricePerOzPure: 32.032...,
// }

API

computePremium(input) → result

interface ComputePremiumInput {
  spotUsdPerOz: number;     // > 0
  dealerPriceUsd: number;   // > 0; total ask for the lot
  weightTroyOz: number;     // > 0; per-unit gross weight
  purity: number;           // (0, 1]; e.g. 0.999, 0.9167, 0.9
  quantity?: number;        // > 0; defaults to 1
}

interface ComputePremiumResult {
  premiumPerOz: number;     // pricePerOzPure − spot
  premiumPct: number;       // (premiumPerOz / spot) * 100
  pricePerGramPure: number; // dealer / (totalPureOz * 31.1034768)
  pricePerOzPure: number;   // dealer / (weight * purity * quantity)
}

TROY_OZ_GRAMS (31.1034768) is exported for callers that want to convert independently.

Worked example: feeding @agaudeals/spot-price into premium-calc

import { SpotPrice } from '@agaudeals/spot-price';
import { computePremium } from '@agaudeals/premium-calc';

const spot = new SpotPrice(); // Stooq, 60s cache

// Listing under evaluation: 1 kg gold bar (32.1507 troy oz, .9999 fine), $65,000 ask.
const xau = await spot.getSpot('XAU');
const result = computePremium({
  spotUsdPerOz: xau.priceUsdPerOz,
  dealerPriceUsd: 65_000,
  weightTroyOz: 32.1507,
  purity: 0.9999,
});

console.log(`Spot: $${xau.priceUsdPerOz.toFixed(2)}/oz (source: ${xau.source}, stale: ${xau.stale})`);
console.log(`Premium: $${result.premiumPerOz.toFixed(2)}/oz pure (${result.premiumPct.toFixed(2)}%)`);

Validation

Any of the following throws RangeError with a message naming the bad field:

  • spotUsdPerOz, dealerPriceUsd, weightTroyOz, quantity — must be finite and > 0
  • purity — must be finite and in (0, 1]
computePremium({ spotUsdPerOz: 2000, dealerPriceUsd: 2100, weightTroyOz: 1, purity: 1.5 });
// → RangeError: purity must be in (0, 1], got 1.5

Out of scope (v0.1)

  • Multi-currency (USD only — wrap with your FX layer if needed).
  • Comparison/ranking helpers across listings (deferred to v1.0).

License

MIT — see LICENSE. Maintained by AgAu Deals.