@verifyhash/solar-calc 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +11 -12
- package/index.d.ts +124 -0
- package/package.json +4 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
# solar-calc
|
|
2
2
|
|
|
3
|
-
<!-- publish-prep -->
|
|
4
|
-
> **TODO (owner): pick the final npm name/scope before publishing.**
|
|
5
|
-
> The npm package name is **not** finalized by this project. Convention used here:
|
|
6
|
-
> `package.json` keeps the working slug `solar-calc` as a placeholder — replace it
|
|
7
|
-
> (and the `npm install` line below) with the real published name/scope before
|
|
8
|
-
> running `npm publish`.
|
|
9
|
-
|
|
10
3
|
A tiny, **zero-dependency** Node library for solar geometry: sunrise, sunset,
|
|
11
4
|
solar noon, day length, the Sun's elevation and azimuth at any instant, plus
|
|
12
5
|
civil-twilight and golden-hour boundaries — for any latitude, longitude, and
|
|
@@ -149,6 +142,15 @@ golden hour runs **`goldenHourEveningStart` → sunset**.
|
|
|
149
142
|
|----------|---------|
|
|
150
143
|
| `localClockMinutes(instant, tz?)` | minutes-after-midnight `[0, 1440)` on the local clock for a returned event instant, or `null` if passed `null` |
|
|
151
144
|
|
|
145
|
+
### Internals exposed for testing
|
|
146
|
+
|
|
147
|
+
- `_sunPosition(t)` — the raw NOAA kernel behind everything above. Takes the
|
|
148
|
+
Julian **century** `t` (centuries since J2000.0) and returns
|
|
149
|
+
`{ declination, eqTime }`: the Sun's declination in degrees and the equation
|
|
150
|
+
of time in minutes (how far a sundial runs ahead of a mean clock). Exported
|
|
151
|
+
with the underscore prefix so the test suite can pin it against NOAA
|
|
152
|
+
reference values — treat it as internal; its shape is not covered by semver.
|
|
153
|
+
|
|
152
154
|
## Running the tests
|
|
153
155
|
|
|
154
156
|
One command, no dependencies:
|
|
@@ -170,15 +172,12 @@ MIT.
|
|
|
170
172
|
|
|
171
173
|
## Install
|
|
172
174
|
|
|
173
|
-
> Placeholder name: the `solar-calc` below is the working slug, not a finalized
|
|
174
|
-
> npm name — see the owner TODO near the top of this README.
|
|
175
|
-
|
|
176
175
|
```sh
|
|
177
|
-
npm install solar-calc
|
|
176
|
+
npm install @verifyhash/solar-calc
|
|
178
177
|
```
|
|
179
178
|
|
|
180
179
|
```js
|
|
181
|
-
const solar = require('solar-calc');
|
|
180
|
+
const solar = require('@verifyhash/solar-calc');
|
|
182
181
|
|
|
183
182
|
const lat = 40.7128, lon = -74.006, tz = -4; // New York City, EDT
|
|
184
183
|
const date = { year: 2021, month: 6, day: 21 };
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for @verifyhash/solar-calc — zero-dependency solar
|
|
3
|
+
* position & daylight math (NOAA algorithm).
|
|
4
|
+
*
|
|
5
|
+
* Conventions: lat in degrees (+N), lon in degrees (+E), tz = local clock's
|
|
6
|
+
* offset from UTC in hours (default 0). Daily event functions return the true
|
|
7
|
+
* UTC instant of the event as a Date, or null when the event does not occur
|
|
8
|
+
* that day (polar night / midnight sun).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Date input for the daily functions: either a JS Date (only its calendar
|
|
13
|
+
* date is used, read in UTC) or a plain { year, month, day } object with a
|
|
14
|
+
* 1-based month (1 = January).
|
|
15
|
+
*/
|
|
16
|
+
export type DateInput = Date | { year: number; month: number; day: number };
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sun declination in degrees for the given date (evaluated at local solar
|
|
20
|
+
* noon). Positive toward the North.
|
|
21
|
+
*/
|
|
22
|
+
export function declination(dateInput: DateInput, tz?: number): number;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Equation of time in minutes (apparent minus mean solar time) for the given
|
|
26
|
+
* date. Roughly −14 … +16 minutes across a year.
|
|
27
|
+
*/
|
|
28
|
+
export function equationOfTime(dateInput: DateInput, tz?: number): number;
|
|
29
|
+
|
|
30
|
+
/** Solar noon as a UTC instant. Always defined. */
|
|
31
|
+
export function solarNoon(
|
|
32
|
+
lat: number,
|
|
33
|
+
lon: number,
|
|
34
|
+
dateInput: DateInput,
|
|
35
|
+
tz?: number
|
|
36
|
+
): Date;
|
|
37
|
+
|
|
38
|
+
/** Sunrise (upper limb clearing the horizon) as a UTC instant, or null. */
|
|
39
|
+
export function sunrise(
|
|
40
|
+
lat: number,
|
|
41
|
+
lon: number,
|
|
42
|
+
dateInput: DateInput,
|
|
43
|
+
tz?: number
|
|
44
|
+
): Date | null;
|
|
45
|
+
|
|
46
|
+
/** Sunset (upper limb touching the horizon) as a UTC instant, or null. */
|
|
47
|
+
export function sunset(
|
|
48
|
+
lat: number,
|
|
49
|
+
lon: number,
|
|
50
|
+
dateInput: DateInput,
|
|
51
|
+
tz?: number
|
|
52
|
+
): Date | null;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Length of the day (sunrise → sunset) in minutes. Normal day: (0, 1440);
|
|
56
|
+
* polar night: 0; midnight sun: 1440.
|
|
57
|
+
*/
|
|
58
|
+
export function dayLengthMinutes(
|
|
59
|
+
lat: number,
|
|
60
|
+
lon: number,
|
|
61
|
+
dateInput: DateInput,
|
|
62
|
+
tz?: number
|
|
63
|
+
): number;
|
|
64
|
+
|
|
65
|
+
/** Start of civil dawn (Sun 6° below horizon, rising) as a UTC instant, or null. */
|
|
66
|
+
export function civilDawn(
|
|
67
|
+
lat: number,
|
|
68
|
+
lon: number,
|
|
69
|
+
dateInput: DateInput,
|
|
70
|
+
tz?: number
|
|
71
|
+
): Date | null;
|
|
72
|
+
|
|
73
|
+
/** End of civil dusk (Sun 6° below horizon, setting) as a UTC instant, or null. */
|
|
74
|
+
export function civilDusk(
|
|
75
|
+
lat: number,
|
|
76
|
+
lon: number,
|
|
77
|
+
dateInput: DateInput,
|
|
78
|
+
tz?: number
|
|
79
|
+
): Date | null;
|
|
80
|
+
|
|
81
|
+
/** End of the morning golden hour (Sun reaching 6° elevation), or null. */
|
|
82
|
+
export function goldenHourMorningEnd(
|
|
83
|
+
lat: number,
|
|
84
|
+
lon: number,
|
|
85
|
+
dateInput: DateInput,
|
|
86
|
+
tz?: number
|
|
87
|
+
): Date | null;
|
|
88
|
+
|
|
89
|
+
/** Start of the evening golden hour (Sun descending to 6° elevation), or null. */
|
|
90
|
+
export function goldenHourEveningStart(
|
|
91
|
+
lat: number,
|
|
92
|
+
lon: number,
|
|
93
|
+
dateInput: DateInput,
|
|
94
|
+
tz?: number
|
|
95
|
+
): Date | null;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Geometric solar elevation in degrees above the horizon for a full UTC Date
|
|
99
|
+
* instant (no tz needed — the instant pins the moment). No refraction added.
|
|
100
|
+
*/
|
|
101
|
+
export function solarElevation(lat: number, lon: number, date: Date): number;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Solar azimuth in degrees, clockwise from true North (0 = N, 90 = E,
|
|
105
|
+
* 180 = S, 270 = W), for a full UTC Date instant.
|
|
106
|
+
*/
|
|
107
|
+
export function solarAzimuth(lat: number, lon: number, date: Date): number;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Convert a UTC instant (e.g. from sunrise()) to minutes-after-midnight on
|
|
111
|
+
* the LOCAL clock for the given tz offset (hours). Returns a number in
|
|
112
|
+
* [0, 1440), or null when passed null/undefined.
|
|
113
|
+
*/
|
|
114
|
+
export function localClockMinutes(
|
|
115
|
+
instant: Date | null | undefined,
|
|
116
|
+
tz?: number
|
|
117
|
+
): number | null;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Internal NOAA solve exposed for advanced use / testing: Sun declination
|
|
121
|
+
* (degrees) and equation of time (minutes) for Julian centuries t since
|
|
122
|
+
* J2000.0.
|
|
123
|
+
*/
|
|
124
|
+
export function _sunPosition(t: number): { declination: number; eqTime: number };
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verifyhash/solar-calc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Zero-dependency solar position & daylight math (NOAA algorithm): sunrise, sunset, solar noon, day length, elevation, azimuth, civil twilight, and golden hour for any latitude/longitude/date.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"type": "commonjs",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"test": "node test/solar.test.js"
|
|
@@ -24,7 +25,8 @@
|
|
|
24
25
|
"license": "MIT",
|
|
25
26
|
"files": [
|
|
26
27
|
"index.js",
|
|
27
|
-
"README.md"
|
|
28
|
+
"README.md",
|
|
29
|
+
"index.d.ts"
|
|
28
30
|
],
|
|
29
31
|
"publishConfig": {
|
|
30
32
|
"access": "public"
|