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

@pricedb-io/spells

v1.0.4

Published

TypeScript SDK for the spells.pricedb.io TF2 Spell Price API

Readme

@pricedb-io/spells

npm version License: MIT

TypeScript SDK for the spells.pricedb.io API. Calculate spell premiums, get market analytics, and access comprehensive TF2 spell data with full TypeScript support.

📦 Installation

npm install @pricedb-io/spells

or with yarn:

yarn add @pricedb-io/spells

🚀 Quick Start

import { SpellsClient } from '@pricedb-io/spells';

const client = new SpellsClient();

// Get spell prediction for an item
const prediction = await client.predict({
  spells: 'Exorcism',
  item: 'Strange Rocket Launcher'
});

console.log(`Base price: ${prediction.base_price.formatted}`);
console.log(`With spell: ${prediction.predictions.mid.formatted}`);
console.log(`Premium: ${prediction.premium_ranges.mid.formatted}`);

📖 Usage Examples

Get Spell Predictions (Recommended)

// Get enhanced prediction with low/mid/high estimates
const prediction = await client.predict({
  spells: 'Exorcism',
  item: 'Strange Rocket Launcher'
});

console.log('Price Ranges:');
console.log(`  Low:  ${prediction.predictions.low.formatted}`);
console.log(`  Mid:  ${prediction.predictions.mid.formatted}`);
console.log(`  High: ${prediction.predictions.high.formatted}`);
console.log(`Market Data: ${prediction.market_data.sample_size} samples, ${prediction.market_data.confidence} confidence`);

Alternative POST Prediction

// Use spell IDs for prediction
const prediction = await client.predictSpellItem({
  item_name: 'Strange Scattergun',
  spell_ids: [2003, 2002]  // Pumpkin Bombs + Exorcism
});

console.log(`Base price: ${prediction.base_price.formatted}`);
console.log(`Spell premium: ${prediction.spell_premium.formatted}`);
console.log(`Total price: ${prediction.total_price.formatted}`);

Get All Available Spells

// List all TF2 spells
const spells = await client.getSpells();

console.log(`Found ${spells.length} spells:`);
spells.forEach(spell => {
  console.log(`  ${spell.id}: ${spell.name} (${spell.type})`);
});

Convert Between Spell IDs and Names

// ID to Name
const spell = await client.spellIdToName(2002);
console.log(`Spell #${spell.id}: ${spell.name}`);

// Name to ID (case-insensitive, partial matching)
const spellInfo = await client.spellNameToId('Exorcism');
console.log(`${spellInfo.name} has ID: ${spellInfo.id}`);

Get Market Analytics

// Get comprehensive analytics for all spell combinations
const analytics = await client.getSpellAnalytics();

console.log('Top spell premiums:');
analytics
  .sort((a, b) => b.avg_percent - a.avg_percent)
  .slice(0, 10)
  .forEach(spell => {
    console.log(`  Spell ${spell.spell_combo}: +${spell.avg_percent.toFixed(1)}% (${spell.count} samples)`);
  });

Calculate Spell Value

// Get predicted premium for spell combination
const value = await client.getSpellValue('2003,2002');

console.log(`Predicted flat premium: ${value.predicted_flat} ref`);
console.log(`Predicted percentage: ${value.predicted_percent}%`);
console.log(`Average flat: ${value.avg_flat} ref`);
console.log(`Confidence: ${value.confidence}`);
console.log(`Sample size: ${value.count}`);

Get Item Spell Premium

// Calculate detailed breakdown for specific item
const premium = await client.getItemSpellPremium({
  item: 'Strange Scattergun',
  ids: '2003'
});

console.log(`Item: ${premium.item}`);
console.log(`Base price: ${premium.base_price.formatted}`);
console.log(`Spell premium: ${premium.spell_premium.formatted} (+${premium.premium_percent.toFixed(1)}%)`);
console.log(`Total price: ${premium.total_price.formatted}`);
console.log(`Market confidence: ${premium.market_data.confidence}`);

Monitor Data Collection Status

// Check fetcher status
const status = await client.getFetcherStatus();

console.log(`Status: ${status.status}`);
console.log(`Running: ${status.isRunning}`);
console.log(`Last run: ${status.lastRunTime}`);
console.log(`Next run: ${status.nextScheduledRun}`);
console.log(`Schedule: ${status.schedule}`);
console.log('\nStatistics:');
console.log(`  Total fetched: ${status.statistics.totalFetched}`);
console.log(`  Total added: ${status.statistics.totalAdded}`);
console.log(`  Rate limits: ${status.statistics.rateLimits}`);
console.log(`  Errors: ${status.statistics.errors}`);

Get Service Statistics

// Get comprehensive service stats
const stats = await client.getStats();

console.log(`Status: ${stats.status}`);
console.log(`\nDatabase:`);
console.log(`  Spelled items: ${stats.database.totalSpelledItems}`);
console.log(`  Analyzed combos: ${stats.database.analyzedCombos}`);
console.log(`\nKey Prices:`);
console.log(`  Refined: ${stats.keyPrices.ref} ref`);
console.log(`  USD: $${stats.keyPrices.usd}`);
console.log(`\nPerformance:`);
console.log(`  Avg response time: ${stats.performance.avgResponseTime}`);
console.log(`  Requests/min: ${stats.performance.requestsPerMinute}`);
console.log(`  Cache hit rate: ${stats.performance.cacheHitRate}`);

Health Check

// Simple health check
const health = await client.health();
console.log(`Status: ${health.status}`);
console.log(`Uptime: ${health.uptime}`);
console.log(`Version: ${health.version}`);

🔧 Configuration

You can configure the client with custom options:

const client = new SpellsClient({
  baseUrl: 'https://spell.pricedb.io',  // Optional: custom API base URL
  timeout: 10000,                        // Optional: request timeout in ms (default: 10000)
  headers: {                             // Optional: custom headers
    'User-Agent': 'MyApp/1.0.0'
  }
});

📋 API Reference

Client Methods

  • predict(options) - Get spell prediction with price ranges (recommended)
  • predictSpellItem(options) - Alternative POST prediction endpoint
  • getSpellValue(ids) - Calculate premium for spell combination
  • getSpellAnalytics() - Get market analytics for all spells
  • getItemSpellPremium(options) - Detailed premium breakdown
  • spellIdToName(id) - Convert spell ID to name
  • spellNameToId(name) - Convert spell name to ID
  • getSpells() - Get all available spells
  • getFetcherStatus() - Check data collection status
  • health() - Simple health check
  • getStats() - Comprehensive service statistics
  • getStatusProxy() - Get unified status across all services

Types

All TypeScript types are fully exported:

import type { 
  Spell,
  SpellPrediction,
  PostPredictionResponse,
  SpellValue,
  SpellAnalytics,
  ItemSpellPremium,
  FetcherStatus,
  HealthResponse,
  ServiceStats,
  TF2Price
} from '@pricedb-io/spells';

📊 Understanding the Data

Confidence Levels

  • High Confidence: 100+ sample listings - very reliable predictions
  • Medium Confidence: 20-99 sample listings - reasonably reliable
  • Low Confidence: <20 sample listings - use with caution

Price Ranges

The predict endpoint provides three estimates:

  • Low (0.75x): Quick sale price, conservative estimate
  • Mid (1.0x): Market average, most accurate for typical sales
  • High (1.35x): Premium asking price, optimistic estimate

Data Freshness

  • Spell listings updated every 6 hours (00:00, 06:00, 12:00, 18:00 UTC)
  • Key prices (ref) updated every 5 minutes from pricedb.io
  • Key prices (USD) updated every 24 hours from Steam Market
  • Analytics recalculated after each spell listing update

📊 Rate Limiting

The API limits requests to 100 requests per minute per IP address. Health check endpoints are exempt from rate limiting.

Rate limit info is available in response headers:

  • RateLimit-Limit - Maximum requests per window (100)
  • RateLimit-Remaining - Remaining requests in current window
  • RateLimit-Reset - Unix timestamp when limit resets

🐛 Error Handling

try {
  const prediction = await client.predict({
    spells: 'InvalidSpell',
    item: 'Unknown Item'
  });
} catch (error) {
  if (error instanceof Error) {
    console.error('Error:', error.message);
  }
}