@oeos-components/utils 0.0.2 → 0.0.4

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/index.cjs CHANGED
@@ -1,16 +1,795 @@
1
- const { createJiti } = require("../../../node_modules/.pnpm/jiti@2.5.1/node_modules/jiti/lib/jiti.cjs")
1
+ 'use strict';
2
2
 
3
- const jiti = createJiti(__filename, {
4
- "interopDefault": true,
5
- "alias": {
6
- "@oeos-components/utils": "/Users/andy/cyrd/oeos-components/packages/utils"
7
- },
8
- "transformOptions": {
9
- "babel": {
10
- "plugins": []
3
+ const reactivity = require('@vue/reactivity');
4
+ const lodashEs = require('lodash-es');
5
+ const consola = require('consola');
6
+ const elementPlus = require('element-plus');
7
+
8
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
+ const isString = (val) => typeof val === "string";
10
+ const isStringNumber = (val) => {
11
+ if (!isString(val)) {
12
+ return false;
13
+ }
14
+ return !Number.isNaN(Number(val));
15
+ };
16
+ const isNumber = (val) => typeof val === "number";
17
+ function $toast(message, type = "success", otherParams = {}) {
18
+ const map = {
19
+ s: "success",
20
+ i: "info",
21
+ e: "error",
22
+ w: "warning"
23
+ };
24
+ if (getType(message) === "object") {
25
+ if (message.clodeAll) {
26
+ elementPlus.ElMessage.closeAll();
27
+ }
28
+ elementPlus.ElMessage(message);
29
+ return;
30
+ }
31
+ if (getType(type) === "object") {
32
+ if (type.clodeAll) {
33
+ elementPlus.ElMessage.closeAll();
34
+ }
35
+ elementPlus.ElMessage({
36
+ message,
37
+ type: "success",
38
+ ...type
39
+ });
40
+ return;
41
+ }
42
+ if (otherParams.closeAll) {
43
+ elementPlus.ElMessage.closeAll();
44
+ }
45
+ elementPlus.ElMessage({
46
+ message,
47
+ type: map[type] || type,
48
+ ...otherParams
49
+ });
50
+ }
51
+ $toast.success = (message, otherParams = {}) => $toast(message, "success", otherParams);
52
+ $toast.info = (message, otherParams = {}) => $toast(message, "info", otherParams);
53
+ $toast.error = (message, otherParams = {}) => $toast(message, "error", otherParams);
54
+ $toast.warning = (message, otherParams = {}) => $toast(message, "warning", otherParams);
55
+ function setStorage(storageName, params, isSession = false) {
56
+ let handleParams;
57
+ if (typeof params === "number" || typeof params === "string") {
58
+ handleParams = params;
59
+ } else {
60
+ handleParams = JSON.stringify(params);
61
+ }
62
+ if (isSession) {
63
+ sessionStorage.setItem(storageName, handleParams);
64
+ } else {
65
+ localStorage.setItem(storageName, handleParams);
66
+ }
67
+ }
68
+ function getStorage(data, isSession = false) {
69
+ let getLocalData = "";
70
+ let getSessionData = "";
71
+ if (isSession) {
72
+ getSessionData = sessionStorage.getItem(data);
73
+ } else {
74
+ getLocalData = localStorage.getItem(data);
75
+ }
76
+ if (getLocalData) {
77
+ try {
78
+ if (typeof JSON.parse(getLocalData) !== "number") {
79
+ getLocalData = JSON.parse(getLocalData);
80
+ }
81
+ } catch (e) {
82
+ }
83
+ return getLocalData;
84
+ } else if (getSessionData) {
85
+ try {
86
+ if (typeof JSON.parse(getSessionData) !== "number") {
87
+ getSessionData = JSON.parse(getSessionData);
88
+ }
89
+ } catch (e) {
90
+ }
91
+ return getSessionData;
92
+ }
93
+ return null;
94
+ }
95
+ function clearStorage(str = "") {
96
+ if (isEmpty(str)) {
97
+ sessionStorage.clear();
98
+ localStorage.clear();
99
+ }
100
+ if (notEmpty(str) && getType(str) !== "object") {
101
+ let strArr = Array.isArray(str) ? str : [str];
102
+ for (let i = 0; i < strArr.length; i++) {
103
+ sessionStorage.removeItem(strArr[i]);
104
+ localStorage.removeItem(strArr[i]);
105
+ }
106
+ }
107
+ if (_isObjectWithExclude(str)) {
108
+ if (notEmpty(str.exclude) && getType(str) === "object") {
109
+ let sessionStorageObj = {};
110
+ let localStorageObj = {};
111
+ for (const key in str.exclude) {
112
+ if (Object.prototype.hasOwnProperty.call(str.exclude, key)) {
113
+ const name = str.exclude[key];
114
+ if (getStorage(name)) {
115
+ localStorageObj[name] = getStorage(name);
116
+ }
117
+ if (getStorage(name, true)) {
118
+ sessionStorageObj[name] = getStorage(name, true);
119
+ }
120
+ }
121
+ }
122
+ sessionStorage.clear();
123
+ localStorage.clear();
124
+ for (const key in sessionStorageObj) {
125
+ setStorage(key, sessionStorageObj[key], true);
126
+ }
127
+ for (const key in localStorageObj) {
128
+ setStorage(key, localStorageObj[key]);
129
+ }
130
+ }
131
+ }
132
+ }
133
+ function _isObjectWithExclude(obj) {
134
+ return typeof obj === "object" && obj !== null && "exclude" in obj && typeof obj.exclude === "object";
135
+ }
136
+ function validForm(ref, { message = "\u8868\u5355\u6821\u9A8C\u9519\u8BEF, \u8BF7\u68C0\u67E5", detail = false, showMessage = true } = {}) {
137
+ return new Promise((resolve, reject) => {
138
+ reactivity.unref(ref).validate((valid, status) => {
139
+ if (valid) {
140
+ resolve(status);
141
+ } else {
142
+ if (message && showMessage) {
143
+ let errorText = Object.keys(status);
144
+ let toastMessage = message;
145
+ if (detail) {
146
+ toastMessage = message + errorText.join(",");
147
+ }
148
+ $toast(toastMessage, "e");
149
+ }
150
+ reject(status);
151
+ }
152
+ });
153
+ });
154
+ }
155
+ function isEmpty(data) {
156
+ if (reactivity.isRef(data)) {
157
+ data = reactivity.unref(data);
158
+ }
159
+ if (data instanceof Date) {
160
+ return isNaN(data.getTime());
161
+ }
162
+ switch (typeof data) {
163
+ case "undefined":
164
+ return true;
165
+ case "string":
166
+ if (data.trim().length === 0) return true;
167
+ break;
168
+ case "boolean":
169
+ if (!data) return true;
170
+ break;
171
+ case "number":
172
+ if (0 === data) return true;
173
+ break;
174
+ case "object":
175
+ if (null === data) return true;
176
+ if (void 0 !== data.length && data.length === 0) return true;
177
+ for (var k in data) {
178
+ return false;
179
+ }
180
+ return true;
181
+ }
182
+ return false;
183
+ }
184
+ function notEmpty(v) {
185
+ return !isEmpty(v);
186
+ }
187
+ function merge(obj1, obj2) {
188
+ let merged = { ...obj1, ...obj2 };
189
+ for (let key in merged) {
190
+ if (!isEmpty(obj1[key]) && !isEmpty(obj2[key])) {
191
+ merged[key] = obj2[key];
192
+ } else if (isEmpty(obj1[key]) && !isEmpty(obj2[key])) {
193
+ merged[key] = obj2[key];
194
+ } else if (!isEmpty(obj1[key]) && isEmpty(obj2[key])) {
195
+ merged[key] = obj1[key];
196
+ }
197
+ }
198
+ return merged;
199
+ }
200
+ function clone(data, times = 1) {
201
+ if (reactivity.isRef(data)) {
202
+ data = reactivity.unref(data);
203
+ }
204
+ if (getType(data) !== "array") {
205
+ return lodashEs.cloneDeep(data);
206
+ }
207
+ const clonedData = lodashEs.cloneDeep(data);
208
+ const result = [];
209
+ for (let i = 0; i < times; i++) {
210
+ result.push(...clonedData);
211
+ }
212
+ return result;
213
+ }
214
+ function formatTime(time, cFormat = "{y}-{m}-{d} {h}:{i}:{s}") {
215
+ if (!time) {
216
+ return time;
217
+ }
218
+ let date;
219
+ if (typeof time === "object") {
220
+ date = time;
221
+ } else {
222
+ if (("" + time).length === 10) time = parseInt(time) * 1e3;
223
+ date = new Date(time);
224
+ }
225
+ const formatObj = {
226
+ y: date.getFullYear(),
227
+ m: date.getMonth() + 1,
228
+ d: date.getDate(),
229
+ h: date.getHours(),
230
+ i: date.getMinutes(),
231
+ s: date.getSeconds(),
232
+ a: date.getDay()
233
+ };
234
+ const time_str = cFormat.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
235
+ let value = formatObj[key];
236
+ if (key === "a") {
237
+ return ["\u65E5", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D"][value];
238
+ }
239
+ if (result.length > 0 && value < 10) {
240
+ value = "0" + value;
241
+ }
242
+ return value || 0;
243
+ });
244
+ return time_str;
245
+ }
246
+ function formatDurationTime(timestamp, cFormat = "{d} \u5929 {h} \u65F6 {i} \u5206 {s} \u79D2") {
247
+ const secondsPerMinute = 60;
248
+ const minutesPerHour = 60;
249
+ const hoursPerDay = 24;
250
+ let totalSeconds = Math.floor(timestamp / 1e3);
251
+ let days = 0;
252
+ if (cFormat.indexOf("d") !== -1) {
253
+ days = Math.floor(totalSeconds / (secondsPerMinute * minutesPerHour * hoursPerDay));
254
+ totalSeconds %= secondsPerMinute * minutesPerHour * hoursPerDay;
255
+ }
256
+ let hours = Math.floor(totalSeconds / (secondsPerMinute * minutesPerHour));
257
+ totalSeconds %= secondsPerMinute * minutesPerHour;
258
+ let minutes = Math.floor(totalSeconds / secondsPerMinute);
259
+ let seconds = totalSeconds % secondsPerMinute;
260
+ const formatObj = {
261
+ d: days,
262
+ h: hours,
263
+ i: minutes,
264
+ s: seconds
265
+ };
266
+ let parseFormat = cFormat;
267
+ if (days === 0) {
268
+ parseFormat = cFormat.match(/{h}.*/g)[0];
269
+ if (hours === 0) {
270
+ parseFormat = cFormat.match(/{i}.*/g)[0];
271
+ if (minutes === 0) {
272
+ parseFormat = cFormat.match(/{s}.*/g)[0];
273
+ }
274
+ }
275
+ }
276
+ const time_str = parseFormat.replace(/{(y|m|d|h|i|s)+}/g, (result, key) => {
277
+ let value = formatObj[key];
278
+ if (result.length > 0 && value < 10 && value != 0) {
279
+ value = "0" + value;
280
+ }
281
+ return value || "00";
282
+ });
283
+ return time_str;
284
+ }
285
+ function uuid(type = "", length = 4, { emailStr = "@qq.com", timeStr = "{m}-{d} {h}:{i}:{s}", startStr = "", optionsIndex = null } = {}) {
286
+ let randomStr = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
287
+ let res = type;
288
+ if (reactivity.isRef(type)) {
289
+ type = reactivity.unref(type);
290
+ }
291
+ if (getType(type) === "array" && type.length > 0) {
292
+ let randNum = random(0, type.length - 1);
293
+ if (!length) {
294
+ return type[optionsIndex ?? randNum];
295
+ }
296
+ return type[optionsIndex ?? randNum][length === 4 ? "value" : length];
297
+ }
298
+ if (type === "phone") {
299
+ let prefixArray = new Array("130", "131", "132", "133", "135", "136", "137", "138", "170", "187", "189");
300
+ let i = parseInt(Math.random() * 10);
301
+ let res2 = prefixArray[i];
302
+ for (var j = 0; j < 8; j++) {
303
+ res2 += Math.floor(Math.random() * 10);
304
+ }
305
+ return res2;
306
+ }
307
+ if (type === "email") {
308
+ return uuid(startStr, length) + emailStr;
309
+ }
310
+ if (type === "time") {
311
+ return uuid(startStr, length) + " " + formatTime(/* @__PURE__ */ new Date(), timeStr);
312
+ }
313
+ if (type === "number") {
314
+ let randomStr2 = "123456789";
315
+ let res2 = "";
316
+ for (let i = length; i > 0; --i) {
317
+ res2 += randomStr2[Math.floor(Math.random() * randomStr2.length)];
318
+ }
319
+ return Number(res2);
320
+ }
321
+ if (type === "ip") {
322
+ let randomNum = random(1, 99);
323
+ return `10.0.11.` + randomNum;
324
+ }
325
+ if (type === "port") {
326
+ let randomNum = random(1, 65535);
327
+ return randomNum;
328
+ }
329
+ for (let i = length; i > 0; --i) {
330
+ res += randomStr[Math.floor(Math.random() * randomStr.length)];
331
+ }
332
+ return res;
333
+ }
334
+ function getType(type) {
335
+ if (typeof type === "object") {
336
+ const objType = Object.prototype.toString.call(type).slice(8, -1).toLowerCase();
337
+ return objType;
338
+ } else {
339
+ return typeof type;
340
+ }
341
+ }
342
+ function sleep(delay = 0, fn) {
343
+ return new Promise(
344
+ (resolve) => setTimeout(() => {
345
+ fn?.();
346
+ resolve();
347
+ }, delay)
348
+ );
349
+ }
350
+ function validate(type = "required", rules = {}, pureValid = false) {
351
+ if (getType(type) === "object") {
352
+ pureValid = rules || false;
353
+ rules = type;
354
+ type = "required";
355
+ }
356
+ let trigger = rules.trigger || [];
357
+ const typeMaps = ["required", "pwd", "number", "mobile", "between", "length", "same", "ip", "port", "custom"];
358
+ let parseRequired = rules.required ?? true;
359
+ if (!typeMaps.includes(type)) {
360
+ return {
361
+ required: parseRequired,
362
+ message: type,
363
+ trigger
364
+ };
365
+ }
366
+ if (type === "required") {
367
+ return {
368
+ required: parseRequired,
369
+ message: rules.message ?? "\u8BF7\u8F93\u5165",
370
+ trigger
371
+ };
372
+ }
373
+ if (type === "password") {
374
+ const validateName = (rule, value, callback) => {
375
+ let validFlag = /^[a-zA-Z0-9_-]+$/.test(value);
376
+ if (!validFlag) {
377
+ callback(new Error(rules.message || "\u5BC6\u7801\u53EA\u80FD\u7531\u82F1\u6587\u3001\u6570\u5B57\u3001\u4E0B\u5212\u7EBF\u3001\u4E2D\u5212\u7EBF\u7EC4\u6210"));
378
+ } else {
379
+ callback();
380
+ }
381
+ };
382
+ return {
383
+ validator: validateName,
384
+ trigger
385
+ };
386
+ }
387
+ if (type === "positive" || type === "number") {
388
+ return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u6574\u6570", pureValid, /^[1-9]+\d*$/);
389
+ }
390
+ if (type === "zeroPositive") {
391
+ return _validValue(rules, "\u8BF7\u8F93\u5165\u975E\u8D1F\u6574\u6570", pureValid, /^(0|[1-9]+\d*)$/);
392
+ }
393
+ if (type === "integer") {
394
+ return _validValue(rules, "\u8BF7\u8F93\u5165\u6574\u6570", pureValid, /^(0|[-]?[1-9]\d*)$/);
395
+ }
396
+ if (type === "decimal") {
397
+ return _validValue(rules, "\u8BF7\u8F93\u5165\u975E\u8D1F\u6570\u5B57, \u5305\u542B\u5C0F\u6570\u4E14\u6700\u591A2\u4F4D", pureValid, /(0|[1-9]\d*)(\.\d{1, 2})?|0\.\d{1,2}/);
398
+ }
399
+ if (type === "mobile") {
400
+ return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7", pureValid, /^[1][0-9]{10}$/);
401
+ }
402
+ if (type === "ip") {
403
+ return _validValue(
404
+ rules,
405
+ "\u8BF7\u8F93\u5165\u6B63\u786E\u7684ip\u5730\u5740",
406
+ pureValid,
407
+ /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
408
+ );
409
+ }
410
+ if (type === "between") {
411
+ let min = rules.min || 1;
412
+ let max = rules.max || 10;
413
+ const validateBetween = (rule, value, callback) => {
414
+ let validFlag = /^[0-9]+$/.test(value);
415
+ if (!validFlag) {
416
+ callback(new Error("\u8BF7\u8F93\u5165\u6570\u5B57"));
417
+ }
418
+ if (value < min) {
419
+ callback(new Error(`\u6570\u5B57\u4E0D\u80FD\u5C0F\u4E8E${min}`));
420
+ }
421
+ if (value > max) {
422
+ callback(new Error(`\u6570\u5B57\u4E0D\u80FD\u5927\u4E8E${max}`));
423
+ }
424
+ callback();
425
+ };
426
+ return {
427
+ validator: validateBetween,
428
+ trigger,
429
+ required: parseRequired
430
+ };
431
+ }
432
+ if (type === "length") {
433
+ return {
434
+ min: rules.min,
435
+ max: rules.max,
436
+ message: rules.message ?? `\u8BF7\u8F93\u5165${rules.min}\u5230${rules.max}\u4E2A\u5B57\u7B26`,
437
+ trigger,
438
+ required: parseRequired
439
+ };
440
+ }
441
+ if (type === "port") {
442
+ return _validValue(
443
+ rules,
444
+ "\u8BF7\u8F93\u51651-65535\u7684\u7AEF\u53E3\u53F7",
445
+ pureValid,
446
+ /^([1-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-5][0-5][0-3][0-5])$/
447
+ );
448
+ }
449
+ if (type === "same") {
450
+ const validateSame = (rule, value, callback) => {
451
+ let isSame = value === rules.value;
452
+ if (!isSame) {
453
+ const errMessage = rules.message || "\u5BC6\u7801\u548C\u786E\u8BA4\u5BC6\u7801\u8981\u4E00\u81F4";
454
+ callback(new Error(errMessage));
455
+ }
456
+ if (parseRequired && !value) {
457
+ callback(new Error(rules.message || "\u8BF7\u8F93\u5165"));
458
+ }
459
+ callback();
460
+ };
461
+ let res = {
462
+ validator: validateSame,
463
+ trigger,
464
+ required: parseRequired
465
+ };
466
+ return res;
467
+ }
468
+ if (type === "custom") {
469
+ if (pureValid) {
470
+ return _validValue(rules.value, rules.message, pureValid, rules.reg);
471
+ } else {
472
+ return _validValue(rules, rules.message, pureValid, rules.reg);
473
+ }
474
+ }
475
+ function _validValue(rules2, msg, pureValid2, reg) {
476
+ if (pureValid2 === true) {
477
+ return reg.test(rules2);
478
+ }
479
+ const validatePhone = (rule, value, callback) => {
480
+ let validFlag = reg.test(value);
481
+ if (!validFlag) {
482
+ callback(new Error(rules2.message ?? msg));
483
+ } else {
484
+ callback();
485
+ }
486
+ };
487
+ return {
488
+ validator: validatePhone,
489
+ required: rules2.required ?? true,
490
+ trigger
491
+ };
492
+ }
493
+ }
494
+ async function asyncWrapper(func, ...args) {
495
+ try {
496
+ const res = await func(...args);
497
+ return { res };
498
+ } catch (err) {
499
+ return { err };
500
+ }
501
+ }
502
+ function formatImg(photoName, addPath = "", { basePath = "assets/images" } = {}) {
503
+ if (photoName.startsWith("http") || photoName.startsWith("https")) {
504
+ return photoName;
505
+ }
506
+ if (photoName.indexOf(".") === -1) {
507
+ photoName = photoName + ".png";
508
+ }
509
+ const addLastSlash = addPath.endsWith("/") || !addPath ? addPath : `${addPath}/`;
510
+ const addLastBasePathSlash = basePath.endsWith("/") || !basePath ? basePath : `${basePath}/`;
511
+ let mergeSrc = `${addLastSlash}${photoName}`;
512
+ let res = new URL(`../${addLastBasePathSlash}${mergeSrc}`, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))).href;
513
+ return res;
514
+ }
515
+ const copy = (text, toastParams = {}) => {
516
+ const textarea = document.createElement("textarea");
517
+ textarea.value = text;
518
+ textarea.style.position = "fixed";
519
+ document.body.appendChild(textarea);
520
+ textarea.select();
521
+ document.execCommand("copy");
522
+ document.body.removeChild(textarea);
523
+ if (!toastParams.hideToast) {
524
+ $toast(text + "\u590D\u5236\u6210\u529F", toastParams);
525
+ }
526
+ };
527
+ function formatThousands(number) {
528
+ let matches = ("" + number).match(/^([\d,]+)(\.?)(\d+)?(\D+)?$/);
529
+ if (!matches) {
530
+ return number;
531
+ }
532
+ let numericString = matches[1].replace(/\D/g, "");
533
+ let decimalString = matches[3] ? `.${matches[3]}` : "";
534
+ let unit = matches[4] || "";
535
+ let numberWithSeparator = numericString.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
536
+ return `${numberWithSeparator}${decimalString}${unit}`;
537
+ }
538
+ function log(variableStr, variable, otherInfo = "") {
539
+ const stack = new Error().stack.split("\n")[2].trim();
540
+ const matchResult = stack.match(/\((.*):(\d+):(\d+)\)/);
541
+ let fileInfo = "";
542
+ try {
543
+ if (matchResult && otherInfo) {
544
+ const lineNumber = matchResult[2];
545
+ fileInfo = `vscode://file${JSON.parse(otherInfo)}:${lineNumber}`;
546
+ }
547
+ } catch (error) {
548
+ fileInfo = otherInfo;
549
+ }
550
+ if (reactivity.isRef(variable)) {
551
+ let unrefVariable = reactivity.unref(variable);
552
+ _log(reactivity.toRaw(unrefVariable));
553
+ } else {
554
+ _log(variable);
555
+ }
556
+ function _log(consoleData) {
557
+ if (getType2(consoleData) === "object" || getType2(consoleData) === "array") {
558
+ consola.consola.log(
559
+ `%c${variableStr} `,
560
+ "background:#fff; color: blue;font-size: 0.8em",
561
+ JSON.stringify(consoleData, null, " "),
562
+ `${fileInfo}`
563
+ );
564
+ } else {
565
+ consola.consola.log(`%c${variableStr} `, "background:#fff; color: blue;font-size: 0.8em", consoleData, `${fileInfo}`);
566
+ }
567
+ }
568
+ function getType2(type) {
569
+ if (typeof type === "object") {
570
+ const objType = Object.prototype.toString.call(type).slice(8, -1).toLowerCase();
571
+ return objType;
572
+ } else {
573
+ return typeof type;
574
+ }
575
+ }
576
+ }
577
+ function random(min = 0, max = 10) {
578
+ return Math.floor(Math.random() * (max - min + 1)) + min;
579
+ }
580
+ function toLine(text, connect = "-") {
581
+ let translateText = text.replace(/([A-Z])/g, (match, p1, offset, origin) => {
582
+ if (offset === 0) {
583
+ return `${match.toLocaleLowerCase()}`;
584
+ } else {
585
+ return `${connect}${match.toLocaleLowerCase()}`;
586
+ }
587
+ }).toLocaleLowerCase();
588
+ return translateText;
589
+ }
590
+ function processWidth(initValue, isBase = false) {
591
+ let value = reactivity.unref(initValue);
592
+ let res = "";
593
+ if (!value) {
594
+ return isBase ? value : {};
595
+ } else if (typeof value === "number") {
596
+ value = String(value);
597
+ }
598
+ if (value === "") {
599
+ return isBase ? value : {};
600
+ } else if (typeof value === "string" && !isNaN(value)) {
601
+ res = value + "px";
602
+ } else if (typeof value === "string" && /^[0-9]+(\.[0-9]+)?(px|%|em|rem|vw|vh|ch)*$/.test(value)) {
603
+ res = value;
604
+ } else {
605
+ console.warn(`${value} is Invalid unit provided`);
606
+ return value;
607
+ }
608
+ if (isBase) {
609
+ return res;
610
+ }
611
+ return { width: res };
612
+ }
613
+ function toFixed(value, options = {}) {
614
+ if (typeof options === "number") {
615
+ options = { digit: options };
616
+ }
617
+ let { digit = 2, prefix = "", suffix = "", unit = true } = options;
618
+ let matches = ("" + value).match(/^([\d,]+)(\.?)(\d+)?(\D+)?$/);
619
+ if (!matches) {
620
+ return value;
621
+ }
622
+ let numericString = matches[1].replace(/\D/g, "");
623
+ let decimalString = matches[3] ? `.${matches[3]}` : "";
624
+ let finalUnit = matches[4] || "";
625
+ let res = numericString;
626
+ if (isStringNumber(numericString) || isNumber(numericString)) {
627
+ res = Number(numericString + decimalString).toFixed(digit);
628
+ }
629
+ if (!unit) {
630
+ finalUnit = "";
631
+ }
632
+ return `${prefix}${res}${finalUnit}${suffix}`;
633
+ }
634
+ function formatBytes(bytes, { toFixed: toFixed2 = 2, thousands = true } = {}) {
635
+ if (isStringNumber(bytes) || isNumber(bytes)) {
636
+ bytes = Number(bytes);
637
+ } else {
638
+ return bytes;
639
+ }
640
+ if (bytes <= 0) {
641
+ return bytes.toFixed(toFixed2) + " B";
642
+ }
643
+ const k = 1024;
644
+ const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
645
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
646
+ let res = (bytes / Math.pow(k, i)).toFixed(toFixed2) + " " + sizes[i];
647
+ if (thousands) {
648
+ res = formatThousands(res);
649
+ }
650
+ return res;
651
+ }
652
+ function formatBytesConvert(oBytes, { thounsand = false, toFixed: toFixed2 = 0 } = {}) {
653
+ if (isStringNumber(oBytes) || isNumber(oBytes) || getType(oBytes) !== "string") {
654
+ return oBytes;
655
+ }
656
+ if (!oBytes) {
657
+ return oBytes;
658
+ }
659
+ const regex = /^\d{1,3}(,\d{3})*(\.\d+)?[a-zA-Z ]*$/;
660
+ let bytes = oBytes;
661
+ if (regex.test(oBytes)) {
662
+ bytes = oBytes.replace(/,/g, "");
663
+ if (isStringNumber(bytes) || isNumber(bytes) || getType(bytes) !== "string") {
664
+ return bytes;
665
+ }
666
+ }
667
+ const bytesRegex = /^(\d+(?:\.\d+)?)\s*([BKMGTPEZY]?B|Byte)$/i;
668
+ const units = {
669
+ B: 1,
670
+ BYTE: 1,
671
+ KB: 1024,
672
+ MB: 1024 ** 2,
673
+ GB: 1024 ** 3,
674
+ TB: 1024 ** 4,
675
+ PB: 1024 ** 5,
676
+ EB: 1024 ** 6,
677
+ ZB: 1024 ** 7,
678
+ YB: 1024 ** 8
679
+ };
680
+ const match = bytes.match(bytesRegex);
681
+ if (!match) {
682
+ console.warn("Invalid bytes format. Please provide a valid bytes string, like '100GB'.");
683
+ return;
684
+ }
685
+ const size = parseFloat(match[1]);
686
+ const unit = match[2].toUpperCase();
687
+ if (!units.hasOwnProperty(unit)) {
688
+ console.warn(
689
+ "Invalid bytes unit. Please provide a valid unit, like 'B', 'BYTE', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', or 'YB'."
690
+ );
691
+ return;
692
+ }
693
+ let finalRes = size * units[unit];
694
+ if (toFixed2) {
695
+ finalRes = parseFloat(finalRes.toFixed(toFixed2));
696
+ }
697
+ if (thounsand) {
698
+ finalRes = formatThousands(finalRes);
699
+ }
700
+ return finalRes;
701
+ }
702
+ function throttle(fn, delay = 1e3) {
703
+ let last = 0;
704
+ let timer = null;
705
+ return function() {
706
+ let context = this;
707
+ let args = arguments;
708
+ let now = +/* @__PURE__ */ new Date();
709
+ if (now - last < delay) {
710
+ clearTimeout(timer);
711
+ timer = setTimeout(function() {
712
+ last = now;
713
+ fn.apply(context, args);
714
+ }, delay);
715
+ } else {
716
+ last = now;
717
+ fn.apply(context, args);
718
+ }
719
+ };
720
+ }
721
+ function debounce(fn, delay = 1e3) {
722
+ let timer = null;
723
+ return function() {
724
+ if (timer) {
725
+ clearTimeout(timer);
11
726
  }
727
+ timer = setTimeout(() => {
728
+ fn.apply(this, arguments);
729
+ timer = null;
730
+ }, delay);
731
+ };
732
+ }
733
+ function confirm(message, options) {
734
+ const resolvedMessage = typeof message === "function" ? message() : message;
735
+ const elContext = elementPlus.ElMessageBox.install?.context || elementPlus.ElMessageBox._context || document.querySelector("#app")?._vue_app?._context;
736
+ const mergeOptions = {
737
+ title: "\u63D0\u793A",
738
+ draggable: true,
739
+ showCancelButton: false,
740
+ confirmButtonText: "\u786E\u5B9A",
741
+ dangerouslyUseHTMLString: true,
742
+ // 允许 HTML
743
+ appContext: elContext,
744
+ // 强制注入 Element Plus 的上下文
745
+ ...options
746
+ };
747
+ return elementPlus.ElMessageBox.confirm(resolvedMessage, mergeOptions);
748
+ }
749
+ function formatNewLines(str) {
750
+ if (!str || typeof str !== "string") {
751
+ return str;
12
752
  }
13
- })
753
+ str = str.replace(/\n/g, "<br>");
754
+ str = str.replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;");
755
+ return str;
756
+ }
757
+ function getVariable(propertyName) {
758
+ let res = getComputedStyle(document.documentElement).getPropertyValue(propertyName).trim();
759
+ return res;
760
+ }
14
761
 
15
- /** @type {import("/Users/andy/cyrd/oeos-components/packages/utils/src/index")} */
16
- module.exports = jiti("/Users/andy/cyrd/oeos-components/packages/utils/src/index.ts")
762
+ exports.$toast = $toast;
763
+ exports.asyncWrapper = asyncWrapper;
764
+ exports.clearStorage = clearStorage;
765
+ exports.clone = clone;
766
+ exports.confirm = confirm;
767
+ exports.copy = copy;
768
+ exports.debounce = debounce;
769
+ exports.formatBytes = formatBytes;
770
+ exports.formatBytesConvert = formatBytesConvert;
771
+ exports.formatDurationTime = formatDurationTime;
772
+ exports.formatImg = formatImg;
773
+ exports.formatNewLines = formatNewLines;
774
+ exports.formatThousands = formatThousands;
775
+ exports.formatTime = formatTime;
776
+ exports.getStorage = getStorage;
777
+ exports.getType = getType;
778
+ exports.getVariable = getVariable;
779
+ exports.isEmpty = isEmpty;
780
+ exports.isNumber = isNumber;
781
+ exports.isString = isString;
782
+ exports.isStringNumber = isStringNumber;
783
+ exports.log = log;
784
+ exports.merge = merge;
785
+ exports.notEmpty = notEmpty;
786
+ exports.processWidth = processWidth;
787
+ exports.random = random;
788
+ exports.setStorage = setStorage;
789
+ exports.sleep = sleep;
790
+ exports.throttle = throttle;
791
+ exports.toFixed = toFixed;
792
+ exports.toLine = toLine;
793
+ exports.uuid = uuid;
794
+ exports.validForm = validForm;
795
+ exports.validate = validate;