npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tortaruga/moon-phase-js

v1.0.2

Published

Calculate moon phase, emoji, and illumination for any date

Downloads

363

Readme

🌙 moon-phase-js

A lightweight JavaScript utility to calculate the moon phase for any date, including phase name, emoji, and illumination percentage.


📦 Installation

npm install @tortaruga/moon-phase-js

🚀 Usage

import { getPhase, getEmoji, getIllumination } from "@tortaruga/moon-phase-js";

const date = new Date("2026-04-01");

console.log(getPhase(date));       // "Full Moon"
console.log(getEmoji(date));       // "🌕"
console.log(getIllumination(date)); // 0.985077512880078

Note: getIllumination returns a value from 0 to 1. Multiply by 100 for a percentage.

🧠 API

getPhase(date)

Returns the moon phase name for a given date.

  • Parameters: date (Date object)
  • Returns: string — phase name
  • Example:
getPhase(new Date("2026-04-01")); // "Full Moon"
getPhase(new Date("17 April 2026")); // "New Moon"

getEmoji(date)

Returns an emoji representing the moon phase.

  • Parameters: date (Date object)
  • Returns: string — emoji
  • Example:
getEmoji(new Date('1 march 2026')); // "🌔"

getIllumination(date)

Returns the fraction of the moon illuminated.

  • Parameters: date (Date object)
  • Returns: number — 0–1
  • Example:
getIllumination(new Date("2026-04-01")); // 0.985077512880078
  • Tip: Use toFixed() to round to a preferred number of decimal places:
getIllumination(new Date("2026-04-01")).toFixed(2) // 0.99 

🌕 Moon Phases Reference

| Phase Name | Emoji | Approx. Illumination | |---------------------|-------|--------------------| | New Moon | 🌑 | 0% | | Waxing Crescent | 🌒 | 1–49% | | First Quarter | 🌓 | 50% | | Waxing Gibbous | 🌔 | 51–99% | | Full Moon | 🌕 | 100% | | Waning Gibbous | 🌖 | 51–99% | | Last Quarter | 🌗 | 50% | | Waning Crescent | 🌘 | 1–49% |

⚠️ Notes

The moon phase calculation is based only on the age of the moon, not precise astronomical positions. This means that near phase transitions, the result may be slightly off compared to astronomical data.

🎯 Features

  • 🌙 Moon phase calculation from date
  • 😀 Emoji support
  • 📊 Illumination fraction
  • ⚡ Lightweight and dependency-free

🧮 How it works

This library calculates moon phases based on the age of the moon (days since the last new moon).

  1. Convert the given date to a Julian date.
  2. Calculate the moon’s age in days using a standard lunar cycle (synodic month ≈ 29.53 days).
  3. Determine the phase by comparing the age to thresholds for each phase:

| Moon Phase | Moon age | | --------------- | --------------- | | New Moon | < 1.84566173161 | | Waxing Crescent | < 5.53698519483 | | First Quarter | < 9.22830865805 | | Waxing Gibbous | < 12.91963212127| | Full Moon | < 16.61095558449| | Waning Gibbous | < 20.30227904771| | Last Quarter | < 23.99360251093| | Waning Crescent | < 29.530589 |

  1. Compute illumination fraction with the formula:

    illumination = (1 - cos(phaseAngle)) / 2 where phaseAngle = 2π * moonAge / 29.53

(For more details on the calculation method see docs/logic.md.)

📄 License

MIT