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

@blcklab/luna

v0.1.4

Published

Astronomy engine for moon phases, moonrise, moonset, and lunar calculations

Readme

Luna

A JavaScript/TypeScript library for lunar calculations

v0.1.4 — Comprehensive lunar position, phase, and timing calculations.

@blcklab/luna provides moon position, direction vectors, phase, illumination, rise/set times, and tide estimates based on observer coordinates and time.

The library runs entirely client-side and has no external dependencies or API requirements.

It can be used alongside @blcklab/helios for combined solar and lunar simulation.


Use Cases

  • Night sky simulation
  • 3D scene lighting
  • Game day/night cycles
  • Astronomical visualization
  • Tidal prediction

Features

Position

Calculate altitude and azimuth relative to an observer's latitude and longitude.

import { luna } from "@blcklab/luna"

const moon = luna(14.5995, 120.9842) // Imus, Philippines

const position = moon.position()
console.log(position)
// => { altitude: 57.9, azimuth: 234.1, distance: 384400, ... }

Direction Vector

Get x, y, and z coordinates ready for 3D positioning or directional lighting.

const data = moon.now()
console.log(data.direction)
// => { x: -0.43, y: 0.84, z: -0.31 }

Phase and Illumination

Track the current lunar phase, illumination percentage, and age.

const state = moon.now()

console.log(state.phase)
// => { name: "first-quarter", age: 7.4, angle: 89.9, illumination: 0.49, illuminationPercent: 49 }

console.log(state.isVisible)
// => true

Supported Phases: new, waxing-crescent, first-quarter, waxing-gibbous, full, waning-gibbous, last-quarter, waning-crescent

Rise & Set Times

Get moonrise and moonset for a given day and location.

const state = moon.at(new Date("2024-06-01"))

console.log(state.times)
// => { rise: Date(2024-06-01T18:45Z), set: Date(2024-06-02T06:30Z), alwaysUp: false, neverUp: false }

Lunar Distance

Distance from Earth's center in kilometers, useful for determining perigee/apogee and tide strength.

const state = moon.now()
console.log(state.position.distance)
// => 384400

Alignment & Tides

Check moon-sun alignment and estimate tidal strength.

const state = moon.now()

console.log(state.alignment)
// => { angle: 45.2, isNewMoon: false, isFullMoon: false }

console.log(state.tide)
// => { type: "spring", relativeStrength: 1.2 }

Three.js Example

Update a moon mesh position relative to the observer's sky dome:

const moon = luna(lat, lng).now()

moonMesh.position.set(
  moon.direction.x * 1000,
  moon.direction.y * 1000,
  moon.direction.z * 1000
)

// Optional: scale by illumination
moonMesh.material.opacity = moon.phase.illumination

API

luna(lat, lng)

Create a calculator bound to a fixed observer location.

const moon = luna(40.7128, -74.0060) // NYC

moon.now()              // Current moon data
moon.at(date)           // Moon data for a specific date
moon.getMoon(date?)     // Same as .at()
moon.position(date?)    // Just position info

Return Object (MoonTimes)

{
  position: {
    altitude: number          // Degrees above horizon
    azimuth: number           // Degrees from north
    distance: number          // km
    angularDiameter: number   // Degrees
    brightLimbAngle: number   // Degrees
  }
  
  direction: {
    x: number                 // East component
    y: number                 // Up component
    z: number                 // North component
  }
  
  phase: {
    name: MoonPhaseName
    age: number               // Days into cycle
    illumination: number      // 0.0–1.0
    illuminationPercent: number
    angle: number             // Degrees (0–360)
  }
  
  times: {
    rise: Date | null
    set: Date | null
    alwaysUp: boolean
    neverUp: boolean
  }
  
  alignment: {
    angle: number             // Moon–sun angle (0–360)
    isNewMoon: boolean
    isFullMoon: boolean
  }
  
  tide: {
    type: "spring" | "neap" | "normal"
    relativeStrength: number  // 0.5–1.5
  }
  
  isVisible: boolean          // altitude > 0°
}

Installation

npm install @blcklab/luna

Notes

  • All times are in UTC.
  • Altitude includes atmospheric refraction and lunar parallax corrections.
  • Tide estimates are qualitative and based on alignment and distance; not a full hydrodynamic model.
  • Best accuracy within ±100 years of J2000 (2000-01-01).

Roadmap

v0.1.4 (Current)

  • ✓ Moon position (altitude, azimuth, distance)
  • ✓ Direction vectors
  • ✓ Phase calculation & illumination
  • ✓ Moonrise / moonset times
  • ✓ Moon-sun alignment (new/full moon detection)
  • ✓ Tidal strength estimation

v0.2.0 (Planned)

  • Lunar eclipse simulation
  • Higher-precision algorithms
  • Performance optimizations

License

MIT • Made by BLCKLAB