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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ergast

v0.0.7

Published

A simple, portable, zero dependency API wrapper for the F1 API Ergast.

Downloads

15

Readme

Ergast.js logo

MIT License Badge Zero Dependencies Badge Compressed package size NPM Version

Currently unstable and incomplete; Not all data APIs are available

Ergast.js is a simple, portable, zero dependency API wrapper for the F1 API Ergast. It can be run on Node.js, the browser, or almost anywhere else JavaScript can be run, and is written entirely in TypeScript.

Features

  • 🪶 Lightweight, with zero dependencies
  • 📦 Built in caching for web runtimes (Node.js coming soon) using the Cachestorage API.
  • 🌎 Supports Deno, Node, the web, and even service workers. Also comes with built-in Typescript types
  • 🔰 Very easy to use, batteries included API
  • 📅 Automatically transforms properties like dates into their native JavaScript datatype

Get started

First, install Ergast.js using your respective package manager.

npm install ergast

Then, import it and instantiate a new class using the default import

import Ergast from "ergast";
const F1Data = new Ergast();

If you want, you can also set a default season and round by passing season and round as properties in the configuration object. If you do not set them, they will default to the current year and every round that year. You can also specify the TTL (time-to-live) of the cache by passing a ttl property with the number of seconds (however, note that the cache currently does not work in Node.js). It defaults to 30 minutes.

import Ergast from "ergast";
const F1Data = new Ergast({
  season: 2023, // Once again, completely optional
  round: 2,
  ttl: 18000,
});

You can also pass the season and round as arguments to individual functions to override the defaults.

Now, you can start using the API. The API itself is rather simple and is documented through the TypeScript types bundled with the library by default. For example, if you wanted to get information about a certain driver, you would use this:

const driverData = await F1Data.drivers.get(
  /*driver id, normally their last name*/ "albon"
);
console.log(driverData);
/*
{
	driverId: "albon",
	permanentNumber: 23,
	code: "ALB",
	url: "http://en.wikipedia.org/wiki/Alexander_Albon",
	givenName: "Alexander",
	familyName: "Albon",
	dateOfBirth: 1996-03-23T00:00:00.000Z,
	nationality: "Thai",
}
*/

As another example, if you want to get the results of a race, just run this:

const raceData = await F1Data.races.get(2023,1)
console.log(raceData)
/*
[
  {
    season: 2023,
    round: 1,
    url: "https://en.wikipedia.org/wiki/2023_Bahrain_Grand_Prix",
    raceName: "Bahrain Grand Prix",
    Circuit: {
      circuitId: "bahrain",
      url: "http://en.wikipedia.org/wiki/Bahrain_International_Circuit",
      circuitName: "Bahrain International Circuit",
      Location: // Truncated
    },
    date: "2023-03-05",
    time: "15:00:00Z",
    Results: [
      // Truncated
    ],
    dateTime: 2023-03-05T15:00:00.000Z,
  }
]

Once again, to find information on all currently available API methods, simply look at the type declaration files. Most modern IDEs also show available methods and the attached annotations automatically.

Contributing

To learn how to contribute, check out the contribution page