mirror of
https://github.com/acamarata/nrel-spa.git
synced 2026-06-30 19:04:25 +00:00
Complete modernization of the package. The core SPA algorithm is unchanged and validated; everything else is rebuilt to match current JavaScript ecosystem standards. Changes: - TypeScript wrapper in src/ with full type definitions - Dual CJS/ESM build via tsup (dist/index.cjs, dist/index.mjs) - Core algorithm moved from dist/spa.js to lib/spa.js (same code) - Input validation with descriptive TypeError/RangeError messages - formatTime() and SPA function code constants as named exports - getSpa() / calcSpa() accept null for optional args (tz, options) - Test suite: 61 ESM assertions and 17 CJS assertions - GitHub Actions CI: Node 20/22/24 matrix, typecheck, pack-check - GitHub Wiki: Home, API Reference, Architecture, Twilight, NREL SPA - NREL attribution in LICENSE and README per their license terms - package.json: exports map, files, engines >=20, sideEffects: false - Author corrected to Aric Camarata; repository.url uses git+https:// - LICENSE year corrected to 2023-2026 - Removed: index.js, test.js, dist/spa.js (superseded by above)
1.6 KiB
1.6 KiB
nrel-spa
Pure JavaScript implementation of the NREL Solar Position Algorithm (SPA). Computes solar zenith angle, azimuth, sunrise, sunset, and solar noon for any location and date. Validated to produce identical output to the original NREL C reference implementation.
Overview
Package: nrel-spa on npm Repository: acamarata/nrel-spa on GitHub License: MIT (wrapper). NREL SPA C source: see LICENSE for third-party notice.
Pages
- API Reference - Full function signatures, parameters, return types
- Architecture - How the algorithm is structured and validated
- Twilight Calculations - Custom zenith angles for civil, nautical, astronomical twilight
- NREL SPA Algorithm - The algorithm background, accuracy, and reference
Quick Example
import { calcSpa } from 'nrel-spa';
const result = calcSpa(
new Date('2025-06-21T00:00:00Z'),
40.7128, // New York latitude
-74.006, // New York longitude
-4, // EDT (UTC-4)
);
console.log(result.sunrise); // "05:25:03"
console.log(result.solarNoon); // "12:57:56"
console.log(result.sunset); // "20:30:35"
Key Facts
- Zero runtime dependencies
- Synchronous: no async, no WASM, no loading delay
- Dual CJS and ESM, full TypeScript definitions
- Matches NREL C reference output within one second across all tested locations
API Reference . Architecture . Twilight Calculations . NREL SPA Algorithm