Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

legal-holidays-cn

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

legal-holidays-cn - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

14

dist/index.d.ts
interface Holidays {
desc: string;
date: string[];
days: number;
readonly desc: string;
readonly date: string[];
readonly days: number;
}
export declare const isHoliday: (val: string) => boolean;
export declare const getHolidaysDetailByYears: () => Holidays[];
export declare const getHolidaysByYears: () => string[];
export declare const getHolidayInfo: (val: string) => any;
export declare const isHoliday: (val: string, year?: "2023" | "2022") => boolean;
export declare const getHolidaysByYears: (year?: "2023" | "2022") => string[];
export declare const getHolidaysDetailByYears: (year?: "2023" | "2022") => Holidays[];
export declare const getHolidayInfo: (val: string, year?: "2023" | "2022") => any;
export {};

@@ -14,4 +14,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getHolidayInfo = exports.getHolidaysByYears = exports.getHolidaysDetailByYears = exports.isHoliday = void 0;
var holidays = [
exports.getHolidayInfo = exports.getHolidaysDetailByYears = exports.getHolidaysByYears = exports.isHoliday = void 0;
var holiday2022 = [
{ desc: "元旦", date: ["20220101", "20220102", "20220103"], days: 3 },

@@ -53,11 +53,68 @@ {

];
var holiday2023 = [
{ desc: "元旦", date: ["20221231", "20230101", "20230102"], days: 3 },
{
desc: "春节",
date: [
"20230121",
"20230122",
"20230123",
"20230124",
"20230125",
"20230126",
"20230127",
],
days: 7,
},
{ desc: "清明节", date: ["20230405"], days: 3 },
{
desc: "劳动节",
date: ["20230429", "20230430", "20230501", "20230502", "20230503"],
days: 5,
},
{ desc: "端午节", date: ["20230622", "20230623", "20230624"], days: 3 },
{ desc: "中秋节", date: ["20230929", "20230930"], days: 2 },
{
desc: "国庆节",
date: [
"20231001",
"20231002",
"20231003",
"20231004",
"20231005",
"20231006",
],
days: 6,
},
];
var holidays = [];
var allHoliday = [];
holidays.forEach(function (item) { return (allHoliday = allHoliday.concat(item.date)); });
var isHoliday = function (val) { return allHoliday.includes(val); };
function init(year) {
if (year === void 0) { year = "2023"; }
holidays = [];
allHoliday = [];
holidays = year === "2023" ? holiday2023 : holiday2022;
holidays.forEach(function (item) { return (allHoliday = allHoliday.concat(item.date)); });
}
var isHoliday = function (val, year) {
if (year === void 0) { year = "2023"; }
init(year);
return allHoliday.includes(val);
};
exports.isHoliday = isHoliday;
var getHolidaysDetailByYears = function () { return holidays; };
var getHolidaysByYears = function (year) {
if (year === void 0) { year = "2023"; }
init(year);
return allHoliday;
};
exports.getHolidaysByYears = getHolidaysByYears;
var getHolidaysDetailByYears = function (year) {
if (year === void 0) { year = "2023"; }
init(year);
return holidays;
};
exports.getHolidaysDetailByYears = getHolidaysDetailByYears;
var getHolidaysByYears = function () { return allHoliday; };
exports.getHolidaysByYears = getHolidaysByYears;
var getHolidayInfo = function (val) {
var getHolidayInfo = function (val, year) {
if (year === void 0) { year = "2023"; }
init(year);
var isHoliday = false;

@@ -64,0 +121,0 @@ var _item = {};

{
"name": "legal-holidays-cn",
"version": "1.0.5",
"version": "1.0.6",
"description": "Judge whether a data is a legal holiday in China",

@@ -5,0 +5,0 @@ "main": "src/index.js",

## Introduction
判断某个日期是否为国家法定节假日及详细信息(目前仅支持 2022 年)
判断某个日期是否为国家法定节假日及详细信息(目前支持 2023、2022 年)。默认查询 2023 年,如需查询 2022 年数据,api 传入参数'2022'

@@ -19,15 +19,24 @@ ## Installation

`isHoliday('20221001') // true`
**isHoliday('20231001')** // true
**isHoliday('20221001','2022')** // true
### 获取 2022 年所有法定节假日 日期数组
### 获取 2023 年所有法定节假日 日期数组
`getHolidaysByYears() // ["20220101","20220102","20220103",...,"20221007"]`
**getHolidaysByYears()**
// ["20221231","20230101","20230102",...,"20231006"]
**getHolidaysByYears('2022')**
// ["20220101","20220102","20220103",...,"20221007"]
### 获取 2022 年所有法定节假日日期详细数组
### 获取 2023 年所有法定节假日日期详细数组
`getHolidaysDetailByYears() `
`// [{desc: '元旦', date: ['20220101', '20220102', '20220103'], days: 3}, {…}, {…}, {…}, {…}, {…}, {…}]`
**getHolidaysDetailByYears()**
// [{desc: '元旦', date: ['20221231', '20230101', '20230102'], days: 3}, {…}, {…}, {…}, {…}, {…}, {…}]
**getHolidaysDetailByYears('2022')**
// [{desc: '元旦', date: ['20220101', '20220102', '20220103'], days: 3}, {…}, {…}, {…}, {…}, {…}, {…}]
### 获取某日期详细数据
`getHolidayInfo("20220501") // {isHoliday: true, desc: '中秋节', date: Array(3), days: 3}`
**getHolidayInfo("20230501")**
// {isHoliday: true, desc: '劳动节', date: Array(5), days: 5}
**getHolidayInfo("20220501",'2022')**
// {isHoliday: true, desc: '劳动节', date: Array(5), days: 5}
interface Holidays {
desc: string;
date: string[];
days: number;
readonly desc: string;
readonly date: string[];
readonly days: number;
}
const holidays: Holidays[] = [
const holiday2022: Holidays[] = [
{ desc: "元旦", date: ["20220101", "20220102", "20220103"], days: 3 },

@@ -44,12 +44,67 @@ {

];
const holiday2023: Holidays[] = [
{ desc: "元旦", date: ["20221231", "20230101", "20230102"], days: 3 },
{
desc: "春节",
date: [
"20230121",
"20230122",
"20230123",
"20230124",
"20230125",
"20230126",
"20230127",
],
days: 7,
},
{ desc: "清明节", date: ["20230405"], days: 3 },
{
desc: "劳动节",
date: ["20230429", "20230430", "20230501", "20230502", "20230503"],
days: 5,
},
{ desc: "端午节", date: ["20230622", "20230623", "20230624"], days: 3 },
{ desc: "中秋节", date: ["20230929", "20230930"], days: 2 },
{
desc: "国庆节",
date: [
"20231001",
"20231002",
"20231003",
"20231004",
"20231005",
"20231006",
],
days: 6,
},
];
let holidays: Holidays[] = [];
let allHoliday: string[] = [];
holidays.forEach((item) => (allHoliday = allHoliday.concat(item.date)));
export const isHoliday = (val: string) => allHoliday.includes(val);
function init(year: "2023" | "2022" = "2023") {
holidays = [];
allHoliday = [];
holidays = year === "2023" ? holiday2023 : holiday2022;
holidays.forEach((item) => (allHoliday = allHoliday.concat(item.date)));
}
export const getHolidaysDetailByYears = () => holidays;
export const isHoliday = (val: string, year: "2023" | "2022" = "2023") => {
init(year);
return allHoliday.includes(val);
};
export const getHolidaysByYears = () => allHoliday;
export const getHolidaysByYears = (year: "2023" | "2022" = "2023") => {
init(year);
return allHoliday;
};
export const getHolidayInfo = (val: string) => {
export const getHolidaysDetailByYears = (year: "2023" | "2022" = "2023") => {
init(year);
return holidays;
};
export const getHolidayInfo = (val: string, year: "2023" | "2022" = "2023") => {
init(year);
let isHoliday = false;

@@ -56,0 +111,0 @@ let _item: Holidays | any = {};

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc