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 🙏

© 2024 – Pkg Stats / Ryan Hefner

lunar-lite

v0.2.3

Published

精简版的农历和阳历日期转换库。

Downloads

232

Readme

📦 lunar-lite

精简版的农历和阳历日期转换库。

Maintainability Codecov npm Codecov npm GitHub GitHub code size in bytes Package Quality


安装

npm i lunar-lite -S

你也可以用你熟悉的任何包管理软件安装依赖。

类型定义

/**
 * 农历日期对象
 *
 * @property
 * - lunarYear 年
 * - lunarMonth 月
 * - lunarDay 日
 * - isLeap 月份是否闰月
 *
 * @function toString() 输出 YYYY-M-D 或 农历中文 字符串
 */
export type LunarDate = {
  /** 农历年 */
  lunarYear: number;
  /** 农历月 */
  lunarMonth: number;
  /** 农历日 */
  lunarDay: number;
  /** 是否闰月 */
  isLeap: boolean;
  /**
   * 转化为字符串
   *
   * @param toCnStr 是否使用中文字符串, 若该参数为false则字符串中不会携带闰月信息
   * @returns string
   * @example
   * lunarYear = 2023;
   * lunarMonth = 6;
   * lunarDay = 12;
   * isLeap = true;
   *
   * toString(); // 2023-6-12
   * toString(true); // 二〇二三年闰二月十一
   */
  toString: (toCnStr?: boolean) => string;
};

/**
 * 阳历日期对象
 *
 * @property
 * - solarYear 年
 * - solarMonth 月
 * - solarDay 日
 *
 * @function toString() 将对象以 YYYY-M-D 格式字符串输出
 */
export type SolarDate = {
  /** 公历年 */
  solarYear: number;
  /** 公历月 */
  solarMonth: number;
  /** 公历日 */
  solarDay: number;
  /**
   * 转化为字符串
   *
   * @returns string
   * @example
   * solarYear = 2023;
   * solarMonth = 6;
   * solarDay = 12;
   *
   * toString(); // 2023-6-12
   */
  toString: () => string;
};

方法定义

/**
 * 公历转农历,年份需要在【1900~2100】之间,并且日期必须在1900-1-31之后
 *
 * @param dateStr 公历日期 YYYY-MM-DD格式的字符串或者Date对象
 * @returns LunarDate
 */
type solar2lunar = (dateStr: string | Date) => LunarDate;

/**
 * 农历转公历
 *
 * @param dateStr 农历日期 YYYY-MM-DD
 * @param isLeapMonth 是否闰月,若该月不是闰月,会忽略该参数
 * @returns SolarDate
 */
type lunar2solar = (dateStr: string, isLeapMonth?: boolean) => SolarDate;

使用方法

import {solar2lunar, lunar2solar} from 'lunar-lite';

// 农历转公历
// 当该月不是闰月的时候,第二个参数会被忽略
const solarDate = lunar2solar('1990-10-10', true);

// 公历转农历
const lunarDate = solar2lunar('2023-10-23');