- Dharmagya
- panchang-ts docs
- Errors & Compatibility
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:
| Code | Thrown when |
|---|---|
INVALID_DATE | the date is not a valid Date |
INVALID_LATITUDE | latitude outside [-90, 90] |
INVALID_LONGITUDE | longitude outside [-180, 180] |
INVALID_ELEVATION | elevation is not a finite number |
INVALID_TIMEZONE | timezone is neither a finite offset nor a resolvable IANA name |
INVALID_AYANAMSA | unknown ayanamsa slug |
INVALID_INPUT | an argument outside the cases above (bad index, malformed rule, …) |
TIMEZONE_RESOLUTION_FAILED | an IANA zone was passed but Intl could not resolve it (older Hermes) |
NO_SUNRISE | the low-level getSunrise found no event (polar day/night) |
NO_SUNSET | the low-level getSunset found no event |
SEARCH_DIVERGED | an internal root search failed to converge — please report these |
CIRCUMPOLAR | Placidus-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
| Environment | Support |
|---|---|
| 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.
