@magmacomputing/tempo-fns
v1.2.0
Published
Tree-shakeable functional utilities for the Temporal API
Maintainers
Readme
A library of highly granular, fully tree-shakeable utility functions built directly on top of the JavaScript Temporal API.
This package provides a bridge for developers transitioning from legacy date wrappers (like Moment or date-fns) into the modern Temporal API.
Why tempo-fns?
- Tree-shakeable: Import exactly what you need.
import { isFirstDayOfMonth } from '@magmacomputing/tempo-fns'pulls in zero extra bloat. - Native Temporal & Universal Inputs: Functions accept native
Temporal.PlainDate,Temporal.ZonedDateTime, ISO date strings, standard JSDateobjects, and timestamps. No wrapper required. - Synergy: If you do use the
Tempoclass wrapper,tempo-fnsfunctions seamlessly acceptTempoinstances and provide advanced business-intelligence utilities that understand Tempo's Terms engine (e.g.,isSameFiscalQuarter).
Usage (NPM / Modern Bundlers)
Every function is a standalone, pure export:
import { isFirstDayOfMonth, isBusinessDay, nextBusinessDay, haversineDistance } from '@magmacomputing/tempo-fns';
// 1. Works with simple ISO strings
isFirstDayOfMonth('2026-10-01'); // true
isBusinessDay('2026-10-02'); // true (Friday)
// 2. Works with native Temporal objects
const today = Temporal.Now.plainDateISO();
const nextTradingDay = nextBusinessDay(today);
// 3. Works with standard JS Dates & timestamps
isFirstDayOfMonth(new Date(2026, 9, 1)); // true
// 4. Geodesic & Navigation math with zero dependencies
const distanceKm = haversineDistance(
{ lat: 40.7128, lng: -74.006 }, // NYC
{ lat: 51.5074, lng: -0.1278 } // London
);Usage (Static CDN / Browser Global)
If you aren't using a bundler (like Vite, Webpack, or Rollup), we provide a pre-bundled script that exposes a Functions global object.
<script src="https://cdn.jsdelivr.net/npm/@magmacomputing/tempo-fns/dist/tempo-fns.global.js"></script>
<script>
// Access functions via the Functions global
Functions.isFirstDayOfMonth(Temporal.Now.plainDateISO());
Functions.isBusinessDay('2026-10-02');
</script>