hsu-utils 0.0.53 → 0.0.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -11
- package/dist/hsu-utils.js +14 -4
- package/dist/hsu-utils.min.js +1 -1
- package/dist/hsu-utils.min.js.LICENSE.txt +2 -2
- package/es/DownloadFile/index.d.ts +7 -1
- package/es/DownloadFile/index.js +8 -1
- package/es/GetDateRange/index.js +2 -0
- package/lib/DownloadFile/index.d.ts +7 -1
- package/lib/DownloadFile/index.js +8 -1
- package/lib/GetDateRange/index.js +2 -0
- package/package.json +16 -3
package/README.md
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# hsu-utils
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/hsu-utils)
|
|
4
|
+
[](./LICENSE)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
常用前端工具集:深拷贝、类型判断、相等比较、文件下载、PDF 渲染、日期范围、控制台表格、字符串尺寸测量等,TypeScript 编写,零业务依赖。
|
|
6
7
|
|
|
7
8
|
## 安装
|
|
8
9
|
|
|
9
|
-
```
|
|
10
|
-
npm install
|
|
10
|
+
```bash
|
|
11
|
+
npm install hsu-utils
|
|
11
12
|
# 或
|
|
12
13
|
yarn add hsu-utils
|
|
13
14
|
```
|
|
14
15
|
|
|
15
|
-
##
|
|
16
|
+
## 使用
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { deepCopy, Typeof, getDateRange, downloadFile } from "hsu-utils";
|
|
20
|
+
|
|
21
|
+
const copy = deepCopy({ a: [1, 2, 3] });
|
|
22
|
+
Typeof([], "array"); // true
|
|
23
|
+
getDateRange({ type: "thisWeek", baseDate: "2026-07-17" }); // ['2026-07-12', '2026-07-18'](以周日为一周起点)
|
|
24
|
+
await downloadFile("https://example.com/report.xlsx", "报表.xlsx");
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## API 一览
|
|
16
28
|
|
|
17
29
|
| 方法 | 子方法 | 说明 | 类型 | 备注 |
|
|
18
30
|
| ----------------- | --------------------- | ------------------------------- | --------------------------------------------------------------------------------------------- | -------------------------------- |
|
|
@@ -77,9 +89,9 @@ yarn add hsu-utils
|
|
|
77
89
|
| 参数 | 说明 | 类型 | 默认值 | 备注 |
|
|
78
90
|
| ------------ | ------------ | ------ | ------ | ---- |
|
|
79
91
|
| pdfUrl | pdf 文件地址 | string | - | 必填 |
|
|
80
|
-
| containerId | pdf 容器 id | string |
|
|
81
|
-
| startPageNum | 开始页码 | number |
|
|
82
|
-
| endPageNum | 结束页码 | number |
|
|
92
|
+
| containerId | pdf 容器 id | string | - | 必填 |
|
|
93
|
+
| startPageNum | 开始页码 | number | - | - |
|
|
94
|
+
| endPageNum | 结束页码 | number | - | - |
|
|
83
95
|
| pixelRatio | 像素比例 | number | 2 | - |
|
|
84
96
|
| scale | 缩放 | number | 1 | - |
|
|
85
97
|
|
|
@@ -118,7 +130,7 @@ yarn add hsu-utils
|
|
|
118
130
|
- `past` - 过去
|
|
119
131
|
- `future` - 未来
|
|
120
132
|
- `today` - 当日
|
|
121
|
-
- `thisWeek` -
|
|
133
|
+
- `thisWeek` - 当周(以**周日**为一周起点)
|
|
122
134
|
- `thisMonth` - 当月
|
|
123
135
|
- `thisQuarter` - 当季
|
|
124
136
|
- `thisYear` - 当年
|
|
@@ -137,6 +149,18 @@ yarn add hsu-utils
|
|
|
137
149
|
|
|
138
150
|
注意:当 `hasTime` 为 `true` 时,包含日期部分的格式会自动添加时间部分 `HH:mm:ss`。默认 `hasTime` 为 `false`。时、分、秒单位固定返回 `YYYY-MM-DD HH:mm:ss` 格式。
|
|
139
151
|
|
|
152
|
+
## 开发
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
yarn # 安装依赖
|
|
156
|
+
yarn build # 构建 es/ + lib/ + dist/
|
|
157
|
+
yarn test # 运行单元测试
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 贡献
|
|
161
|
+
|
|
162
|
+
日常开发在 `develop` 分支进行(feature 分支合入 `develop`),`main` 只接受来自 `develop` 的 PR;合入 `main` 后按 `package.json` 版本自动打 tag 并发布 npm。PR 标题遵循 [Conventional Commits](https://www.conventionalcommits.org/)。
|
|
163
|
+
|
|
140
164
|
## License
|
|
141
165
|
|
|
142
|
-
MIT
|
|
166
|
+
[MIT](./LICENSE) © VitaHsu
|
package/dist/hsu-utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
*
|
|
3
|
-
* hsu-utils v0.0.
|
|
3
|
+
* hsu-utils v0.0.55
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* 常用前端工具集:深拷贝、类型判断、相等比较、文件下载、PDF 渲染、日期范围、控制台表格等
|
|
6
6
|
*
|
|
7
7
|
* MIT License
|
|
8
8
|
*
|
|
@@ -58,6 +58,16 @@ eval("!function(t,e){ true?module.exports=e():0}(this,(function(){\"use strict\"
|
|
|
58
58
|
|
|
59
59
|
/***/ }),
|
|
60
60
|
|
|
61
|
+
/***/ "./node_modules/dayjs/plugin/advancedFormat.js":
|
|
62
|
+
/*!*****************************************************!*\
|
|
63
|
+
!*** ./node_modules/dayjs/plugin/advancedFormat.js ***!
|
|
64
|
+
\*****************************************************/
|
|
65
|
+
/***/ (function(module) {
|
|
66
|
+
|
|
67
|
+
eval("!function(e,t){ true?module.exports=t():0}(this,(function(){\"use strict\";return function(e,t){var r=t.prototype,n=r.format;r.format=function(e){var t=this,r=this.$locale();if(!this.isValid())return n.bind(this)(e);var s=this.$utils(),a=(e||\"YYYY-MM-DDTHH:mm:ssZ\").replace(/\\[([^\\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,(function(e){switch(e){case\"Q\":return Math.ceil((t.$M+1)/3);case\"Do\":return r.ordinal(t.$D);case\"gggg\":return t.weekYear();case\"GGGG\":return t.isoWeekYear();case\"wo\":return r.ordinal(t.week(),\"W\");case\"w\":case\"ww\":return s.s(t.week(),\"w\"===e?1:2,\"0\");case\"W\":case\"WW\":return s.s(t.isoWeek(),\"W\"===e?1:2,\"0\");case\"k\":case\"kk\":return s.s(String(0===t.$H?24:t.$H),\"k\"===e?1:2,\"0\");case\"X\":return Math.floor(t.$d.getTime()/1e3);case\"x\":return t.$d.getTime();case\"z\":return\"[\"+t.offsetName()+\"]\";case\"zzz\":return\"[\"+t.offsetName(\"long\")+\"]\";default:return e}}));return n.bind(this)(a)}}}));\n\n//# sourceURL=webpack://hsu-utils/./node_modules/dayjs/plugin/advancedFormat.js?");
|
|
68
|
+
|
|
69
|
+
/***/ }),
|
|
70
|
+
|
|
61
71
|
/***/ "./node_modules/dayjs/plugin/quarterOfYear.js":
|
|
62
72
|
/*!****************************************************!*\
|
|
63
73
|
!*** ./node_modules/dayjs/plugin/quarterOfYear.js ***!
|
|
@@ -139,7 +149,7 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar
|
|
|
139
149
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
140
150
|
|
|
141
151
|
"use strict";
|
|
142
|
-
eval("\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.getFileNameFromHeader = void 0;\nvar __1 = __webpack_require__(/*! .. */ \"./tools/index.ts\");\nfunction getFileNameFromHeader(response) {\n var contentDisposition = response.headers.get('Content-Disposition');\n if (!contentDisposition) {\n return null;\n }\n var filenameStarMatch = contentDisposition.match(/filename\\*=UTF-8''([^;]+)/i);\n if (filenameStarMatch) {\n return decodeURIComponent(filenameStarMatch[1]);\n }\n var filenameMatch = contentDisposition.match(/filename=[\"']?([^;\"']+)[\"']?/i);\n if (filenameMatch) {\n return decodeURIComponent(filenameMatch[1]);\n }\n return null;\n}\nexports.getFileNameFromHeader = getFileNameFromHeader;\nfunction downloadFileByUrl(url, fileName, signal) {\n return __awaiter(this, void 0, void 0, function () {\n var response, finalFileName, arrayBuffer, error_1, downloadElement;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _a.trys.push([0, 3, , 4]);\n return [4, fetch(url, { signal: signal })];\n case 1:\n response = _a.sent();\n finalFileName = fileName;\n if (!finalFileName) {\n finalFileName = getFileNameFromHeader(response) || undefined;\n }\n return [4, response.arrayBuffer()];\n case 2:\n arrayBuffer = _a.sent();\n downloadFile(arrayBuffer, finalFileName);\n return [3, 4];\n case 3:\n error_1 = _a.sent();\n if ((error_1 === null || error_1 === void 0 ? void 0 : error_1.name) !== 'AbortError') {\n downloadElement = document.createElement('a');\n downloadElement.href = url;\n downloadElement.download = decodeURIComponent(fileName || '');\n downloadElement.target = '_blank';\n document.body.appendChild(downloadElement);\n downloadElement.click();\n document.body.removeChild(downloadElement);\n }\n return [3, 4];\n case 4: return [2];\n }\n });\n });\n}\nfunction downloadFile(file, fileName, signal) {\n return __awaiter(this, void 0, void 0, function () {\n var blob, downloadElement, href;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!(typeof file === 'string')) return [3, 2];\n return [4, downloadFileByUrl(file, fileName, signal)];\n case 1:\n _a.sent();\n return [3, 3];\n case 2:\n blob = (0, __1.Typeof)(file) === 'blob' ? file : new Blob([file]);\n downloadElement = document.createElement('a');\n href = window.URL.createObjectURL(blob);\n downloadElement.href = href;\n downloadElement.download = decodeURIComponent(fileName || '');\n downloadElement.target = '_blank';\n document.body.appendChild(downloadElement);\n downloadElement.click();\n document.body.removeChild(downloadElement);\n window.URL.revokeObjectURL(href);\n _a.label = 3;\n case 3: return [2];\n }\n });\n });\n}\nexports[\"default\"] = downloadFile;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/DownloadFile/index.ts?");
|
|
152
|
+
eval("\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (g && (g = 0, op[0] && (_ = 0)), _) try {\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [op[0] & 2, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.getFileNameFromHeader = void 0;\nvar __1 = __webpack_require__(/*! .. */ \"./tools/index.ts\");\nfunction getFileNameFromHeader(response) {\n var contentDisposition = null;\n if (response.headers && typeof response.headers.get === 'function') {\n contentDisposition = response.headers.get('Content-Disposition');\n }\n else if (response.headers && typeof response.headers === 'object') {\n var headers = response.headers;\n contentDisposition = headers['content-disposition'] || headers['Content-Disposition'] || null;\n }\n if (!contentDisposition) {\n return null;\n }\n var filenameStarMatch = contentDisposition.match(/filename\\*=UTF-8''([^;]+)/i);\n if (filenameStarMatch) {\n return decodeURIComponent(filenameStarMatch[1]);\n }\n var filenameMatch = contentDisposition.match(/filename=[\"']?([^;\"']+)[\"']?/i);\n if (filenameMatch) {\n return decodeURIComponent(filenameMatch[1]);\n }\n return null;\n}\nexports.getFileNameFromHeader = getFileNameFromHeader;\nfunction downloadFileByUrl(url, fileName, signal) {\n return __awaiter(this, void 0, void 0, function () {\n var response, finalFileName, arrayBuffer, error_1, downloadElement;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n _a.trys.push([0, 3, , 4]);\n return [4, fetch(url, { signal: signal })];\n case 1:\n response = _a.sent();\n finalFileName = fileName;\n if (!finalFileName) {\n finalFileName = getFileNameFromHeader(response) || undefined;\n }\n return [4, response.arrayBuffer()];\n case 2:\n arrayBuffer = _a.sent();\n downloadFile(arrayBuffer, finalFileName);\n return [3, 4];\n case 3:\n error_1 = _a.sent();\n if ((error_1 === null || error_1 === void 0 ? void 0 : error_1.name) !== 'AbortError') {\n downloadElement = document.createElement('a');\n downloadElement.href = url;\n downloadElement.download = decodeURIComponent(fileName || '');\n downloadElement.target = '_blank';\n document.body.appendChild(downloadElement);\n downloadElement.click();\n document.body.removeChild(downloadElement);\n }\n return [3, 4];\n case 4: return [2];\n }\n });\n });\n}\nfunction downloadFile(file, fileName, signal) {\n return __awaiter(this, void 0, void 0, function () {\n var blob, downloadElement, href;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!(typeof file === 'string')) return [3, 2];\n return [4, downloadFileByUrl(file, fileName, signal)];\n case 1:\n _a.sent();\n return [3, 3];\n case 2:\n blob = (0, __1.Typeof)(file) === 'blob' ? file : new Blob([file]);\n downloadElement = document.createElement('a');\n href = window.URL.createObjectURL(blob);\n downloadElement.href = href;\n downloadElement.download = decodeURIComponent(fileName || '');\n downloadElement.target = '_blank';\n document.body.appendChild(downloadElement);\n downloadElement.click();\n document.body.removeChild(downloadElement);\n window.URL.revokeObjectURL(href);\n _a.label = 3;\n case 3: return [2];\n }\n });\n });\n}\nexports[\"default\"] = downloadFile;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/DownloadFile/index.ts?");
|
|
143
153
|
|
|
144
154
|
/***/ }),
|
|
145
155
|
|
|
@@ -172,7 +182,7 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunc
|
|
|
172
182
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
173
183
|
|
|
174
184
|
"use strict";
|
|
175
|
-
eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar dayjs_1 = __importDefault(__webpack_require__(/*! dayjs */ \"./node_modules/dayjs/dayjs.min.js\"));\nvar quarterOfYear_1 = __importDefault(__webpack_require__(/*! dayjs/plugin/quarterOfYear */ \"./node_modules/dayjs/plugin/quarterOfYear.js\"));\nvar weekOfYear_1 = __importDefault(__webpack_require__(/*! dayjs/plugin/weekOfYear */ \"./node_modules/dayjs/plugin/weekOfYear.js\"));\ndayjs_1.default.extend(quarterOfYear_1.default);\ndayjs_1.default.extend(weekOfYear_1.default);\nfunction getFormat(type, unit, hasTime) {\n if (unit === void 0) { unit = 'day'; }\n if (hasTime === void 0) { hasTime = false; }\n var baseFormat;\n switch (type) {\n case 'today':\n baseFormat = 'YYYY-MM-DD';\n break;\n case 'thisWeek':\n baseFormat = 'YYYY-MM-DD';\n break;\n case 'thisMonth':\n baseFormat = 'YYYY-MM';\n break;\n case 'thisQuarter':\n baseFormat = 'YYYY-[Q]Q';\n break;\n case 'thisYear':\n baseFormat = 'YYYY';\n break;\n case 'past':\n case 'future':\n default:\n switch (unit) {\n case 'year':\n baseFormat = 'YYYY';\n break;\n case 'month':\n baseFormat = 'YYYY-MM';\n break;\n case 'second':\n case 'minute':\n case 'hour':\n return 'YYYY-MM-DD HH:mm:ss';\n case 'week':\n case 'day':\n default:\n baseFormat = 'YYYY-MM-DD';\n break;\n }\n break;\n }\n if (hasTime && baseFormat.endsWith('DD')) {\n return \"\".concat(baseFormat, \" HH:mm:ss\");\n }\n return baseFormat;\n}\nfunction getDateRange(options) {\n var type = options.type, _a = options.amount, amount = _a === void 0 ? 0 : _a, baseDate = options.baseDate, _b = options.unit, unit = _b === void 0 ? 'day' : _b, minDateLimit = options.minDate, maxDateLimit = options.maxDate, _c = options.hasTime, hasTime = _c === void 0 ? false : _c;\n var base = baseDate ? (0, dayjs_1.default)(baseDate) : (0, dayjs_1.default)();\n var minDate;\n var maxDate;\n switch (type) {\n case 'past':\n maxDate = base.endOf(unit);\n minDate = base.subtract(amount, unit).startOf(unit);\n if (minDateLimit) {\n var minLimit = (0, dayjs_1.default)(minDateLimit).startOf(unit);\n if (minLimit.isAfter(minDate)) {\n minDate = minLimit;\n }\n }\n if (maxDateLimit) {\n var maxLimit = (0, dayjs_1.default)(maxDateLimit).endOf(unit);\n if (maxLimit.isBefore(maxDate)) {\n maxDate = maxLimit;\n }\n }\n break;\n case 'future':\n minDate = base.startOf(unit);\n maxDate = base.add(amount, unit).endOf(unit);\n if (minDateLimit) {\n var minLimit = (0, dayjs_1.default)(minDateLimit).startOf(unit);\n if (minLimit.isAfter(minDate)) {\n minDate = minLimit;\n }\n }\n if (maxDateLimit) {\n var maxLimit = (0, dayjs_1.default)(maxDateLimit).endOf(unit);\n if (maxLimit.isBefore(maxDate)) {\n maxDate = maxLimit;\n }\n }\n break;\n case 'today':\n minDate = base.startOf('day');\n maxDate = base.endOf('day');\n break;\n case 'thisWeek':\n minDate = base.startOf('week');\n maxDate = base.endOf('week');\n break;\n case 'thisMonth':\n minDate = base.startOf('month');\n maxDate = base.endOf('month');\n break;\n case 'thisQuarter':\n minDate = base.startOf('quarter');\n maxDate = base.endOf('quarter');\n break;\n case 'thisYear':\n minDate = base.startOf('year');\n maxDate = base.endOf('year');\n break;\n default:\n throw new Error(\"\\u4E0D\\u652F\\u6301\\u7684\\u7C7B\\u578B: \".concat(type));\n }\n var format = getFormat(type, unit, hasTime);\n var min = minDate.format(format);\n var max = maxDate.format(format);\n return [min, max];\n}\nexports[\"default\"] = getDateRange;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/GetDateRange/index.ts?");
|
|
185
|
+
eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar dayjs_1 = __importDefault(__webpack_require__(/*! dayjs */ \"./node_modules/dayjs/dayjs.min.js\"));\nvar quarterOfYear_1 = __importDefault(__webpack_require__(/*! dayjs/plugin/quarterOfYear */ \"./node_modules/dayjs/plugin/quarterOfYear.js\"));\nvar weekOfYear_1 = __importDefault(__webpack_require__(/*! dayjs/plugin/weekOfYear */ \"./node_modules/dayjs/plugin/weekOfYear.js\"));\nvar advancedFormat_1 = __importDefault(__webpack_require__(/*! dayjs/plugin/advancedFormat */ \"./node_modules/dayjs/plugin/advancedFormat.js\"));\ndayjs_1.default.extend(quarterOfYear_1.default);\ndayjs_1.default.extend(weekOfYear_1.default);\ndayjs_1.default.extend(advancedFormat_1.default);\nfunction getFormat(type, unit, hasTime) {\n if (unit === void 0) { unit = 'day'; }\n if (hasTime === void 0) { hasTime = false; }\n var baseFormat;\n switch (type) {\n case 'today':\n baseFormat = 'YYYY-MM-DD';\n break;\n case 'thisWeek':\n baseFormat = 'YYYY-MM-DD';\n break;\n case 'thisMonth':\n baseFormat = 'YYYY-MM';\n break;\n case 'thisQuarter':\n baseFormat = 'YYYY-[Q]Q';\n break;\n case 'thisYear':\n baseFormat = 'YYYY';\n break;\n case 'past':\n case 'future':\n default:\n switch (unit) {\n case 'year':\n baseFormat = 'YYYY';\n break;\n case 'month':\n baseFormat = 'YYYY-MM';\n break;\n case 'second':\n case 'minute':\n case 'hour':\n return 'YYYY-MM-DD HH:mm:ss';\n case 'week':\n case 'day':\n default:\n baseFormat = 'YYYY-MM-DD';\n break;\n }\n break;\n }\n if (hasTime && baseFormat.endsWith('DD')) {\n return \"\".concat(baseFormat, \" HH:mm:ss\");\n }\n return baseFormat;\n}\nfunction getDateRange(options) {\n var type = options.type, _a = options.amount, amount = _a === void 0 ? 0 : _a, baseDate = options.baseDate, _b = options.unit, unit = _b === void 0 ? 'day' : _b, minDateLimit = options.minDate, maxDateLimit = options.maxDate, _c = options.hasTime, hasTime = _c === void 0 ? false : _c;\n var base = baseDate ? (0, dayjs_1.default)(baseDate) : (0, dayjs_1.default)();\n var minDate;\n var maxDate;\n switch (type) {\n case 'past':\n maxDate = base.endOf(unit);\n minDate = base.subtract(amount, unit).startOf(unit);\n if (minDateLimit) {\n var minLimit = (0, dayjs_1.default)(minDateLimit).startOf(unit);\n if (minLimit.isAfter(minDate)) {\n minDate = minLimit;\n }\n }\n if (maxDateLimit) {\n var maxLimit = (0, dayjs_1.default)(maxDateLimit).endOf(unit);\n if (maxLimit.isBefore(maxDate)) {\n maxDate = maxLimit;\n }\n }\n break;\n case 'future':\n minDate = base.startOf(unit);\n maxDate = base.add(amount, unit).endOf(unit);\n if (minDateLimit) {\n var minLimit = (0, dayjs_1.default)(minDateLimit).startOf(unit);\n if (minLimit.isAfter(minDate)) {\n minDate = minLimit;\n }\n }\n if (maxDateLimit) {\n var maxLimit = (0, dayjs_1.default)(maxDateLimit).endOf(unit);\n if (maxLimit.isBefore(maxDate)) {\n maxDate = maxLimit;\n }\n }\n break;\n case 'today':\n minDate = base.startOf('day');\n maxDate = base.endOf('day');\n break;\n case 'thisWeek':\n minDate = base.startOf('week');\n maxDate = base.endOf('week');\n break;\n case 'thisMonth':\n minDate = base.startOf('month');\n maxDate = base.endOf('month');\n break;\n case 'thisQuarter':\n minDate = base.startOf('quarter');\n maxDate = base.endOf('quarter');\n break;\n case 'thisYear':\n minDate = base.startOf('year');\n maxDate = base.endOf('year');\n break;\n default:\n throw new Error(\"\\u4E0D\\u652F\\u6301\\u7684\\u7C7B\\u578B: \".concat(type));\n }\n var format = getFormat(type, unit, hasTime);\n var min = minDate.format(format);\n var max = maxDate.format(format);\n return [min, max];\n}\nexports[\"default\"] = getDateRange;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/GetDateRange/index.ts?");
|
|
176
186
|
|
|
177
187
|
/***/ }),
|
|
178
188
|
|