SunCalc is a lightweight JavaScript library for calculating sun and moon positions, sunlight phases, and lunar data for any location and time.
The library solves the problem of accurately computing astronomical events without external dependencies. It calculates sun altitude and azimuth, provides precise times for sunrise, sunset, and twilight phases (civil, nautical, and astronomical), determines moon position and phase, and identifies moonrise and moonset times. The calculations follow formulas from Jean Meeus' Astronomical Algorithms and match the accuracy standards of timeanddate.com and the U.S. Naval Observatory. The library handles edge cases at high latitudes, such as polar days when the sun never sets and polar nights when it never rises.
Developers should choose this tool when building applications that need reliable astronomical calculations without adding dependencies or complexity. It suits projects ranging from photography apps that need golden hour timing to location-based services requiring sunrise and sunset data. The library works in both Node.js and browser environments, installable via npm or usable directly through a CDN. Its tiny footprint and zero dependencies make it suitable for performance-sensitive applications.
The project maintains a focused scope with infrequent updates, suggesting stability in the core calculation logic. Issues and pull requests receive responses, indicating active maintenance despite the minimal change frequency. The codebase remains small and self-contained, with no external dependencies to manage or update.