hsu-utils 0.0.54 → 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 CHANGED
@@ -1,18 +1,30 @@
1
- # [Hsu Utils](https://github.com/VitaTsui/hsu-utils#hsu-utils)
1
+ # hsu-utils
2
2
 
3
- ## 前言
3
+ [![npm version](https://img.shields.io/npm/v/hsu-utils.svg)](https://www.npmjs.com/package/hsu-utils)
4
+ [![license](https://img.shields.io/npm/l/hsu-utils.svg)](./LICENSE)
4
5
 
5
- `hsu-utils` 一些前端的工具集
6
+ 常用前端工具集:深拷贝、类型判断、相等比较、文件下载、PDF 渲染、日期范围、控制台表格、字符串尺寸测量等,TypeScript 编写,零业务依赖。
6
7
 
7
8
  ## 安装
8
9
 
9
- ```sh
10
- npm install --save hsu-utils
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 | normal | 必填 |
81
- | startPageNum | 开始页码 | number | normal | - |
82
- | endPageNum | 结束页码 | number | normal | - |
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.53
3
+ * hsu-utils v0.0.55
4
4
  *
5
- * some front-end utils
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 ***!
@@ -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