@verifyhash/moon-phase 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.
Files changed (4) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +12 -12
  3. package/index.d.ts +57 -0
  4. package/package.json +4 -2
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 <OWNER-NAME PLACEHOLDER>
3
+ Copyright (c) 2026 verifyhash
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,12 +1,5 @@
1
1
  # moon-phase
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 `moon-phase` 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 **zero-dependency, pure-function** Node library that turns any instant into the
11
4
  Moon's phase: its phase angle, the fraction of the disk that is lit, the synodic
12
5
  age in days, the canonical phase name, and the Brown lunation number.
@@ -61,6 +54,16 @@ defining angle — so `New` covers 337.5°–360°–22.5°, `First Quarter` cov
61
54
  67.5°–112.5°, and so on. The narrow "instant" phases (New, the two quarters,
62
55
  Full) are the sectors straddling their exact angles.
63
56
 
57
+ ### Constants & internals
58
+
59
+ - `SYNODIC_MONTH` — the mean synodic month, `29.530588853` days (new moon to
60
+ new moon). Handy for converting `ageDays` to a fraction of the cycle.
61
+ - `_julianDay(date)` — Julian Day number for a JS `Date` (UTC).
62
+ - `_elongationAtJD(jd)` — Moon−Sun elongation in degrees at a Julian Day.
63
+
64
+ The two underscore-prefixed functions are the internal kernels, exported only
65
+ so the tests can pin them against almanac values — internal API, not semver-stable.
66
+
64
67
  ## Algorithm & citation
65
68
 
66
69
  The geometry follows **Jean Meeus, *Astronomical Algorithms* (2nd ed., 1998)**:
@@ -122,15 +125,12 @@ MIT.
122
125
 
123
126
  ## Install
124
127
 
125
- > Placeholder name: the `moon-phase` below is the working slug, not a finalized
126
- > npm name — see the owner TODO near the top of this README.
127
-
128
128
  ```sh
129
- npm install moon-phase
129
+ npm install @verifyhash/moon-phase
130
130
  ```
131
131
 
132
132
  ```js
133
- const moon = require('moon-phase');
133
+ const moon = require('@verifyhash/moon-phase');
134
134
 
135
135
  const d = new Date('2024-01-25T17:54:00Z'); // a full moon
136
136
  moon.phaseName(d); // 'Full'
package/index.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Type declarations for @verifyhash/moon-phase — zero-dependency lunar phase
3
+ * & illumination math (simplified Meeus method).
4
+ *
5
+ * Every function takes a JS Date interpreted as a UTC INSTANT (date + time
6
+ * both matter — the Moon moves ~12° per day). Inputs are never mutated.
7
+ */
8
+
9
+ /** The 8 canonical phase names returned by phaseName(). */
10
+ export type MoonPhaseName =
11
+ | 'New'
12
+ | 'Waxing Crescent'
13
+ | 'First Quarter'
14
+ | 'Waxing Gibbous'
15
+ | 'Full'
16
+ | 'Waning Gibbous'
17
+ | 'Last Quarter'
18
+ | 'Waning Crescent';
19
+
20
+ /**
21
+ * Sun-Moon elongation in degrees, in [0, 360). 0° = New, 90° = First Quarter,
22
+ * 180° = Full, 270° = Last Quarter.
23
+ */
24
+ export function moonPhaseAngle(date: Date): number;
25
+
26
+ /**
27
+ * Fraction of the Moon's disk that is lit, in [0, 1]. 0 at new moon, 1 at
28
+ * full moon, ~0.5 at the quarters.
29
+ */
30
+ export function illuminatedFraction(date: Date): number;
31
+
32
+ /**
33
+ * Days since the last new moon (synodic age), in [0, ~29.53). Good to a
34
+ * fraction of a day (derived via the MEAN synodic month), not to the minute.
35
+ */
36
+ export function moonAge(date: Date): number;
37
+
38
+ /**
39
+ * One of the 8 canonical phase names, binned by elongation into 45° sectors
40
+ * (boundaries at 22.5°, 67.5°, 112.5°, …).
41
+ */
42
+ export function phaseName(date: Date): MoonPhaseName;
43
+
44
+ /**
45
+ * Brown Lunation Number of the lunation in progress on the given date
46
+ * (integer; the new moon of 2000-01-06 is number 953).
47
+ */
48
+ export function lunation(date: Date): number;
49
+
50
+ /** Mean length of the synodic month in days (29.530588853). */
51
+ export const SYNODIC_MONTH: number;
52
+
53
+ /** Internal, exposed for testing: Julian Day (with fraction) of a Date instant. */
54
+ export function _julianDay(date: Date): number;
55
+
56
+ /** Internal, exposed for testing: true Sun-Moon elongation (deg) at a Julian Day. */
57
+ export function _elongationAtJD(jd: number): number;
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@verifyhash/moon-phase",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Zero-dependency lunar phase & illumination math (simplified Meeus method): phase angle, illuminated fraction, synodic age, canonical phase name, and Brown lunation number for any UTC instant.",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "type": "commonjs",
7
8
  "scripts": {
8
9
  "test": "node test/moon.test.js"
@@ -22,7 +23,8 @@
22
23
  "license": "MIT",
23
24
  "files": [
24
25
  "index.js",
25
- "README.md"
26
+ "README.md",
27
+ "index.d.ts"
26
28
  ],
27
29
  "publishConfig": {
28
30
  "access": "public"