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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@agape/temporal

v0.3.2

Published

Temporal namespace

Readme

@agape/temporal

Access the Temporal namespace safely, even in environments where it's not natively available.

@agape/temporal is designed primarily for library authors who need to work with Temporal but can’t guarantee it’s installed in the consumer’s runtime. It provides a drop-in Temporal namespace that either uses the real implementation (native or polyfill) or falls back to stubs that throw clear runtime errors. This lets your library safely reference Temporal types, fail gracefully when it’s unavailable, and let consumers decide whether to install a polyfill.

Example pattern for library authors:

import { Temporal, hasTemporal } from '@agape/temporal';

export function addHours(hours: number) {
  if (!hasTemporal()) {
    throw new Error('Temporal support required for addHours');
  }

  return Temporal.Now.plainDateTimeISO().add({ hours });
}

🚀 Get Started

import { Temporal, hasTemporal, setTemporal } from '@agape/temporal';

// Always works - checks for Temporal availability
if (hasTemporal()) {
  const now = Temporal.PlainDateTime.from('2025-09-19T10:00');
  console.log(now.toString()); // "2025-09-19T10:00:00"
} else {
  console.log('Temporal not available, using fallback');
}

With Polyfill

If the native Temporal exists, or a polyfill has been set on the globalThis, that will be the implementation used.

import { Temporal as TemporalPolyfill } from '@js-temporal/polyfill';
(globalThis as any)['Temporal'] = TemporalPolyfill;

import { Temporal } from '@agape/temporal';

// Temporal just works
const date = Temporal.PlainDate.from('2025-09-19');
const duration = Temporal.Duration.from('PT1H30M');

With Agape Configuration

You can configure which implementation Agape uses.

import { Temporal as TemporalPolyfill } from '@js-temporal/polyfill';
import { setTemporal, Temporal } from '@agape/temporal';

setTemporal(TemporalPolyfill);

const date = Temporal.PlainDate.from('2025-09-19');
const duration = Temporal.Duration.from('PT1H30M');

📖 API

Temporal Namespace

Use the full Temporal API — Temporal.PlainDateTime, Temporal.PlainDate, Temporal.Duration, etc. Works with real Temporal or provides helpful error stubs.

hasTemporal(): boolean

Check if Temporal is available before using it.

setTemporal(temporal): void

Configure your preferred Temporal implementation (polyfill, custom, etc.).

⚠️ Error Handling

When Temporal is not available, the library throws TemporalNotAvailableError with helpful guidance:

import { Temporal, TemporalNotAvailableError } from '@agape/temporal';

try {
  const date = Temporal.PlainDate.from('2025-09-19');
} catch (error) {
  if (error instanceof TemporalNotAvailableError) {
    console.error('Temporal not available:', error.message);
    // Handle gracefully or use fallback
  }
}

The error message includes guidance on resolving the issue:

  • Use a JavaScript runtime with native Temporal support
  • Install a polyfill like @js-temporal/polyfill

🔗 Dependency on @js-temporal/polyfill

This package lists @js-temporal/polyfill as a dependency so that its type definitions are always available at build time.

  • No Runtime Code Included: The polyfill’s runtime is never imported or bundled by @agape/temporal.
  • Safe for Library Authors: Your consumers remain free to install or omit a polyfill — you are not forcing one into their build.
  • Tree-Shakable: Modern bundlers will include nothing from @js-temporal/polyfill at runtime unless you explicitly call setTemporal with it or attach it to globalThis yourself.

This means you can confidently use Temporal types in your library’s API surface without bloating your downstream consumers’ bundles.


📚 Documentation

See the full API documentation at agape.dev/api.


📦 Agape Toolkit

This package is part of the Agape Toolkit — a comprehensive collection of TypeScript utilities and libraries for modern web development.