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

festival_chn

v0.1.3

Published

## 介绍 `festival_chn` 无任何依赖,无需异步请求,满足对日期的假期检测,判断是否为调休日等。

Downloads

24

Readme

Festival_chn

Festival_chn 是一个简单易用的中国节日和法定节假日判断工具库,支持浏览器和 Node.js 环境。它提供了多种 API 来查询某一天是否是节日和法定节假日,获取假期名称等功能,以及查询指定日期范围内的假期信息和天数等。它无需依赖其它库和异步请求,数据源直接内置在库文件中。

安装

npm install festival_chn

使用

浏览器中使用

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Festival_chn Example</title>
  </head>
  <body>
    <script src="./dist/festival.js"></script>
    <script>
      const getSwapHolidaysInRange = Festival.getSwapHolidaysInRange(20230101, 20230131)
      console.log('getSwapHolidaysInRange ===>', getSwapHolidaysInRange)
    </script>
  </body>
</html>

在 Node.js 中使用

const { Festival_chn } = require('festival_chn');
const festival = new Festival();
const dayInfo = festival.day(20220101);
console.log(dayInfo.name); // "元旦"

查询某天的节日和假期信息

const festival = new Festival();
const dayInfo = festival.day(20220101);
console.log(dayInfo);

{
  date: 20220101,
  name: "元旦",
  isHoliday: true,
  isLegal: true,
  isSwap: false
}

返回的结果对象包含以下字段:

|字段名称|字段类型|说明| |---|---|---| |date|Number|八位数字组成的年月日| |name|String|节日名称| |isHoliday|Boolean|是否为假期节假日| |isLegal|Boolean|是否为法定节假日| |isSwap|Boolean|是否为调休日|

查询某天的假期名称

const festival = new Festival();
const name = festival.name(20220101);
console.log(name); // "元旦"

判断某天是否为节日和假期

const festival = new Festival();
const isHoliday = festival.isHoliday(20220101);
console.log(isHoliday); // true

const isLegal = festival.isLegal(20220101);
console.log(isLegal); // true

const isSwap = festival.isSwap(20220101);
console.log(isSwap); // false

查询指定日期范围内的假期信息

const festival = new Festival();
const daysInRange = festival.getDaysInRange(20230101, 20230131);
console.log(daysInRange);

查询指定日期范围内的法定假日

const festival = new Festival();
const legalHolidays = festival.getLegalHolidaysInRange(20230101, 20230131);
console.log(legalHolidays);

查询指定日期范围内的调休日

const festival = new Festival();
const count = festival.getHolidaysInRange(20230101, 20230131);
console.log(count);

查询指定日期范围内的假期天数

const festival = new Festival();
const count = festival.countHolidaysInRange(20230101, 20230131);
console.log(count);

更新计划

  • setStartDate(year):设置数据源的起始年份,默认为 1970。一般情况下不需要调用此方法。
  • setEndDate(year):设置数据源的终止年份,默认为 2050。一般情况下不需要调用此方法。
  • getDayInfo(date):查询指定日期的节日和假期信息,与 day 方法相同。

数据源

Festival_chn 内置了中国节日和法定节假日的数据源,其基本来源于互联网上公开的数据。如果你需要更新数据源,可以修改 chn文件夹下的三个文件。

注意事项

由于中国国家法定节假日的调休规则相对复杂,如果需要进行严格的判断和计算,请慎重使用本库。例如,如何判断 2021 年端午节和中秋节的调休情况,需要考虑到国务院发布的调休政策和各省市的具体实施情况,需要一定的研究和验证。本库只能作为预估和参考之用,不保证其完全正确性和准确性,使用者应自行验证并承担风险。

License

MIT