ziya-utils 1.1.0 → 1.1.1
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/dist/ziya-utils.js +1 -351
- package/package.json +3 -2
package/dist/ziya-utils.js
CHANGED
|
@@ -1,351 +1 @@
|
|
|
1
|
-
(function (
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ZiyaUtils = {}));
|
|
5
|
-
})(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
/******************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
22
|
-
|
|
23
|
-
var extendStatics = function(d, b) {
|
|
24
|
-
extendStatics = Object.setPrototypeOf ||
|
|
25
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
26
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
27
|
-
return extendStatics(d, b);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
function __extends(d, b) {
|
|
31
|
-
if (typeof b !== "function" && b !== null)
|
|
32
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
33
|
-
extendStatics(d, b);
|
|
34
|
-
function __() { this.constructor = d; }
|
|
35
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
39
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
40
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
41
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
42
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
43
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
44
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function __generator(thisArg, body) {
|
|
49
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
50
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
51
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
52
|
-
function step(op) {
|
|
53
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
54
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
55
|
-
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;
|
|
56
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
57
|
-
switch (op[0]) {
|
|
58
|
-
case 0: case 1: t = op; break;
|
|
59
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
60
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
61
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
62
|
-
default:
|
|
63
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
64
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
65
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
66
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
67
|
-
if (t[2]) _.ops.pop();
|
|
68
|
-
_.trys.pop(); continue;
|
|
69
|
-
}
|
|
70
|
-
op = body.call(thisArg, _);
|
|
71
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
72
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
77
|
-
var e = new Error(message);
|
|
78
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @fileoverview 正则模块
|
|
83
|
-
* @date 2025-04-02
|
|
84
|
-
* @author glk
|
|
85
|
-
*/
|
|
86
|
-
// 正则表达式常量
|
|
87
|
-
var RegexPatterns = {
|
|
88
|
-
/** 手机号码正则 */
|
|
89
|
-
PHONE: /^1[3-9]\d{9}$/,
|
|
90
|
-
/** 邮箱地址正则 */
|
|
91
|
-
EMAIL: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
|
|
92
|
-
/** 身份证号码正则(支持15位和18位) */
|
|
93
|
-
ID_CARD: /(^\d{15}$)|(^\d{17}(\d|X|x)$)/,
|
|
94
|
-
/** URL地址正则 */
|
|
95
|
-
URL: /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/,
|
|
96
|
-
/** IPv4地址正则 */
|
|
97
|
-
IPV4: /^(\d{1,3}\.){3}\d{1,3}$/,
|
|
98
|
-
/** 强密码正则(至少8位,包含大小写字母、数字和特殊字符) */
|
|
99
|
-
STRONG_PASSWORD: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,
|
|
100
|
-
/** 中文字符正则 */
|
|
101
|
-
CHINESE: /^[\u4e00-\u9fa5]+$/
|
|
102
|
-
};
|
|
103
|
-
// 使用 `abstract class` 代替 `interface`,用于静态方法约束
|
|
104
|
-
var IRegexValidatorStatic = /** @class */ (function () {
|
|
105
|
-
function IRegexValidatorStatic() {
|
|
106
|
-
}
|
|
107
|
-
return IRegexValidatorStatic;
|
|
108
|
-
}());
|
|
109
|
-
var RegexValidator = /** @class */ (function (_super) {
|
|
110
|
-
__extends(RegexValidator, _super);
|
|
111
|
-
function RegexValidator() {
|
|
112
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
113
|
-
}
|
|
114
|
-
RegexValidator.isPhone = function (phone) {
|
|
115
|
-
return RegexPatterns.PHONE.test(phone);
|
|
116
|
-
};
|
|
117
|
-
RegexValidator.isEmail = function (email) {
|
|
118
|
-
return RegexPatterns.EMAIL.test(email);
|
|
119
|
-
};
|
|
120
|
-
RegexValidator.isIdCard = function (idCard) {
|
|
121
|
-
return RegexPatterns.ID_CARD.test(idCard);
|
|
122
|
-
};
|
|
123
|
-
RegexValidator.isUrl = function (url) {
|
|
124
|
-
return RegexPatterns.URL.test(url);
|
|
125
|
-
};
|
|
126
|
-
RegexValidator.isIpv4 = function (ip) {
|
|
127
|
-
return RegexPatterns.IPV4.test(ip);
|
|
128
|
-
};
|
|
129
|
-
RegexValidator.isStrongPassword = function (password) {
|
|
130
|
-
return RegexPatterns.STRONG_PASSWORD.test(password);
|
|
131
|
-
};
|
|
132
|
-
RegexValidator.isChinese = function (text) {
|
|
133
|
-
return RegexPatterns.CHINESE.test(text);
|
|
134
|
-
};
|
|
135
|
-
return RegexValidator;
|
|
136
|
-
}(IRegexValidatorStatic));
|
|
137
|
-
// 默认导出
|
|
138
|
-
var IRegexUtils = {
|
|
139
|
-
patterns: RegexPatterns,
|
|
140
|
-
validator: RegexValidator
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* @fileoverview 文件模块
|
|
145
|
-
* @date 2025-04-2
|
|
146
|
-
* @author glk
|
|
147
|
-
*/
|
|
148
|
-
/**
|
|
149
|
-
* 从文件路径中提取文件名
|
|
150
|
-
* @param filePath 文件路径字符串
|
|
151
|
-
* @returns 提取的文件名,如果路径为空则返回空字符串,如果路径中没有分隔符则返回原字符串
|
|
152
|
-
*/
|
|
153
|
-
var extractFileNameFromPath = function (filePath) {
|
|
154
|
-
if (!filePath) {
|
|
155
|
-
return "";
|
|
156
|
-
}
|
|
157
|
-
// 同时支持 Unix/Linux/Mac (/) 和 Windows (\) 风格的路径
|
|
158
|
-
var lastSlashIndex = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));
|
|
159
|
-
// 如果找不到分隔符,则整个字符串就是文件名
|
|
160
|
-
if (lastSlashIndex === -1) {
|
|
161
|
-
return filePath;
|
|
162
|
-
}
|
|
163
|
-
return filePath.slice(lastSlashIndex + 1);
|
|
164
|
-
};
|
|
165
|
-
/**
|
|
166
|
-
* 下载文件到本地
|
|
167
|
-
* @param url 文件的远程URL
|
|
168
|
-
* @param name 可选的自定义文件名,若未提供则从URL中提取
|
|
169
|
-
* @returns Promise<void>
|
|
170
|
-
* @throws Error 当URL无效或网络请求失败时抛出错误
|
|
171
|
-
*/
|
|
172
|
-
var downloadSingleFile = function (url, name) { return __awaiter(void 0, void 0, void 0, function () {
|
|
173
|
-
var response, fileName, queryIndex, blob, blobUrl_1, link_1, error_1;
|
|
174
|
-
return __generator(this, function (_a) {
|
|
175
|
-
switch (_a.label) {
|
|
176
|
-
case 0:
|
|
177
|
-
// 验证URL
|
|
178
|
-
if (!url || !IRegexUtils.validator.isUrl(url)) {
|
|
179
|
-
throw new Error('无效的URL');
|
|
180
|
-
}
|
|
181
|
-
_a.label = 1;
|
|
182
|
-
case 1:
|
|
183
|
-
_a.trys.push([1, 4, , 5]);
|
|
184
|
-
return [4 /*yield*/, fetch(url)];
|
|
185
|
-
case 2:
|
|
186
|
-
response = _a.sent();
|
|
187
|
-
// 检查响应状态
|
|
188
|
-
if (!response.ok) {
|
|
189
|
-
throw new Error("\u4E0B\u8F7D\u5931\u8D25: ".concat(response.status, " ").concat(response.statusText));
|
|
190
|
-
}
|
|
191
|
-
fileName = name;
|
|
192
|
-
if (!fileName) {
|
|
193
|
-
fileName = extractFileNameFromPath(url);
|
|
194
|
-
queryIndex = fileName.indexOf('?');
|
|
195
|
-
if (queryIndex !== -1) {
|
|
196
|
-
fileName = fileName.substring(0, queryIndex);
|
|
197
|
-
}
|
|
198
|
-
// 如果仍然没有文件名,使用默认名称
|
|
199
|
-
if (!fileName) {
|
|
200
|
-
fileName = 'downloaded_file';
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return [4 /*yield*/, response.blob()];
|
|
204
|
-
case 3:
|
|
205
|
-
blob = _a.sent();
|
|
206
|
-
blobUrl_1 = URL.createObjectURL(blob);
|
|
207
|
-
link_1 = document.createElement('a');
|
|
208
|
-
link_1.href = blobUrl_1;
|
|
209
|
-
link_1.download = fileName;
|
|
210
|
-
// 执行下载
|
|
211
|
-
document.body.appendChild(link_1);
|
|
212
|
-
link_1.click();
|
|
213
|
-
// 清理
|
|
214
|
-
setTimeout(function () {
|
|
215
|
-
URL.revokeObjectURL(blobUrl_1);
|
|
216
|
-
link_1.remove();
|
|
217
|
-
}, 100); // 添加小延迟以确保下载开始
|
|
218
|
-
return [3 /*break*/, 5];
|
|
219
|
-
case 4:
|
|
220
|
-
error_1 = _a.sent();
|
|
221
|
-
console.error('文件下载失败:', error_1);
|
|
222
|
-
throw error_1; // 重新抛出错误以便调用者可以处理
|
|
223
|
-
case 5: return [2 /*return*/];
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}); };
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* @fileoverview 时间模块
|
|
230
|
-
* @date 2025-04-02
|
|
231
|
-
* @author glk
|
|
232
|
-
*/
|
|
233
|
-
/**
|
|
234
|
-
* 休眠
|
|
235
|
-
* @param time - 休眠时间(s)
|
|
236
|
-
* @returns
|
|
237
|
-
*/
|
|
238
|
-
var sleep = function (time) {
|
|
239
|
-
return new Promise(function (resolve) {
|
|
240
|
-
setTimeout(function () {
|
|
241
|
-
resolve(true);
|
|
242
|
-
}, time * 1000);
|
|
243
|
-
});
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* @fileoverview 日期模块
|
|
248
|
-
* @date 2025-04-02
|
|
249
|
-
* @author glk
|
|
250
|
-
*/
|
|
251
|
-
/**
|
|
252
|
-
* 判断时间戳格式是否正确且有意义
|
|
253
|
-
* @param timestamp 要验证的时间戳,可以是数字或字符串
|
|
254
|
-
* @returns 如果时间戳格式正确且有意义则返回true,否则返回false
|
|
255
|
-
*/
|
|
256
|
-
function isValidTimestamp(timestamp) {
|
|
257
|
-
// 如果是字符串,尝试转换为数字
|
|
258
|
-
if (typeof timestamp === "string") {
|
|
259
|
-
// 检查是否只包含数字
|
|
260
|
-
if (!/^\d+$/.test(timestamp)) {
|
|
261
|
-
return false;
|
|
262
|
-
}
|
|
263
|
-
timestamp = Number(timestamp);
|
|
264
|
-
}
|
|
265
|
-
// 检查是否为数字且不为NaN
|
|
266
|
-
if (typeof timestamp !== "number" || isNaN(timestamp)) {
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
// 检查时间戳范围是否合理
|
|
270
|
-
// 时间戳下限:1970年1月1日
|
|
271
|
-
var minTimestamp = 0;
|
|
272
|
-
// 时间戳上限:设置为一个合理的未来日期,例如2100年1月1日
|
|
273
|
-
var maxTimestamp = 4102444800000; // 2100-01-01的毫秒时间戳
|
|
274
|
-
// 检查时间戳是否为13位(毫秒级)或10位(秒级)
|
|
275
|
-
if (timestamp.toString().length === 13) {
|
|
276
|
-
// 毫秒级时间戳
|
|
277
|
-
return timestamp >= minTimestamp && timestamp <= maxTimestamp;
|
|
278
|
-
}
|
|
279
|
-
else if (timestamp.toString().length === 10) {
|
|
280
|
-
// 秒级时间戳,转换为毫秒级进行比较
|
|
281
|
-
return timestamp >= minTimestamp / 1000 && timestamp <= maxTimestamp / 1000;
|
|
282
|
-
}
|
|
283
|
-
// 不符合常见的时间戳长度
|
|
284
|
-
return false;
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* 是不是秒级时间戳
|
|
288
|
-
* @param timestamp
|
|
289
|
-
* @returns
|
|
290
|
-
*/
|
|
291
|
-
var isSecondTimestamp = function (timestamp) {
|
|
292
|
-
return isValidTimestamp(timestamp) && timestamp.toString().length === 10;
|
|
293
|
-
};
|
|
294
|
-
/**
|
|
295
|
-
* 是不是毫秒级时间戳
|
|
296
|
-
* @param timestamp
|
|
297
|
-
* @returns
|
|
298
|
-
*/
|
|
299
|
-
var isMillisecondTimestamp = function (timestamp) {
|
|
300
|
-
return isValidTimestamp(timestamp) && timestamp.toString().length === 13;
|
|
301
|
-
};
|
|
302
|
-
/**
|
|
303
|
-
* 计算传入时间戳和当前时间的时间差
|
|
304
|
-
* @param timestamp 时间戳
|
|
305
|
-
* @returns
|
|
306
|
-
*/
|
|
307
|
-
var getElapsedTimeSince = function (timestamp) {
|
|
308
|
-
var now = Date.now();
|
|
309
|
-
if (!isValidTimestamp(timestamp)) {
|
|
310
|
-
timestamp = now;
|
|
311
|
-
}
|
|
312
|
-
var diff = Math.max(0, now - (isSecondTimestamp(timestamp) ? timestamp * 1000 : timestamp));
|
|
313
|
-
// 计算小时
|
|
314
|
-
var hours = Math.floor(diff / (1000 * 60 * 60));
|
|
315
|
-
// 计算分钟
|
|
316
|
-
var minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
|
|
317
|
-
// 计算秒
|
|
318
|
-
var seconds = Math.floor((diff % (1000 * 60)) / 1000);
|
|
319
|
-
return {
|
|
320
|
-
hours: hours,
|
|
321
|
-
minutes: minutes,
|
|
322
|
-
seconds: seconds,
|
|
323
|
-
};
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* 通用安全工具
|
|
328
|
-
*/
|
|
329
|
-
/**
|
|
330
|
-
* 生成通用唯一识别码(UUID)
|
|
331
|
-
* @returns
|
|
332
|
-
*/
|
|
333
|
-
var getUuid = function () {
|
|
334
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
335
|
-
var r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
336
|
-
return v.toString(16);
|
|
337
|
-
});
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
exports.RegexPatterns = RegexPatterns;
|
|
341
|
-
exports.RegexValidator = RegexValidator;
|
|
342
|
-
exports.downloadSingleFile = downloadSingleFile;
|
|
343
|
-
exports.extractFileNameFromPath = extractFileNameFromPath;
|
|
344
|
-
exports.getElapsedTimeSince = getElapsedTimeSince;
|
|
345
|
-
exports.getUuid = getUuid;
|
|
346
|
-
exports.isMillisecondTimestamp = isMillisecondTimestamp;
|
|
347
|
-
exports.isSecondTimestamp = isSecondTimestamp;
|
|
348
|
-
exports.isValidTimestamp = isValidTimestamp;
|
|
349
|
-
exports.sleep = sleep;
|
|
350
|
-
|
|
351
|
-
}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ZiyaUtils={})}(this,function(t){"use strict";var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};function n(t,e,n,r){return new(n||(n=Promise))(function(o,i){function u(t){try{s(r.next(t))}catch(t){i(t)}}function a(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(u,a)}s((r=r.apply(t,e||[])).next())})}function r(t,e){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=e.call(t,u)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}"function"==typeof SuppressedError&&SuppressedError;var o={PHONE:/^1[3-9]\d{9}$/,EMAIL:/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,ID_CARD:/(^\d{15}$)|(^\d{17}(\d|X|x)$)/,URL:/^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/,IPV4:/^(\d{1,3}\.){3}\d{1,3}$/,STRONG_PASSWORD:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,CHINESE:/^[\u4e00-\u9fa5]+$/},i=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}(n,t),n.isPhone=function(t){return o.PHONE.test(t)},n.isEmail=function(t){return o.EMAIL.test(t)},n.isIdCard=function(t){return o.ID_CARD.test(t)},n.isUrl=function(t){return o.URL.test(t)},n.isIpv4=function(t){return o.IPV4.test(t)},n.isStrongPassword=function(t){return o.STRONG_PASSWORD.test(t)},n.isChinese=function(t){return o.CHINESE.test(t)},n}(function(){}),u={patterns:o,validator:i},a=function(t){if(!t)return"";var e=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"));return-1===e?t:t.slice(e+1)};function s(t){if("string"==typeof t){if(!/^\d+$/.test(t))return!1;t=Number(t)}if("number"!=typeof t||isNaN(t))return!1;var e=41024448e5;return 13===t.toString().length?t>=0&&t<=e:10===t.toString().length&&(t>=0&&t<=4102444800)}var c=function(t){return s(t)&&10===t.toString().length};t.RegexPatterns=o,t.RegexValidator=i,t.downloadSingleFile=function(t,e){return n(void 0,void 0,void 0,function(){var n,o,i,s,c,f,l;return r(this,function(r){switch(r.label){case 0:if(!t||!u.validator.isUrl(t))throw new Error("无效的URL");r.label=1;case 1:return r.trys.push([1,4,,5]),[4,fetch(t)];case 2:if(!(n=r.sent()).ok)throw new Error("下载失败: ".concat(n.status," ").concat(n.statusText));return(o=e)||(o=a(t),-1!==(i=o.indexOf("?"))&&(o=o.substring(0,i)),o||(o="downloaded_file")),[4,n.blob()];case 3:return s=r.sent(),c=URL.createObjectURL(s),(f=document.createElement("a")).href=c,f.download=o,document.body.appendChild(f),f.click(),setTimeout(function(){URL.revokeObjectURL(c),f.remove()},100),[3,5];case 4:throw l=r.sent(),console.error("文件下载失败:",l),l;case 5:return[2]}})})},t.extractFileNameFromPath=a,t.getElapsedTimeSince=function(t){var e=Date.now();s(t)||(t=e);var n=Math.max(0,e-(c(t)?1e3*t:t));return{hours:Math.floor(n/36e5),minutes:Math.floor(n%36e5/6e4),seconds:Math.floor(n%6e4/1e3)}},t.getUuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},t.isMillisecondTimestamp=function(t){return s(t)&&13===t.toString().length},t.isSecondTimestamp=c,t.isValidTimestamp=s,t.sleep=function(t){return new Promise(function(e){setTimeout(function(){e(!0)},1e3*t)})}});
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ziya-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./es/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
|
-
"unpkg": "dist/
|
|
7
|
+
"unpkg": "dist/ziya-utils.js",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"lib",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@rollup/plugin-commonjs": "^25.0.3",
|
|
31
31
|
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
32
32
|
"@rollup/plugin-strip": "^3.0.4",
|
|
33
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
33
34
|
"@rollup/plugin-typescript": "^11.1.2",
|
|
34
35
|
"rimraf": "^6.0.1",
|
|
35
36
|
"rollup": "^3.26.3",
|