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

sgdata-sdk

v0.2.0

Published

Modern TypeScript SDK for Singapore Government Open Data APIs

Downloads

111

Readme

SGData SDK

Modern TypeScript SDK for Singapore Government Open Data APIs. Access real-time transport, weather, and environmental data with full type safety.

🇸🇬 Replaces the abandoned 8-year-old data-dot-gov package with a modern, TypeScript-first approach.

Features

  • TypeScript-first — Full type definitions and IntelliSense support
  • Zero runtime dependencies — Lightweight and secure
  • Automatic retry — Exponential backoff on 429 and 5xx responses
  • Typed errorsSGDataError and SGDataRateLimitError for precise error handling
  • Date/time filtering — All endpoints accept an optional date_time parameter
  • Modern APIs — Works with current data.gov.sg endpoints

Installation

npm install sgdata-sdk

Quick Start

import { SGDataClient } from 'sgdata-sdk';

const client = new SGDataClient();

// Real-time carpark availability
const carparks = await client.getCarparkAvailability();
console.log(carparks.items[0].carpark_data);

// 2-hour weather forecast
const weather = await client.getWeatherForecast2H();
console.log(weather.items[0].forecasts);

// Air quality (PSI)
const psi = await client.getPSI();
console.log(psi.items[0].readings.psi_twenty_four_hourly);

Configuration

const client = new SGDataClient({
  apiKey: 'your-api-key',  // optional — for higher rate limits
  retries: 3,              // default: 3 (set to 0 to disable)
  retryDelay: 1000,        // base delay in ms, doubles each retry (default: 1000)
});

To get an API key: sign up at data.gov.sg and find it in your account dashboard.

API Reference

All methods return typed promises. All methods accept an optional { date_time?: string } parameter (ISO 8601) to query historical data — omit it to get the latest reading.

await client.getTemperature();
await client.getTemperature({ date_time: '2025-01-15T10:00:00' });

Transport

| Method | Description | Update frequency | |---|---|---| | getCarparkAvailability() | HDB/LTA/URA carpark lots | Every minute | | getTaxiAvailability() | GPS coordinates of available taxis | Every 30 seconds | | getTrafficImages() | Traffic camera images with metadata | Every 20 seconds |

Weather

| Method | Description | Update frequency | |---|---|---| | getWeatherForecast2H() | Area-level 2-hour forecast | Every 30 minutes | | getWeatherForecast24H() | General 24-hour forecast with temperature/wind/humidity | Multiple times daily | | getWeatherForecast4D() | 4-day outlook | Twice daily | | getUVIndex() | UV index readings | Hourly, 7AM–7PM |

Environment

| Method | Description | Update frequency | |---|---|---| | getPSI() | Pollutant Standards Index by region | Every 15 minutes | | getTemperature() | Air temperature across weather stations | Every 5 minutes | | getRainfall() | Rainfall readings across weather stations | Every 5 minutes | | getHumidity() | Relative humidity across weather stations | Every minute |

Error Handling

import { SGDataClient, SGDataError, SGDataRateLimitError } from 'sgdata-sdk';

const client = new SGDataClient();

try {
  const data = await client.getPSI();
} catch (error) {
  if (error instanceof SGDataRateLimitError) {
    console.log('Rate limited. Retry after:', error.retryAfter, 'seconds');
  } else if (error instanceof SGDataError) {
    console.log('API error:', error.statusCode, error.message);
  }
}

The SDK automatically retries 429 and 5xx responses with exponential backoff before throwing. Set retries: 0 to disable.

Examples

Find carparks with availability

const carparks = await client.getCarparkAvailability();
const available = carparks.items[0].carpark_data
  .filter(cp => parseInt(cp.lots_available) > 10);
console.log(`${available.length} carparks with 10+ spaces`);

Check if you need an umbrella

const weather = await client.getWeatherForecast2H();
const rainy = weather.items[0].forecasts.some(f =>
  f.forecast.toLowerCase().includes('rain')
);
console.log(rainy ? 'Bring an umbrella' : 'No rain expected');

Air quality alert

const psi = await client.getPSI();
const national = psi.items[0].readings.psi_twenty_four_hourly.national;
if (national > 100) console.log('Unhealthy air quality today');

Find available taxis nearby

const taxis = await client.getTaxiAvailability();
console.log(`${taxis.features.length} taxis available`);
// Each feature has: geometry.coordinates = [longitude, latitude]

TypeScript

All response types are exported:

import {
  SGDataClient,
  // Transport
  CarparkInfo, CarparkAvailabilityResponse,
  TaxiAvailabilityResponse,
  TrafficCamera, TrafficImagesResponse,
  // Weather
  WeatherForecast2HResponse, WeatherForecast24HResponse, WeatherForecast4DResponse,
  UVIndexResponse,
  // Environment
  PSIResponse, TemperatureResponse, RainfallResponse, HumidityResponse,
  // Errors
  SGDataError, SGDataRateLimitError,
} from 'sgdata-sdk';

Data Sources

All data is from Singapore's official data.gov.sg platform.

  • Transport: Land Transport Authority (LTA), HDB, URA
  • Weather / Environment: National Environment Agency (NEA)

Contributing

Issues and pull requests are welcome on GitHub.

License

MIT — Ong Kong Tat