Skip to content
Documentation · all sections

Errors & Compatibility

panchang-ts · v5.0.0 · MIT

PanchangError codes, polar-latitude behavior, and the supported runtimes — Node, browsers, React Native (Hermes), and Expo.

PanchangError

import { PanchangError } from 'panchang-ts';

try {
  getDailyPanchang(date, location, options);
} catch (e) {
  if (e instanceof PanchangError) {
    console.error(e.code);     // e.g. 'INVALID_LATITUDE', 'INVALID_TIMEZONE'
    console.error(e.message);
  }
}

Every code is a member of the exported PanchangErrorCode union, so a switch over it is exhaustively checkable:

CodeThrown when
INVALID_DATEthe date is not a valid Date
INVALID_LATITUDElatitude outside [-90, 90]
INVALID_LONGITUDElongitude outside [-180, 180]
INVALID_ELEVATIONelevation is not a finite number
INVALID_TIMEZONEtimezone is neither a finite offset nor a resolvable IANA name
INVALID_AYANAMSAunknown ayanamsa slug
INVALID_INPUTan argument outside the cases above (bad index, malformed rule, …)
TIMEZONE_RESOLUTION_FAILEDan IANA zone was passed but Intl could not resolve it (older Hermes)
NO_SUNRISEthe low-level getSunrise found no event (polar day/night)
NO_SUNSETthe low-level getSunset found no event
SEARCH_DIVERGEDan internal root search failed to converge — please report these
CIRCUMPOLARPlacidus-KP houses requested above ±66.5° latitude

Polar locations

getDailyPanchang and getInstantPanchang return null rather than throwing — the Hindu day is undefined when sunrise cannot be computed. The low-level getSunrise / getSunset primitives still throw PanchangError('NO_SUNRISE') / ('NO_SUNSET') for direct callers who need the precise reason. getMoonrise / getMoonset return null (normal for the Moon anywhere on Earth).

Compatibility

EnvironmentSupport
Node.js ≥ 22 (per the package "engines" field)Supported
React Native (Hermes)Supported — pass timezone as a number
Expo (managed + bare)Supported
Browser (modern, ESM)Supported
Browser (legacy / IE)Not supported

The build itself is ES2020 (ESM + CJS, full .d.ts), has zero runtime dependencies, and is sideEffects: false so bundlers tree-shake it. The four subpath entries (panchang-ts/festivals, /eclipses, /moon-phases, /muhurta) import no astronomy code — see Types & Exports.