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

election-tonight-client

v1.0.14

Published

![](https://graphics.thomsonreuters.com/style-assets/images/logos/reuters-graphics-logo/svg/graphics-logo-color-dark.svg)

Downloads

40

Readme

🗳️ election-tonight-client

NPM Version Reuters open source software

Client for the ElectionTonight API, an API for retrieving U.S. election results and exit polls conducted by Edison Research.

📚 API docs

⚙️ GitHub Repo

Features

  • ✨ Easy and full-featured API to efficiently retrieve data from the ElectionTonight API in whatever way best suits you.
  • 🐇 Fast, efficient and fully typed database queries with Drizzle and Postgres.js.
  • ✅ Tested across multiple elections.
  • 📆 Simulates your own election night tests.

Install

npm install election-tonight-client

Quickstart

Initialise the client.

import { ElectionTonightClient } from 'election-tonight-client';

// ElectionTonight API key
const API_KEY = 'SECRET';
// ElectionTonight event ID
const EVENT_ID = '20221108';

const client = new ElectionTonightClient(API_KEY, EVENT_ID);

Connect to your PostgreSQL database, using Postgres.js.

const databaseUrl = 'postgresql://localhost:5432/yourdb';

client.connect(databaseUrl);

Setup the event with all its metadata.

await client.setupEvent();

Get all election data in a "sweep" ...

await client.getCountyVotes();
await client.getCalls();
await client.getEditorialTurnout();
await client.getTotalExpectedVote();
await client.getMessages();

... or get just the latest in a "stream."

let updatedEntities = await client.getStreamedCountyVotes();

// Now, do something with the updated entites -- states,
// offices, etc. -- returned from the stream.
for (const updatedEntity of updatedEntites.updated) {
  console.log(`New votes for state: ${updatedEntity.state}`);
}

updatedEntities = await client.getStreamedCalls();
updatedEntities = await client.getStreamedEditorialTurnout();
updatedEntities = await client.getStreamedTotalExpectedVote();
updatedEntities = await client.getStreamedMessages();

Filter requests to only get the county vote data you want.

client.filter({
  states: ['TX', 'KS', 'MO'],
  summary: true,
});

await client.getCountyVotes();

After you've gotten election data from the API, use Drizzle queries to retrieve records from your database.

const states = await client.db.query.state.findMany();

Close the PostgreSQL connection when you're done.

await client.disconnect();

Read more in the client's API docs.

API coverage

Current coverage of ElectionTonight API endpoints. All others are planned by 2024.

Events

| | endpoint | | --- | ---------------------- | | ✅ | event list | | ✅ | absentee-method | | ✅ | county-by-elect | | ✅ | county-by-state | | ⭕ | delegate-district | | ⭕ | delegate-district-type | | ✅ | election | | ✅ | election/race | | ✅ | party-by-office | | ✅ | party-lookup | | ⭕ | past-county-data | | ⭕ | xtab-setup |

Results/streams

| | endpoint | | --- | ------------------------- | | ✅ | county-vote | | ⭕ | delegate-allocation | | ⭕ | delegate-vote | | ✅ | editorial-turnout | | ✅ | electoral-vote | | ✅ | est | | ✅ | msg | | ✅ | national-delegate-summary | | ✅ | total-expected-vote | | ⭕ | xtab |

Development

Testing

Setup

Export a DATABASE_URL environment variable or use the built-in ephemeral PostgreSQL testcontainer.

If using testcontainers, you must have a Docker client installed, e.g., Docker Desktop.

Running tests

npm run test

Run specific tests by passing a substring or regular expression to the --grep filter:

npm run test -- --grep 'your-substring'

☂️ Code coverage

See coverage report.