No description
Find a file
2025-03-18 06:13:30 -04:00
dist unignored dist folder 2023-11-11 18:17:51 +07:00
.DS_Store initial commit 2023-11-11 17:23:30 +07:00
.gitignore unignored dist folder 2023-11-11 18:17:51 +07:00
CHANGELOG.md updated require in readme 2023-11-13 07:45:53 +07:00
index.js updated format and docs 2023-11-13 07:43:18 +07:00
LICENSE Update LICENSE 2025-03-07 09:49:05 -05:00
package.json Updated package.json repository field for NPM 2025-03-18 06:13:30 -04:00
README.md updated require in readme 2023-11-13 07:45:53 +07:00
test.js updated format and docs 2023-11-13 07:43:18 +07:00

nrel-spa

NREL SPA (Solar Position Algorithm) native implementation in JavaScript. This package allows for precise calculations of solar positions and phases based on geographical coordinates and time.

Installation

npm install nrel-spa

Usage

Basic usage examples:

const { getSpa, calcSpa } = require('nrel-spa');

const date = new Date();
console.log(date)

// NYC - minimum params
const city = "New York"
const lat = 40.7128;
const lng = -74.006;
const tz = null     // optional
const params = null // optional
const angles = []   // optional

/* Jakarta - all params
const city = "Jakarta"
const lat = -6.2088
const lng = 106.8456
const tz = 0
const elevation = 18
const temperature = 26.56
const pressure = 1017
const params = {elevation, temperature, pressure}
const angles = [63.435] */

// Get results
const get = getSpa(date, lat, lng); // minimum args
const calc = calcSpa(date, lat, lng, tz, params, angles);

// Print results
console.log(`\nTest: ${city} with current Date():\n`)
console.log("getSpa =", get, "\n");
console.log("calcSpa =", calc, "\n");

API

Exporting getSpa, calcSpa, and fractalTime. Only date, lat, lng are required but if timezone (tz) is null, will return in UTC.

  • getSpa(date, lat, lng, tz, params, angles) // returns SPA results in fractal times
  • getSpa(date, lat, lng, tz, params, angles) // returns SPA results in formatted times
  • fractalTime(fractionalHour) // formats time from 10.767407706732804 to 10:46:02.667

Contributing

Contributions are welcome! Please read our contributing guidelines.

License

This project is licensed under the ISC License - see the LICENSE file for details.