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

@beatsphere/lastfm-client

v0.1.0

Published

Last.fm API client with Zod validation — auth, scrobbles, top tracks/artists/albums, weekly reports

Readme

@beatsphere/lastfm-client

Last.fm API client with Zod runtime validation. Covers auth, now-playing, top tracks/artists/albums, recent tracks, and weekly reports. Battle-tested in BeatSphere.

Install

npm install @beatsphere/lastfm-client

Quick Start

import {
  getMobileSession,
  getUserInfo,
  getListeningStatus,
  getTopTracks,
  getRecentTracks,
  getWeeklyReport,
} from '@beatsphere/lastfm-client';

// You must provide an MD5 function for API signature generation.
// Examples: crypto.createHash('md5') (Node), react-native-quick-md5, js-md5, etc.
import { createHash } from 'crypto';
const md5 = (input: string) => createHash('md5').update(input).digest('hex');

// Authenticate
const { sessionKey, username } = await getMobileSession(
  'YOUR_API_KEY',
  'YOUR_SHARED_SECRET',
  oauthToken,     // from Last.fm callback URL
  md5,
);

// Get user info
const user = await getUserInfo('YOUR_API_KEY', sessionKey);

// Check what someone is listening to
const status = await getListeningStatus('YOUR_API_KEY', username);
if (status) {
  console.log(`${status.track.name} — ${status.status}`); // 'live' or 'recent'
}

// Top tracks
const tracks = await getTopTracks('YOUR_API_KEY', username, sessionKey, 10);

// Weekly report
const report = await getWeeklyReport('YOUR_API_KEY', username);
// { totalScrobbles: 142, uniqueArtists: 38, topArtist: { name: 'Radiohead' } }

API

| Function | Description | |----------|-------------| | getMobileSession(apiKey, secret, token, md5) | OAuth → session key. Prevents double-processing of single-use tokens | | getUserInfo(apiKey, sessionKey) | User profile (name, playcount, image, etc.) | | getListeningStatus(apiKey, username, threshold?) | Currently playing or recently scrobbled track | | getTopTracks(apiKey, username, sessionKey?, limit?) | User's top tracks | | getTopArtists(apiKey, username, sessionKey?, period?, limit?) | User's top artists | | getTopAlbums(apiKey, username, sessionKey?, period?, limit?) | User's top albums | | getRecentTracks(apiKey, username, sessionKey?, limit?) | Recently scrobbled tracks | | getUserRecentTrack(apiKey, username) | Single most recent track | | getWeeklyReport(apiKey, username) | Weekly scrobble summary | | createApiSignature(params, secret, md5) | Generate Last.fm API signature |

Period values

For getTopArtists and getTopAlbums:

  • '1month' | '3month' | '6month' | '12month' | 'overall'

MD5 function

Last.fm requires MD5-signed requests. Since MD5 implementations vary by platform, you provide your own:

// Node.js
import { createHash } from 'crypto';
const md5 = (s: string) => createHash('md5').update(s).digest('hex');

// React Native
import { stringMd5 } from 'react-native-quick-md5';
const md5 = stringMd5;

// Browser
import md5 from 'js-md5';

Zod schemas

All response schemas are exported for direct use:

import {
  LastFmTrackSchema,
  LastFmUserSchema,
  LastFmAlbumSchema,
  // ... all schemas and types
} from '@beatsphere/lastfm-client';

License

MIT