Browse Source

feat: 增加 json 支持

Yaavi 1 year ago
parent
commit
102ad47d14
3 changed files with 57 additions and 11 deletions
  1. 13 5
      README.en.md
  2. 10 6
      README.md
  3. 34 0
      scripts/build.ts

+ 13 - 5
README.en.md

@@ -6,15 +6,23 @@
 
 
 > Translated by ChatGPT-4, PRs are welcome.
 > Translated by ChatGPT-4, PRs are welcome.
 
 
-This project provides a series of functions for querying Chinese holidays, compensatory holidays, working days, and 24 solar terms, as well as for the conversion between the lunar and solar calendars. By using these functions, users can easily check the status of a specified date, get holidays or workdays within a date range, and find specific workdays. Additionally, the project supports querying the dates of the 24 solar terms, helping users understand the timing of traditional Chinese solar terms.
+This project provides a set of functions for querying Chinese holidays, adjustment days, workdays, the 24 solar terms, and conversions between the lunar and solar calendars. Chinese holidays will be updated according to the releases from the State Council.
 
 
-Description:
-1. Holidays: Supports from 2004 to 2024, including the extended Spring Festival in 2020.
-2. Lunar Dates: Supports from 1900 to 2100.
++ **Holidays**: Supports the years 2004 to 2024, including the extended Spring Festival of 2020.
++ **24 Solar Terms**: Supports the years 1900 to 2100.
++ **Lunar Days**: Supports the years 1900 to 2100.
+
+## For non-JS projects, you can use the JSON file
+
+A `JSON` file of Chinese holidays is provided and can be directly referenced through this link: [chinese-days.json](https://cdn.jsdelivr.net/npm/chinese-days/dist/chinese-days.json).
 
 
 ## Quick Start
 ## Quick Start
 
 
-Include directly in your browser:
+Recommended method: Directly include it in your browser, which will update according to the releases from the State Council.
+
+---
+
+This translation captures the key details and instructions for using the project while ensuring clarity and accuracy.
 
 
 ```html
 ```html
 <script src="https://cdn.jsdelivr.net/npm/chinese-days/dist/index.min.js"></script>
 <script src="https://cdn.jsdelivr.net/npm/chinese-days/dist/index.min.js"></script>

+ 10 - 6
README.md

@@ -4,15 +4,19 @@
 ![GitHub License](https://img.shields.io/github/license/vsme/chinese-days)
 ![GitHub License](https://img.shields.io/github/license/vsme/chinese-days)
 [![README](https://img.shields.io/badge/README-English-brightgreen.svg)](https://github.com/vsme/chinese-days/blob/main/README.en.md)
 [![README](https://img.shields.io/badge/README-English-brightgreen.svg)](https://github.com/vsme/chinese-days/blob/main/README.en.md)
 
 
-本项目提供了一系列用于查询中国节假日、调休日、工作日、24节气查询,农历阳历互转的函数。通过使用这些函数,用户可以方便地检查指定日期的状态,获取日期范围内的节假日或工作日,并查找特定的工作日。此外,项目还支持查询二十四节气的日期,帮助用户了解中国传统节气的时间安排
+本项目提供了一系列用于查询中国节假日、调休日、工作日、24节气、以及农历阳历互转的函数,中国节假日会跟随国务院发布进行更新
 
 
-说明:
-1. 节假日:支持 2004年 至 2024年,包括 2020年 的春节延长。
-2. 农历日:支持 1900年 至 2100年。
++ **节假日**:支持 2004年 至 2024年,包括 2020年 的春节延长
++ **24节气**:支持 1900年 至 2100年。
++ **农历日**:支持 1900年 至 2100年。
+
+## 非 `JS` 语言
+
+提供了中国节假日的 `JSON` 文件,通过链接 [chinese-days.json](https://cdn.jsdelivr.net/npm/chinese-days/dist/chinese-days.json) 可以直接引用。
 
 
 ## 快速开始
 ## 快速开始
 
 
-直接浏览器引入
+推荐方式:直接浏览器引入,会跟随国务院发布更新。
 
 
 ```html
 ```html
 <script src="https://cdn.jsdelivr.net/npm/chinese-days/dist/index.min.js"></script>
 <script src="https://cdn.jsdelivr.net/npm/chinese-days/dist/index.min.js"></script>
@@ -22,7 +26,7 @@
 </script>
 </script>
 ```
 ```
 
 
-安装
+其他方式安装
 
 
 ```sh
 ```sh
 npm i chinese-days
 npm i chinese-days

+ 34 - 0
scripts/build.ts

@@ -0,0 +1,34 @@
+import fs from "fs";
+import { Holiday } from "../src";
+import dayjs from "../src/utils/dayjs";
+import {
+  holidays as compressedHolidays,
+  workdays as compressedWorkdays,
+  inLieuDays as compressedInLieuDays,
+} from "../src/holidays/constants";
+
+const getOriginal = (dates: Record<string, number[]>) => {
+  const dateMap: Map<string, Holiday> = new Map();
+  Object.keys(dates).forEach((key) => {
+    const days = dates[key];
+    days.forEach((n) => {
+      dateMap.set(
+        dayjs("2000-01-01").add(n, "day").format("YYYY-MM-DD"),
+        Holiday[key as keyof typeof Holiday]
+      );
+    });
+  });
+  return Object.fromEntries(dateMap);
+};
+
+const holidays = getOriginal(compressedHolidays);
+const workdays = getOriginal(compressedWorkdays);
+const inLieuDays = getOriginal(compressedInLieuDays);
+
+const tsContent = JSON.stringify({ holidays, workdays, inLieuDays });
+
+// 保存到 ./dist/chinese-days.json 文件
+fs.writeFile("./dist/chinese-days.json", tsContent, (err) => {
+  if (err) throw err;
+  console.log("The json file has been saved!");
+});