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

emoji-moons

v1.1.1

Published

获取指定日期的月亮信息和对应的emoji,包括月相、月龄等数据

Readme

Emoji Moons

一个轻量级 TypeScript 库,用于获取指定日期的月亮信息,包括月相、月龄和对应的 emoji 符号。

NPM License Types

特性

  • 🌕 获取任意日期的月相信息
  • 🚀 轻量级实现,零依赖
  • 📝 完整的 TypeScript 类型支持
  • 🌍 国际化支持(中文描述)
  • ⚡ 简单易用的 API

安装

使用 npm 安装:

npm install emoji-moons

使用 yarn 安装:

yarn add emoji-moons

快速开始

import { moon } from 'emoji-moons';

// 获取今天的月亮信息
const todayMoon = moon();
console.log(todayMoon);
/*
{
  date: 2024-05-20T00:00:00.000Z,
  phase: 'full-moon',
  emoji: '🌕',
  description: '满月 - 整个月亮可见,地球位于太阳和月亮之间',
  age: 15.2
}
*/

使用方法

基本使用

import { moon } from 'emoji-moons';

// 获取今天的月亮信息
const todayMoon = moon();
console.log(todayMoon.emoji); // 🌕

指定日期

// 使用日期字符串
const moonInfo1 = moon('2023-12-25');

// 使用不同格式的日期字符串
const moonInfo2 = moon('January 1, 2024');

// 使用Date对象
const moonInfo3 = moon(new Date(2024, 0, 1));

// 输出示例
console.log(moonInfo1);
/*
{
  date: 2023-12-25T00:00:00.000Z,
  phase: 'waning-crescent',
  emoji: '🌘',
  description: '残月 - 接近新月,只有一小部分月亮可见',
  age: 27.3
}
*/

TypeScript 类型支持

import { moon, MoonInfo, MoonPhase } from 'emoji-moons';

const moonInfo: MoonInfo = moon();
const phase: MoonPhase = moonInfo.phase;

// MoonPhase 类型包括:
// 'new-moon' | 'waxing-crescent' | 'first-quarter' | 'waxing-gibbous' 
// 'full-moon' | 'waning-gibbous' | 'last-quarter' | 'waning-crescent'

API 参考

moon(date?: string | Date): MoonInfo

获取指定日期的月亮信息。

参数

  • date (可选): 可以是日期字符串(如 '2023-10-17')、Date 对象,或不提供(默认使用当前日期)

返回值

返回一个包含以下属性的对象:

| 属性 | 类型 | 描述 | |------|------|------| | date | Date | 计算使用的日期(UTC 时间) | | phase | MoonPhase | 月相标识符 | | emoji | string | 对应的月亮 emoji | | description | string | 月相的中文描述 | | age | number | 月龄(月亮从新月开始的天数,0-30 之间) |

月相类型

| 月相 | 标识符 | Emoji | 描述 | |------|--------|-------|------| | 新月 | new-moon | 🌑 | 月亮不可见,月球位于地球和太阳之间 | | 眉月 | waxing-crescent | 🌒 | 新月之后,可看到一小部分月亮 | | 上弦月 | first-quarter | 🌓 | 月亮右半部可见,呈半圆形 | | 盈凸月 | waxing-gibbous | 🌔 | 超过一半的月亮可见,正在接近满月 | | 满月 | full-moon | 🌕 | 整个月亮可见,地球位于月球和太阳之间 | | 亏凸月 | waning-gibbous | 🌖 | 满月之后,超过一半的月亮可见但正在变小 | | 下弦月 | last-quarter | 🌗 | 月亮左半部可见,呈半圆形 | | 残月 | waning-crescent | 🌘 | 接近新月,只有一小部分月亮可见 |

错误处理

当传入无效的日期时,函数会抛出错误:

try {
  const invalidMoon = moon('invalid-date');
} catch (error) {
  console.error(error.message); // "无效的日期字符串: invalid-date"
}

使用场景

  • 📅 日历应用中的月相显示
  • 🌿 农业应用中的农历信息
  • 🎨 设计项目中的天文元素
  • 📚 教育应用中的天文知识展示
  • 📱 移动应用中的日期装饰元素

许可证

MIT


注意:月龄计算使用简化算法,可能存在 ±1 天的误差。如需更高精度,请参考专业的天文计算库。