@oeos-components/utils 0.0.16 → 0.0.17

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
@@ -300,54 +300,63 @@ function formatDurationTime(timestamp, cFormat = "{d}\u5929{h}\u65F6{i}\u5206{s}
300
300
  });
301
301
  return time_str;
302
302
  }
303
- function uuid(type = "", length = 4, { emailStr = "@qq.com", timeStr = "{m}-{d} {h}:{i}:{s}", startStr = "", optionsIndex = null } = {}) {
304
- let randomStr = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
305
- let res = type;
306
- if (reactivity.isRef(type)) {
307
- type = reactivity.unref(type);
308
- }
309
- if (getType(type) === "array" && type.length > 0) {
310
- let randNum = random(0, type.length - 1);
311
- if (!length) {
312
- return type[optionsIndex ?? randNum];
303
+ function uuid(type = "", length = 4, options = {}) {
304
+ const { emailStr = "@qq.com", timeStr = "{y}-{m}-{d} {h}:{i}:{s}", startStr = "", optionsIndex = null } = options;
305
+ function isRef2(obj) {
306
+ return obj && typeof obj === "object" && obj._isRef === true;
307
+ }
308
+ function unref2(ref) {
309
+ return isRef2(ref) ? ref.value : ref;
310
+ }
311
+ function random2(min, max) {
312
+ return Math.floor(Math.random() * (max - min + 1) + min);
313
+ }
314
+ type = unref2(type);
315
+ if (Array.isArray(type)) {
316
+ if (type.length === 0) return "";
317
+ const randIndex = optionsIndex ?? random2(0, type.length - 1);
318
+ const selectedItem = type[randIndex];
319
+ if (typeof selectedItem === "object" && selectedItem !== null && "value" in selectedItem) {
320
+ return selectedItem.value;
313
321
  }
314
- return type[optionsIndex ?? randNum][length === 4 ? "value" : length];
322
+ return selectedItem;
315
323
  }
324
+ let randomChars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
325
+ let result = startStr;
316
326
  if (type === "phone") {
317
- let prefixArray = new Array("130", "131", "132", "133", "135", "136", "137", "138", "170", "187", "189");
318
- let i = parseInt(Math.random() * 10);
319
- let res2 = prefixArray[i];
320
- for (var j = 0; j < 8; j++) {
321
- res2 += Math.floor(Math.random() * 10);
327
+ const prefixes = ["130", "131", "132", "133", "135", "136", "137", "138", "170", "187", "189"];
328
+ result = prefixes[random2(0, prefixes.length - 1)];
329
+ for (let i = 0; i < 8; i++) {
330
+ result += Math.floor(Math.random() * 10);
322
331
  }
323
- return res2;
332
+ return result;
324
333
  }
325
334
  if (type === "email") {
326
- return uuid(startStr, length) + emailStr;
335
+ result = uuid(startStr, length) + emailStr;
336
+ return result;
327
337
  }
328
338
  if (type === "time") {
329
- return uuid(startStr, length) + " " + formatTime(/* @__PURE__ */ new Date(), timeStr);
339
+ return uuid(startStr, length, options) + " " + formatTime(/* @__PURE__ */ new Date(), timeStr);
330
340
  }
331
341
  if (type === "number") {
332
- let randomStr2 = "123456789";
333
- let res2 = "";
334
- for (let i = length; i > 0; --i) {
335
- res2 += randomStr2[Math.floor(Math.random() * randomStr2.length)];
342
+ const numChars = "123456789";
343
+ result = "";
344
+ for (let i = 0; i < length; i++) {
345
+ result += numChars[random2(0, numChars.length - 1)];
336
346
  }
337
- return Number(res2);
347
+ return Number(result);
338
348
  }
339
349
  if (type === "ip") {
340
- let randomNum = random(1, 99);
341
- return `10.0.11.` + randomNum;
350
+ const randomNum = random2(1, 99);
351
+ return `10.0.11.${randomNum}`;
342
352
  }
343
353
  if (type === "port") {
344
- let randomNum = random(1, 65535);
345
- return randomNum;
354
+ return random2(1, 65535);
346
355
  }
347
- for (let i = length; i > 0; --i) {
348
- res += randomStr[Math.floor(Math.random() * randomStr.length)];
356
+ for (let i = 0; i < length; i++) {
357
+ result += randomChars[random2(0, randomChars.length - 1)];
349
358
  }
350
- return res;
359
+ return result;
351
360
  }
352
361
  function getType(type) {
353
362
  if (typeof type === "object") {
@@ -365,6 +374,13 @@ function sleep(delay = 0, fn) {
365
374
  }, delay)
366
375
  );
367
376
  }
377
+ function validateTrigger(type = "required", rules = {}, pureValid = false) {
378
+ let mergeRules = {
379
+ trigger: ["blur", "change"],
380
+ ...rules
381
+ };
382
+ return validate(type, mergeRules, pureValid);
383
+ }
368
384
  function validate(type = "required", rules = {}, pureValid = false) {
369
385
  if (getType(type) === "object") {
370
386
  pureValid = rules || false;
@@ -372,7 +388,7 @@ function validate(type = "required", rules = {}, pureValid = false) {
372
388
  type = "required";
373
389
  }
374
390
  let trigger = rules.trigger || [];
375
- const typeMaps = ["required", "pwd", "number", "mobile", "between", "length", "same", "ip", "port", "custom"];
391
+ const typeMaps = ["required", "pwd", "number", "mobile", "email", "between", "length", "same", "ip", "port", "custom"];
376
392
  let parseRequired = rules.required ?? true;
377
393
  if (!typeMaps.includes(type)) {
378
394
  return {
@@ -417,6 +433,9 @@ function validate(type = "required", rules = {}, pureValid = false) {
417
433
  if (type === "mobile") {
418
434
  return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7", pureValid, /^[1][0-9]{10}$/);
419
435
  }
436
+ if (type === "email") {
437
+ return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u786E\u7684email", pureValid, /^[^\s@]+@[^\s@]+\.[^\s@]+$/);
438
+ }
420
439
  if (type === "ip") {
421
440
  return _validValue(
422
441
  rules,
@@ -426,17 +445,17 @@ function validate(type = "required", rules = {}, pureValid = false) {
426
445
  );
427
446
  }
428
447
  if (type === "between") {
429
- let min = rules.min || 1;
430
- let max = rules.max || 10;
448
+ let min = rules.min;
449
+ let max = rules.max;
431
450
  const validateBetween = (rule, value, callback) => {
432
- let validFlag = /^[0-9]+$/.test(value);
451
+ let validFlag = /^-?[0-9]+$/.test(value);
433
452
  if (!validFlag) {
434
453
  callback(new Error("\u8BF7\u8F93\u5165\u6570\u5B57"));
435
454
  }
436
- if (value < min) {
455
+ if (value < min && min !== void 0) {
437
456
  callback(new Error(`\u6570\u5B57\u4E0D\u80FD\u5C0F\u4E8E${min}`));
438
457
  }
439
- if (value > max) {
458
+ if (value > max && max !== void 0) {
440
459
  callback(new Error(`\u6570\u5B57\u4E0D\u80FD\u5927\u4E8E${max}`));
441
460
  }
442
461
  callback();
@@ -836,3 +855,4 @@ exports.tryCatch = tryCatch;
836
855
  exports.uuid = uuid;
837
856
  exports.validForm = validForm;
838
857
  exports.validate = validate;
858
+ exports.validateTrigger = validateTrigger;
package/dist/index.d.cts CHANGED
@@ -146,15 +146,15 @@ declare function formatTime(time: any, cFormat?: string): any;
146
146
  declare function formatDurationTime(timestamp: any, cFormat?: string): string;
147
147
  /**
148
148
  * 生成 UUID
149
- * @param {string} [type=''] - 生成 UUID 的类型,可以是 'phone', 'email', 'time', 'number' 或空字符串
150
- * @param {number} [length=4] - 生成字符串的长度
151
- * @param {object} [options={}] - 额外的选项
152
- * @param {string} [options.emailStr='@qq.com'] - 生成 email 时使用的后缀
153
- * @param {string} [options.timeStr='{m}-{d} {h}:{i}:{s}'] - 生成时间字符串的格式
154
- * @param {string} [options.startStr=''] - 起始字符串
155
- * @param {number|null} [options.optionsIndex=null] - 数组索引
156
- * @returns {string|number} - 生成的 UUID
157
- * uuid("名字") => 名字hc8f
149
+ * @param type - 生成 UUID 的类型,可以是 'phone', 'email', 'time', 'number', 'ip', 'port' 或空字符串
150
+ * @param length - 生成字符串的长度(默认为4)
151
+ * @param options - 额外的选项
152
+ * @param options.emailStr - 生成 email 时使用的后缀(默认为 '@qq.com')
153
+ * @param options.timeStr - 生成时间字符串的格式(默认为 '{m}-{d} {h}:{i}:{s}'
154
+ * @param options.startStr - 起始字符串(默认为空)
155
+ * @param options.optionsIndex - 数组索引(默认为随机)
156
+ * @returns 生成的 UUID (字符串或数字)
157
+ * * uuid("名字") => 名字hc8f
158
158
  * uuid() => abcd
159
159
  * uuid('time') => 25MR 10-27 17:34:01
160
160
  * uuid('time', 0, {startStr:'andy', timeStr:"{h}:{i}:{s}"}) => andy 17:38:23
@@ -163,12 +163,15 @@ declare function formatDurationTime(timestamp: any, cFormat?: string): string;
163
163
  * uuid('number') => 2319
164
164
  * uuid([ { label: "小泽泽", value: "xzz" },{ label: "小月月", value: "xyy" }]) => xzz
165
165
  */
166
- declare function uuid(type?: string, length?: number, { emailStr, timeStr, startStr, optionsIndex }?: {
167
- emailStr?: string | undefined;
168
- timeStr?: string | undefined;
169
- startStr?: string | undefined;
170
- optionsIndex?: null | undefined;
171
- }): any;
166
+ declare function uuid(type?: string | Array<{
167
+ label: string;
168
+ value: any;
169
+ }>, length?: number, options?: {
170
+ emailStr?: string;
171
+ timeStr?: string;
172
+ startStr?: string;
173
+ optionsIndex?: number | null;
174
+ }): string | number;
172
175
  /**
173
176
  * 判断传入参数的类型
174
177
  * @param {*} type
@@ -229,6 +232,7 @@ confirmRegPwd: [
229
232
  let ip = proxy.validate('ip', 122322, true)
230
233
  let custom = proxy.validate('custom', { value: -123, reg: /^-\d+\.?\d{0,2}$/ }, true)
231
234
  */
235
+ declare function validateTrigger(type?: string, rules?: {}, pureValid?: boolean): any;
232
236
  declare function validate(type?: string, rules?: {}, pureValid?: boolean): any;
233
237
  /**
234
238
  *
@@ -396,4 +400,4 @@ declare function formatNewLines(str: any): any;
396
400
  * */
397
401
  declare function getVariable(propertyName: any): string;
398
402
 
399
- export { $toast, asyncWrapper, clearStorage, clone, confirm, copy, debounce, formatBytes, formatBytesConvert, formatDurationTime, formatImg, formatNewLines, formatThousands, formatTime, getStorage, getType, getVariable, isEmpty, isNumber, isString, isStringNumber, log, merge, notEmpty, processWidth, random, setStorage, sleep, throttle, toFixed, toLine, tryCatch, uuid, validForm, validate };
403
+ export { $toast, asyncWrapper, clearStorage, clone, confirm, copy, debounce, formatBytes, formatBytesConvert, formatDurationTime, formatImg, formatNewLines, formatThousands, formatTime, getStorage, getType, getVariable, isEmpty, isNumber, isString, isStringNumber, log, merge, notEmpty, processWidth, random, setStorage, sleep, throttle, toFixed, toLine, tryCatch, uuid, validForm, validate, validateTrigger };
package/dist/index.d.mts CHANGED
@@ -146,15 +146,15 @@ declare function formatTime(time: any, cFormat?: string): any;
146
146
  declare function formatDurationTime(timestamp: any, cFormat?: string): string;
147
147
  /**
148
148
  * 生成 UUID
149
- * @param {string} [type=''] - 生成 UUID 的类型,可以是 'phone', 'email', 'time', 'number' 或空字符串
150
- * @param {number} [length=4] - 生成字符串的长度
151
- * @param {object} [options={}] - 额外的选项
152
- * @param {string} [options.emailStr='@qq.com'] - 生成 email 时使用的后缀
153
- * @param {string} [options.timeStr='{m}-{d} {h}:{i}:{s}'] - 生成时间字符串的格式
154
- * @param {string} [options.startStr=''] - 起始字符串
155
- * @param {number|null} [options.optionsIndex=null] - 数组索引
156
- * @returns {string|number} - 生成的 UUID
157
- * uuid("名字") => 名字hc8f
149
+ * @param type - 生成 UUID 的类型,可以是 'phone', 'email', 'time', 'number', 'ip', 'port' 或空字符串
150
+ * @param length - 生成字符串的长度(默认为4)
151
+ * @param options - 额外的选项
152
+ * @param options.emailStr - 生成 email 时使用的后缀(默认为 '@qq.com')
153
+ * @param options.timeStr - 生成时间字符串的格式(默认为 '{m}-{d} {h}:{i}:{s}'
154
+ * @param options.startStr - 起始字符串(默认为空)
155
+ * @param options.optionsIndex - 数组索引(默认为随机)
156
+ * @returns 生成的 UUID (字符串或数字)
157
+ * * uuid("名字") => 名字hc8f
158
158
  * uuid() => abcd
159
159
  * uuid('time') => 25MR 10-27 17:34:01
160
160
  * uuid('time', 0, {startStr:'andy', timeStr:"{h}:{i}:{s}"}) => andy 17:38:23
@@ -163,12 +163,15 @@ declare function formatDurationTime(timestamp: any, cFormat?: string): string;
163
163
  * uuid('number') => 2319
164
164
  * uuid([ { label: "小泽泽", value: "xzz" },{ label: "小月月", value: "xyy" }]) => xzz
165
165
  */
166
- declare function uuid(type?: string, length?: number, { emailStr, timeStr, startStr, optionsIndex }?: {
167
- emailStr?: string | undefined;
168
- timeStr?: string | undefined;
169
- startStr?: string | undefined;
170
- optionsIndex?: null | undefined;
171
- }): any;
166
+ declare function uuid(type?: string | Array<{
167
+ label: string;
168
+ value: any;
169
+ }>, length?: number, options?: {
170
+ emailStr?: string;
171
+ timeStr?: string;
172
+ startStr?: string;
173
+ optionsIndex?: number | null;
174
+ }): string | number;
172
175
  /**
173
176
  * 判断传入参数的类型
174
177
  * @param {*} type
@@ -229,6 +232,7 @@ confirmRegPwd: [
229
232
  let ip = proxy.validate('ip', 122322, true)
230
233
  let custom = proxy.validate('custom', { value: -123, reg: /^-\d+\.?\d{0,2}$/ }, true)
231
234
  */
235
+ declare function validateTrigger(type?: string, rules?: {}, pureValid?: boolean): any;
232
236
  declare function validate(type?: string, rules?: {}, pureValid?: boolean): any;
233
237
  /**
234
238
  *
@@ -396,4 +400,4 @@ declare function formatNewLines(str: any): any;
396
400
  * */
397
401
  declare function getVariable(propertyName: any): string;
398
402
 
399
- export { $toast, asyncWrapper, clearStorage, clone, confirm, copy, debounce, formatBytes, formatBytesConvert, formatDurationTime, formatImg, formatNewLines, formatThousands, formatTime, getStorage, getType, getVariable, isEmpty, isNumber, isString, isStringNumber, log, merge, notEmpty, processWidth, random, setStorage, sleep, throttle, toFixed, toLine, tryCatch, uuid, validForm, validate };
403
+ export { $toast, asyncWrapper, clearStorage, clone, confirm, copy, debounce, formatBytes, formatBytesConvert, formatDurationTime, formatImg, formatNewLines, formatThousands, formatTime, getStorage, getType, getVariable, isEmpty, isNumber, isString, isStringNumber, log, merge, notEmpty, processWidth, random, setStorage, sleep, throttle, toFixed, toLine, tryCatch, uuid, validForm, validate, validateTrigger };
package/dist/index.d.ts CHANGED
@@ -146,15 +146,15 @@ declare function formatTime(time: any, cFormat?: string): any;
146
146
  declare function formatDurationTime(timestamp: any, cFormat?: string): string;
147
147
  /**
148
148
  * 生成 UUID
149
- * @param {string} [type=''] - 生成 UUID 的类型,可以是 'phone', 'email', 'time', 'number' 或空字符串
150
- * @param {number} [length=4] - 生成字符串的长度
151
- * @param {object} [options={}] - 额外的选项
152
- * @param {string} [options.emailStr='@qq.com'] - 生成 email 时使用的后缀
153
- * @param {string} [options.timeStr='{m}-{d} {h}:{i}:{s}'] - 生成时间字符串的格式
154
- * @param {string} [options.startStr=''] - 起始字符串
155
- * @param {number|null} [options.optionsIndex=null] - 数组索引
156
- * @returns {string|number} - 生成的 UUID
157
- * uuid("名字") => 名字hc8f
149
+ * @param type - 生成 UUID 的类型,可以是 'phone', 'email', 'time', 'number', 'ip', 'port' 或空字符串
150
+ * @param length - 生成字符串的长度(默认为4)
151
+ * @param options - 额外的选项
152
+ * @param options.emailStr - 生成 email 时使用的后缀(默认为 '@qq.com')
153
+ * @param options.timeStr - 生成时间字符串的格式(默认为 '{m}-{d} {h}:{i}:{s}'
154
+ * @param options.startStr - 起始字符串(默认为空)
155
+ * @param options.optionsIndex - 数组索引(默认为随机)
156
+ * @returns 生成的 UUID (字符串或数字)
157
+ * * uuid("名字") => 名字hc8f
158
158
  * uuid() => abcd
159
159
  * uuid('time') => 25MR 10-27 17:34:01
160
160
  * uuid('time', 0, {startStr:'andy', timeStr:"{h}:{i}:{s}"}) => andy 17:38:23
@@ -163,12 +163,15 @@ declare function formatDurationTime(timestamp: any, cFormat?: string): string;
163
163
  * uuid('number') => 2319
164
164
  * uuid([ { label: "小泽泽", value: "xzz" },{ label: "小月月", value: "xyy" }]) => xzz
165
165
  */
166
- declare function uuid(type?: string, length?: number, { emailStr, timeStr, startStr, optionsIndex }?: {
167
- emailStr?: string | undefined;
168
- timeStr?: string | undefined;
169
- startStr?: string | undefined;
170
- optionsIndex?: null | undefined;
171
- }): any;
166
+ declare function uuid(type?: string | Array<{
167
+ label: string;
168
+ value: any;
169
+ }>, length?: number, options?: {
170
+ emailStr?: string;
171
+ timeStr?: string;
172
+ startStr?: string;
173
+ optionsIndex?: number | null;
174
+ }): string | number;
172
175
  /**
173
176
  * 判断传入参数的类型
174
177
  * @param {*} type
@@ -229,6 +232,7 @@ confirmRegPwd: [
229
232
  let ip = proxy.validate('ip', 122322, true)
230
233
  let custom = proxy.validate('custom', { value: -123, reg: /^-\d+\.?\d{0,2}$/ }, true)
231
234
  */
235
+ declare function validateTrigger(type?: string, rules?: {}, pureValid?: boolean): any;
232
236
  declare function validate(type?: string, rules?: {}, pureValid?: boolean): any;
233
237
  /**
234
238
  *
@@ -396,4 +400,4 @@ declare function formatNewLines(str: any): any;
396
400
  * */
397
401
  declare function getVariable(propertyName: any): string;
398
402
 
399
- export { $toast, asyncWrapper, clearStorage, clone, confirm, copy, debounce, formatBytes, formatBytesConvert, formatDurationTime, formatImg, formatNewLines, formatThousands, formatTime, getStorage, getType, getVariable, isEmpty, isNumber, isString, isStringNumber, log, merge, notEmpty, processWidth, random, setStorage, sleep, throttle, toFixed, toLine, tryCatch, uuid, validForm, validate };
403
+ export { $toast, asyncWrapper, clearStorage, clone, confirm, copy, debounce, formatBytes, formatBytesConvert, formatDurationTime, formatImg, formatNewLines, formatThousands, formatTime, getStorage, getType, getVariable, isEmpty, isNumber, isString, isStringNumber, log, merge, notEmpty, processWidth, random, setStorage, sleep, throttle, toFixed, toLine, tryCatch, uuid, validForm, validate, validateTrigger };
package/dist/index.mjs CHANGED
@@ -297,54 +297,63 @@ function formatDurationTime(timestamp, cFormat = "{d}\u5929{h}\u65F6{i}\u5206{s}
297
297
  });
298
298
  return time_str;
299
299
  }
300
- function uuid(type = "", length = 4, { emailStr = "@qq.com", timeStr = "{m}-{d} {h}:{i}:{s}", startStr = "", optionsIndex = null } = {}) {
301
- let randomStr = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
302
- let res = type;
303
- if (isRef(type)) {
304
- type = unref(type);
305
- }
306
- if (getType(type) === "array" && type.length > 0) {
307
- let randNum = random(0, type.length - 1);
308
- if (!length) {
309
- return type[optionsIndex ?? randNum];
300
+ function uuid(type = "", length = 4, options = {}) {
301
+ const { emailStr = "@qq.com", timeStr = "{y}-{m}-{d} {h}:{i}:{s}", startStr = "", optionsIndex = null } = options;
302
+ function isRef2(obj) {
303
+ return obj && typeof obj === "object" && obj._isRef === true;
304
+ }
305
+ function unref2(ref) {
306
+ return isRef2(ref) ? ref.value : ref;
307
+ }
308
+ function random2(min, max) {
309
+ return Math.floor(Math.random() * (max - min + 1) + min);
310
+ }
311
+ type = unref2(type);
312
+ if (Array.isArray(type)) {
313
+ if (type.length === 0) return "";
314
+ const randIndex = optionsIndex ?? random2(0, type.length - 1);
315
+ const selectedItem = type[randIndex];
316
+ if (typeof selectedItem === "object" && selectedItem !== null && "value" in selectedItem) {
317
+ return selectedItem.value;
310
318
  }
311
- return type[optionsIndex ?? randNum][length === 4 ? "value" : length];
319
+ return selectedItem;
312
320
  }
321
+ let randomChars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
322
+ let result = startStr;
313
323
  if (type === "phone") {
314
- let prefixArray = new Array("130", "131", "132", "133", "135", "136", "137", "138", "170", "187", "189");
315
- let i = parseInt(Math.random() * 10);
316
- let res2 = prefixArray[i];
317
- for (var j = 0; j < 8; j++) {
318
- res2 += Math.floor(Math.random() * 10);
324
+ const prefixes = ["130", "131", "132", "133", "135", "136", "137", "138", "170", "187", "189"];
325
+ result = prefixes[random2(0, prefixes.length - 1)];
326
+ for (let i = 0; i < 8; i++) {
327
+ result += Math.floor(Math.random() * 10);
319
328
  }
320
- return res2;
329
+ return result;
321
330
  }
322
331
  if (type === "email") {
323
- return uuid(startStr, length) + emailStr;
332
+ result = uuid(startStr, length) + emailStr;
333
+ return result;
324
334
  }
325
335
  if (type === "time") {
326
- return uuid(startStr, length) + " " + formatTime(/* @__PURE__ */ new Date(), timeStr);
336
+ return uuid(startStr, length, options) + " " + formatTime(/* @__PURE__ */ new Date(), timeStr);
327
337
  }
328
338
  if (type === "number") {
329
- let randomStr2 = "123456789";
330
- let res2 = "";
331
- for (let i = length; i > 0; --i) {
332
- res2 += randomStr2[Math.floor(Math.random() * randomStr2.length)];
339
+ const numChars = "123456789";
340
+ result = "";
341
+ for (let i = 0; i < length; i++) {
342
+ result += numChars[random2(0, numChars.length - 1)];
333
343
  }
334
- return Number(res2);
344
+ return Number(result);
335
345
  }
336
346
  if (type === "ip") {
337
- let randomNum = random(1, 99);
338
- return `10.0.11.` + randomNum;
347
+ const randomNum = random2(1, 99);
348
+ return `10.0.11.${randomNum}`;
339
349
  }
340
350
  if (type === "port") {
341
- let randomNum = random(1, 65535);
342
- return randomNum;
351
+ return random2(1, 65535);
343
352
  }
344
- for (let i = length; i > 0; --i) {
345
- res += randomStr[Math.floor(Math.random() * randomStr.length)];
353
+ for (let i = 0; i < length; i++) {
354
+ result += randomChars[random2(0, randomChars.length - 1)];
346
355
  }
347
- return res;
356
+ return result;
348
357
  }
349
358
  function getType(type) {
350
359
  if (typeof type === "object") {
@@ -362,6 +371,13 @@ function sleep(delay = 0, fn) {
362
371
  }, delay)
363
372
  );
364
373
  }
374
+ function validateTrigger(type = "required", rules = {}, pureValid = false) {
375
+ let mergeRules = {
376
+ trigger: ["blur", "change"],
377
+ ...rules
378
+ };
379
+ return validate(type, mergeRules, pureValid);
380
+ }
365
381
  function validate(type = "required", rules = {}, pureValid = false) {
366
382
  if (getType(type) === "object") {
367
383
  pureValid = rules || false;
@@ -369,7 +385,7 @@ function validate(type = "required", rules = {}, pureValid = false) {
369
385
  type = "required";
370
386
  }
371
387
  let trigger = rules.trigger || [];
372
- const typeMaps = ["required", "pwd", "number", "mobile", "between", "length", "same", "ip", "port", "custom"];
388
+ const typeMaps = ["required", "pwd", "number", "mobile", "email", "between", "length", "same", "ip", "port", "custom"];
373
389
  let parseRequired = rules.required ?? true;
374
390
  if (!typeMaps.includes(type)) {
375
391
  return {
@@ -414,6 +430,9 @@ function validate(type = "required", rules = {}, pureValid = false) {
414
430
  if (type === "mobile") {
415
431
  return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7", pureValid, /^[1][0-9]{10}$/);
416
432
  }
433
+ if (type === "email") {
434
+ return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u786E\u7684email", pureValid, /^[^\s@]+@[^\s@]+\.[^\s@]+$/);
435
+ }
417
436
  if (type === "ip") {
418
437
  return _validValue(
419
438
  rules,
@@ -423,17 +442,17 @@ function validate(type = "required", rules = {}, pureValid = false) {
423
442
  );
424
443
  }
425
444
  if (type === "between") {
426
- let min = rules.min || 1;
427
- let max = rules.max || 10;
445
+ let min = rules.min;
446
+ let max = rules.max;
428
447
  const validateBetween = (rule, value, callback) => {
429
- let validFlag = /^[0-9]+$/.test(value);
448
+ let validFlag = /^-?[0-9]+$/.test(value);
430
449
  if (!validFlag) {
431
450
  callback(new Error("\u8BF7\u8F93\u5165\u6570\u5B57"));
432
451
  }
433
- if (value < min) {
452
+ if (value < min && min !== void 0) {
434
453
  callback(new Error(`\u6570\u5B57\u4E0D\u80FD\u5C0F\u4E8E${min}`));
435
454
  }
436
- if (value > max) {
455
+ if (value > max && max !== void 0) {
437
456
  callback(new Error(`\u6570\u5B57\u4E0D\u80FD\u5927\u4E8E${max}`));
438
457
  }
439
458
  callback();
@@ -798,4 +817,4 @@ function getVariable(propertyName) {
798
817
  return res;
799
818
  }
800
819
 
801
- export { $toast, asyncWrapper, clearStorage, clone, confirm, copy, debounce, formatBytes, formatBytesConvert, formatDurationTime, formatImg, formatNewLines, formatThousands, formatTime, getStorage, getType, getVariable, isEmpty, isNumber, isString, isStringNumber, log, merge, notEmpty, processWidth, random, setStorage, sleep, throttle, toFixed, toLine, tryCatch, uuid, validForm, validate };
820
+ export { $toast, asyncWrapper, clearStorage, clone, confirm, copy, debounce, formatBytes, formatBytesConvert, formatDurationTime, formatImg, formatNewLines, formatThousands, formatTime, getStorage, getType, getVariable, isEmpty, isNumber, isString, isStringNumber, log, merge, notEmpty, processWidth, random, setStorage, sleep, throttle, toFixed, toLine, tryCatch, uuid, validForm, validate, validateTrigger };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oeos-components/utils",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "description": "utils of oeos-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -25,7 +25,7 @@
25
25
  "@vue/reactivity": "^3.5.18",
26
26
  "@vue/shared": "^3.5.18",
27
27
  "consola": "^3.4.2",
28
- "element-plus": "^2.10.4",
28
+ "element-plus": "^2.11.5",
29
29
  "es-toolkit": "^1.39.10",
30
30
  "lodash-es": "^4.17.21",
31
31
  "vue": "3.4.15"