hsu-utils 0.0.50 → 0.0.51

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
@@ -109,7 +109,7 @@ yarn add hsu-utils
109
109
  | unit | 单位(用于过去/未来) | 'day' \| 'week' \| 'month' \| 'year' | 'day' | - |
110
110
  | minDate | 最小时间限制 | string \| Date \| Dayjs | - | 用于过去/未来,限制范围最小值 |
111
111
  | maxDate | 最大时间限制 | string \| Date \| Dayjs | - | 用于过去/未来,限制范围最大值 |
112
- | hasTime | 是否包含时间部分 | boolean | true | 控制返回格式是否包含时间 |
112
+ | hasTime | 是否包含时间部分 | boolean | false | 控制返回格式是否包含时间 |
113
113
 
114
114
  ### DateRangeType
115
115
 
@@ -134,7 +134,7 @@ yarn add hsu-utils
134
134
  - `thisQuarter` → `YYYY-[Q]Q` (例如: `2024-Q1`)
135
135
  - `thisYear` / `past`(year) / `future`(year) → `YYYY`
136
136
 
137
- 注意:当 `hasTime` 为 `true`(默认)时,包含日期部分的格式会自动添加时间部分 `HH:mm:ss`。
137
+ 注意:当 `hasTime` 为 `true` 时,包含日期部分的格式会自动添加时间部分 `HH:mm:ss`。默认 `hasTime` 为 `false`。
138
138
 
139
139
  ## License
140
140
 
package/dist/hsu-utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  *
3
- * hsu-utils v0.0.49
3
+ * hsu-utils v0.0.50
4
4
  *
5
5
  * some front-end utils
6
6
  *
@@ -172,7 +172,7 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunc
172
172
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
173
173
 
174
174
  "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 = true; }\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 'week':\n case 'day':\n default:\n baseFormat = 'YYYY-MM-DD';\n break;\n }\n break;\n }\n if (hasTime && (baseFormat.includes('DD') || baseFormat === 'YYYY-MM-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 ? true : _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?");
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 'week':\n case 'day':\n default:\n baseFormat = 'YYYY-MM-DD';\n break;\n }\n break;\n }\n if (hasTime && baseFormat.includes('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
176
 
177
177
  /***/ }),
178
178