New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

util-holidays

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

util-holidays - npm Package Compare versions

Comparing version 1.0.0 to 1.0.2

11

lib/holidays-data.d.ts

@@ -0,1 +1,5 @@

export interface Options {
onLine: boolean;
key: string;
}
export declare enum DayType {

@@ -17,4 +21,9 @@ '工作日' = 1,

holiday: Holiday[];
constructor();
key: string;
onLine: boolean;
constructor(option?: Options);
getDateInfo(date: string): Holiday | undefined;
checkData(): void;
getData(): void;
offOnLine(): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HolidaysData = exports.DayType = void 0;
var superagent_1 = require("superagent");
var DayType;

@@ -12,11 +13,39 @@ (function (DayType) {

var HolidaysData = /** @class */ (function () {
function HolidaysData() {
function HolidaysData(option) {
this.holiday = [];
if (this.holiday.length === 0) {
this.holiday = Holiday_2020_2021;
this.key = '';
this.onLine = false;
this.holiday = Holiday_2020_2021;
if (option === null || option === void 0 ? void 0 : option.onLine) {
this.onLine = option.onLine;
this.key = option.key;
this.checkData();
}
}
HolidaysData.prototype.getDateInfo = function (date) {
if (this.onLine) {
this.checkData();
}
return this.holiday.find(function (o) { return o.date === date; });
};
HolidaysData.prototype.checkData = function () {
var year = new Date().getFullYear() + '';
if (!this.holiday.some(function (o) { return o.date.toString().includes(year); })) {
this.getData();
}
};
HolidaysData.prototype.getData = function () {
var _this = this;
var url = "https://util-holidays.beituyun.com/v1/queryData?key=" + this.key;
superagent_1.get(url)
.then(function (res) {
if (res.body && res.body.flag === 1) {
_this.holiday = res.body.data;
}
})
.catch(function (e) { return console.error(e); });
};
HolidaysData.prototype.offOnLine = function () {
this.onLine = false;
};
return HolidaysData;

@@ -23,0 +52,0 @@ }());

2

lib/index.js

@@ -19,3 +19,3 @@ "use strict";

isWeekend: util_1.isWeekend,
isStatutoryHoliday: util_1.isStatutoryHoliday
isStatutoryHoliday: util_1.isStatutoryHoliday,
};

@@ -1,2 +0,3 @@

import { Holiday } from './holidays-data';
import { Holiday, Options } from './holidays-data';
export declare const config: (option?: Options | undefined) => void;
export declare const getDayInfo: (date: string | Date | number) => Holiday;

@@ -3,0 +4,0 @@ export declare const isWorkingDay: (date: string | Date | number) => boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isStatutoryHoliday = exports.isWeekend = exports.isWorkingDay = exports.getDayInfo = void 0;
exports.isStatutoryHoliday = exports.isWeekend = exports.isWorkingDay = exports.getDayInfo = exports.config = void 0;
var holidays_data_1 = require("./holidays-data");

@@ -19,3 +19,3 @@ var holidays = new holidays_data_1.HolidaysData();

'q+': Math.floor((d.getMonth() + 3) / 3),
'S': d.getMilliseconds()
S: d.getMilliseconds(),
};

@@ -38,2 +38,11 @@ if (/(y+)/.test(fmt)) {

};
var config = function (option) {
if (option === null || option === void 0 ? void 0 : option.onLine) {
holidays = new holidays_data_1.HolidaysData(option);
}
else {
holidays.offOnLine();
}
};
exports.config = config;
var getDayInfo = function (date) {

@@ -44,3 +53,3 @@ var d = dateFormat(date);

date: d,
week: week
week: week,
};

@@ -47,0 +56,0 @@ if (['星期六', '星期日'].includes(week)) {

{
"name": "util-holidays",
"version": "1.0.0",
"version": "1.0.2",
"description": "A Chinese holiday util",

@@ -9,3 +9,3 @@ "main": "lib/index.js",

"type": "git",
"url": "git+https://github.com/oak-c/chinese-holidays.git"
"url": "git+https://github.com/oak-c/util-holidays.git"
},

@@ -32,2 +32,3 @@ "keywords": [

"@types/jest": "^26.0.15",
"@types/superagent": "^4.1.10",
"coveralls": "^3.1.0",

@@ -41,3 +42,6 @@ "jest": "^26.6.3",

"lib/**/*"
]
],
"dependencies": {
"superagent": "^6.1.0"
}
}
# 法定节假日查询(中国,定期维护)
![](https://img.shields.io/badge/Language-TypeScript-orange.svg)
[![Build Status](https://travis-ci.com/oak-c/chinese-holidays.svg?branch=main)](https://travis-ci.com/oak-c/chinese-holidays)
[![Coverage Status](https://coveralls.io/repos/github/oak-c/chinese-holidays/badge.svg)](https://coveralls.io/github/oak-c/chinese-holidays)
[![Build Status](https://travis-ci.com/oak-c/util-holidays.svg?branch=main)](https://travis-ci.com/oak-c/util-holidays)
[![Coverage Status](https://coveralls.io/repos/github/oak-c/util-holidays/badge.svg)](https://coveralls.io/github/oak-c/util-holidays)
### 使用方法
1. 支持离线、在线两种模式;
2. 因每年11月份公布下一年假期,所以离线模式需要每年更新版本,当前版本不属于当年时,会报错提示;
3. 在线模式首次启动或每年12月内,会检查本地数据,若不是当年,则调用接口更新本地数据,(因此若有出网白名单限制的话,请将此API放行:);(离线已含2021年,但在线模式未发布)
### 安装
```bash
# 安装
npm i chinese-holidays
# 或者 yarn add chinese-holidays
npm i util-holidays
# 或者 yarn add util-holidays
```
### 支持离线、在线两种模式,支持typescript
#### 离线模式(已支持2021年)
1. 因每年11月份左右公布下一年假期,所以离线模式需要每年更新版本,当前版本不属于当年时,会报错提示;
```javascript
import { getDayInfo, isWorkingDay, isWeekend, isStatutoryHoliday } from 'chinese-holidays'
import { getDayInfo, isWorkingDay, isWeekend, isStatutoryHoliday } from 'util-holidays'
```

@@ -41,7 +40,23 @@ ```javascript

#### 在线模式
1. 在线模式首次启动或每次调用时,会检查本地数据,若不是当年,则调用接口更新本地数据;
2. 若有出网白名单限制的话,请将此API放行:https://util-holidays.beituyun.com/v1/queryData
3. 在线模式需要获取key并进行配置:
```javascript
// key获取方式为:https://util-holidays.beituyun.com/v1/creatKey?phone=你的手机号
import { config } from 'util-holidays'
config({
onLine: true,
key: 'your key'
})
```
4. 在线离线支持随时切换,您可指定某一时刻才联网更新,并且更新后可关闭在线模式;
5. 其他用法同离线模式。
### 其他说明
1. 另提供免费的开放接口供大家使用,API地址:
2. 使用方法:
- GET:
- POST:
3. 接口资源有限,因此限制每个key可以最高调用10次/s;
1. 另提供免费的开放接口供大家使用,API地址:https://util-holidays.beituyun.com/v1/
2. 使用方法(均支持POST/GET,POST使用body,GET使用query):
- 获取节假日数据:/queryData, 入参key;
- 获取日期信息,同getDayInfo:/getDayInfo, 入参key、date;
- 创建key:/creatKey, 入参phone
3. 接口资源有限,因此限制每个key可以最高调用50次/s;
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