@sybz-components/utils 0.0.10 → 0.0.11

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/base.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  require('vue');
4
4
  require('consola');
5
5
  require('es-toolkit');
6
- const format = require('./shared/utils.BaNHAtTs.cjs');
6
+ const format = require('./shared/utils.D_mBxLLy.cjs');
7
7
  require('element-plus');
8
8
  require('./is.cjs');
9
9
 
@@ -33,4 +33,4 @@ exports.toLine = format.toLine;
33
33
  exports.tryCatch = format.tryCatch;
34
34
  exports.validate = format.validate;
35
35
  exports.validateForm = format.validateForm;
36
- exports.validateTrigger = format.validateTrigger;
36
+ exports.validateOnSubmit = format.validateOnSubmit;
package/dist/base.d.cts CHANGED
@@ -12,6 +12,7 @@ type WidthStyleResult = {
12
12
  };
13
13
  type ValidateTriggerType = 'blur' | 'change';
14
14
  type ValidateInput = ValidateRules | ValidatePrimitiveValue;
15
+ type ValidateTypeInput = string | ValidateRules;
15
16
  type ValidateRuleResult = {
16
17
  required?: boolean;
17
18
  message?: string;
@@ -74,6 +75,10 @@ interface MockValueOptions {
74
75
  optionsIndex?: number | null;
75
76
  }
76
77
  interface ValidateRules {
78
+ /**
79
+ * 校验类型。作为 `validate({ type: 'mobile' })` 使用时生效。
80
+ */
81
+ type?: string;
77
82
  /**
78
83
  * 校验失败提示文案。
79
84
  */
@@ -365,7 +370,7 @@ declare function getType(type: unknown): string;
365
370
  */
366
371
  declare function delay(delay?: number, fn?: () => void): Promise<void>;
367
372
  /**
368
- * 为 `validate` 预置默认触发时机 `['blur', 'change']`。
373
+ * 为 `validate` 预置空触发时机,只在提交或手动调用表单校验时触发。
369
374
  *
370
375
  * @param type 校验类型。
371
376
  * @param rules 校验规则。
@@ -373,10 +378,10 @@ declare function delay(delay?: number, fn?: () => void): Promise<void>;
373
378
  * @returns 与 `validate` 一致。
374
379
  *
375
380
  * @example
376
- * const rule = validateTrigger('required', { message: '请输入名称' })
381
+ * const rule = validateOnSubmit('required', { message: '请输入名称' })
377
382
  */
378
- declare function validateTrigger(type?: string, rules?: ValidateRules, pureValid?: boolean): boolean | ValidateRuleResult;
379
- declare function validate(type?: string, rules?: ValidateInput, pureValid?: boolean): ValidateRuleResult | boolean;
383
+ declare function validateOnSubmit(type?: ValidateTypeInput, rules?: ValidateInput | boolean, pureValid?: boolean): ValidateRuleResult | boolean;
384
+ declare function validate(type?: ValidateTypeInput, rules?: ValidateInput | boolean, pureValid?: boolean): ValidateRuleResult | boolean;
380
385
  /**
381
386
  * 复制文本到剪贴板。
382
387
  *
@@ -559,4 +564,4 @@ declare function getUtilsBuildTime(fallback?: string): string;
559
564
  */
560
565
  declare function test(): string;
561
566
 
562
- export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateTrigger };
567
+ export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit };
package/dist/base.d.mts CHANGED
@@ -12,6 +12,7 @@ type WidthStyleResult = {
12
12
  };
13
13
  type ValidateTriggerType = 'blur' | 'change';
14
14
  type ValidateInput = ValidateRules | ValidatePrimitiveValue;
15
+ type ValidateTypeInput = string | ValidateRules;
15
16
  type ValidateRuleResult = {
16
17
  required?: boolean;
17
18
  message?: string;
@@ -74,6 +75,10 @@ interface MockValueOptions {
74
75
  optionsIndex?: number | null;
75
76
  }
76
77
  interface ValidateRules {
78
+ /**
79
+ * 校验类型。作为 `validate({ type: 'mobile' })` 使用时生效。
80
+ */
81
+ type?: string;
77
82
  /**
78
83
  * 校验失败提示文案。
79
84
  */
@@ -365,7 +370,7 @@ declare function getType(type: unknown): string;
365
370
  */
366
371
  declare function delay(delay?: number, fn?: () => void): Promise<void>;
367
372
  /**
368
- * 为 `validate` 预置默认触发时机 `['blur', 'change']`。
373
+ * 为 `validate` 预置空触发时机,只在提交或手动调用表单校验时触发。
369
374
  *
370
375
  * @param type 校验类型。
371
376
  * @param rules 校验规则。
@@ -373,10 +378,10 @@ declare function delay(delay?: number, fn?: () => void): Promise<void>;
373
378
  * @returns 与 `validate` 一致。
374
379
  *
375
380
  * @example
376
- * const rule = validateTrigger('required', { message: '请输入名称' })
381
+ * const rule = validateOnSubmit('required', { message: '请输入名称' })
377
382
  */
378
- declare function validateTrigger(type?: string, rules?: ValidateRules, pureValid?: boolean): boolean | ValidateRuleResult;
379
- declare function validate(type?: string, rules?: ValidateInput, pureValid?: boolean): ValidateRuleResult | boolean;
383
+ declare function validateOnSubmit(type?: ValidateTypeInput, rules?: ValidateInput | boolean, pureValid?: boolean): ValidateRuleResult | boolean;
384
+ declare function validate(type?: ValidateTypeInput, rules?: ValidateInput | boolean, pureValid?: boolean): ValidateRuleResult | boolean;
380
385
  /**
381
386
  * 复制文本到剪贴板。
382
387
  *
@@ -559,4 +564,4 @@ declare function getUtilsBuildTime(fallback?: string): string;
559
564
  */
560
565
  declare function test(): string;
561
566
 
562
- export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateTrigger };
567
+ export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit };
package/dist/base.d.ts CHANGED
@@ -12,6 +12,7 @@ type WidthStyleResult = {
12
12
  };
13
13
  type ValidateTriggerType = 'blur' | 'change';
14
14
  type ValidateInput = ValidateRules | ValidatePrimitiveValue;
15
+ type ValidateTypeInput = string | ValidateRules;
15
16
  type ValidateRuleResult = {
16
17
  required?: boolean;
17
18
  message?: string;
@@ -74,6 +75,10 @@ interface MockValueOptions {
74
75
  optionsIndex?: number | null;
75
76
  }
76
77
  interface ValidateRules {
78
+ /**
79
+ * 校验类型。作为 `validate({ type: 'mobile' })` 使用时生效。
80
+ */
81
+ type?: string;
77
82
  /**
78
83
  * 校验失败提示文案。
79
84
  */
@@ -365,7 +370,7 @@ declare function getType(type: unknown): string;
365
370
  */
366
371
  declare function delay(delay?: number, fn?: () => void): Promise<void>;
367
372
  /**
368
- * 为 `validate` 预置默认触发时机 `['blur', 'change']`。
373
+ * 为 `validate` 预置空触发时机,只在提交或手动调用表单校验时触发。
369
374
  *
370
375
  * @param type 校验类型。
371
376
  * @param rules 校验规则。
@@ -373,10 +378,10 @@ declare function delay(delay?: number, fn?: () => void): Promise<void>;
373
378
  * @returns 与 `validate` 一致。
374
379
  *
375
380
  * @example
376
- * const rule = validateTrigger('required', { message: '请输入名称' })
381
+ * const rule = validateOnSubmit('required', { message: '请输入名称' })
377
382
  */
378
- declare function validateTrigger(type?: string, rules?: ValidateRules, pureValid?: boolean): boolean | ValidateRuleResult;
379
- declare function validate(type?: string, rules?: ValidateInput, pureValid?: boolean): ValidateRuleResult | boolean;
383
+ declare function validateOnSubmit(type?: ValidateTypeInput, rules?: ValidateInput | boolean, pureValid?: boolean): ValidateRuleResult | boolean;
384
+ declare function validate(type?: ValidateTypeInput, rules?: ValidateInput | boolean, pureValid?: boolean): ValidateRuleResult | boolean;
380
385
  /**
381
386
  * 复制文本到剪贴板。
382
387
  *
@@ -559,4 +564,4 @@ declare function getUtilsBuildTime(fallback?: string): string;
559
564
  */
560
565
  declare function test(): string;
561
566
 
562
- export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateTrigger };
567
+ export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit };
package/dist/base.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import 'vue';
2
2
  import 'consola';
3
3
  import 'es-toolkit';
4
- export { $ as $toast, c as clearStorage, a as clone, b as confirm, d as copy, e as debounce, f as delay, g as getStorage, h as getType, i as getUtilsBuildTime, j as getVariable, k as isEmpty, l as log, m as merge, n as mockValue, p as processWidth, r as random, s as setStorage, t as test, o as throttle, q as toLine, u as tryCatch, v as validate, w as validateForm, x as validateTrigger } from './shared/utils.CzQQZf9j.mjs';
4
+ export { $ as $toast, c as clearStorage, a as clone, b as confirm, d as copy, e as debounce, f as delay, g as getStorage, h as getType, i as getUtilsBuildTime, j as getVariable, k as isEmpty, l as log, m as merge, n as mockValue, p as processWidth, r as random, s as setStorage, t as test, o as throttle, q as toLine, u as tryCatch, v as validate, w as validateForm, x as validateOnSubmit } from './shared/utils.CCqAduBt.mjs';
5
5
  import 'element-plus';
6
6
  import './is.mjs';
package/dist/format.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const format = require('./shared/utils.BaNHAtTs.cjs');
3
+ const format = require('./shared/utils.D_mBxLLy.cjs');
4
4
  require('./is.cjs');
5
5
  require('consola');
6
6
  require('vue');
package/dist/format.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { y as formatBytes, z as formatBytesConvert, A as formatDurationTime, B as formatImg, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed } from './shared/utils.CzQQZf9j.mjs';
1
+ export { y as formatBytes, z as formatBytesConvert, A as formatDurationTime, B as formatImg, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed } from './shared/utils.CCqAduBt.mjs';
2
2
  import './is.mjs';
3
3
  import 'consola';
4
4
  import 'vue';
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const format = require('./shared/utils.BaNHAtTs.cjs');
3
+ const format = require('./shared/utils.D_mBxLLy.cjs');
4
4
  const day = require('./day.cjs');
5
5
  const is = require('./is.cjs');
6
6
  const ws = require('./ws.cjs');
@@ -45,7 +45,7 @@ exports.toLine = format.toLine;
45
45
  exports.tryCatch = format.tryCatch;
46
46
  exports.validate = format.validate;
47
47
  exports.validateForm = format.validateForm;
48
- exports.validateTrigger = format.validateTrigger;
48
+ exports.validateOnSubmit = format.validateOnSubmit;
49
49
  exports.diffDate = day.diffDate;
50
50
  exports.diffDateFromCurrent = day.diffDateFromCurrent;
51
51
  exports.formatDate = day.formatDate;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateTrigger } from './base.cjs';
1
+ export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit } from './base.cjs';
2
2
  export { diffDate, diffDateFromCurrent, formatDate, formatDateToDay, formatDateToMinute } from './day.cjs';
3
3
  export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.cjs';
4
4
  export { WS, WSAutoReconnectOptions, WSHeartbeatOptions, WSOptions } from './ws.cjs';
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateTrigger } from './base.mjs';
1
+ export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit } from './base.mjs';
2
2
  export { diffDate, diffDateFromCurrent, formatDate, formatDateToDay, formatDateToMinute } from './day.mjs';
3
3
  export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.mjs';
4
4
  export { WS, WSAutoReconnectOptions, WSHeartbeatOptions, WSOptions } from './ws.mjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateTrigger } from './base.js';
1
+ export { $toast, clearStorage, clone, confirm, copy, debounce, delay, getStorage, getType, getUtilsBuildTime, getVariable, isEmpty, log, merge, mockValue, processWidth, random, setStorage, test, throttle, toLine, tryCatch, validate, validateForm, validateOnSubmit } from './base.js';
2
2
  export { diffDate, diffDateFromCurrent, formatDate, formatDateToDay, formatDateToMinute } from './day.js';
3
3
  export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.js';
4
4
  export { WS, WSAutoReconnectOptions, WSHeartbeatOptions, WSOptions } from './ws.js';
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { $ as $toast, c as clearStorage, a as clone, b as confirm, d as copy, e as debounce, f as delay, y as formatBytes, z as formatBytesConvert, A as formatDurationTime, B as formatImg, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed, g as getStorage, h as getType, i as getUtilsBuildTime, j as getVariable, k as isEmpty, l as log, m as merge, n as mockValue, p as processWidth, r as random, s as setStorage, t as test, o as throttle, q as toLine, u as tryCatch, v as validate, w as validateForm, x as validateTrigger } from './shared/utils.CzQQZf9j.mjs';
1
+ export { $ as $toast, c as clearStorage, a as clone, b as confirm, d as copy, e as debounce, f as delay, y as formatBytes, z as formatBytesConvert, A as formatDurationTime, B as formatImg, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed, g as getStorage, h as getType, i as getUtilsBuildTime, j as getVariable, k as isEmpty, l as log, m as merge, n as mockValue, p as processWidth, r as random, s as setStorage, t as test, o as throttle, q as toLine, u as tryCatch, v as validate, w as validateForm, x as validateOnSubmit } from './shared/utils.CCqAduBt.mjs';
2
2
  export { diffDate, diffDateFromCurrent, formatDate, formatDateToDay, formatDateToMinute } from './day.mjs';
3
3
  export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.mjs';
4
4
  export { WS } from './ws.mjs';
@@ -529,15 +529,23 @@ function delay(delay2 = 0, fn) {
529
529
  }, delay2)
530
530
  );
531
531
  }
532
- function validateTrigger(type = "required", rules = {}, pureValid = false) {
533
- let mergeRules = {
534
- trigger: ["blur", "change"],
535
- ...rules
536
- };
537
- return validate(type, mergeRules, pureValid);
532
+ function validateOnSubmit(type = "required", rules = {}, pureValid = false) {
533
+ const normalized = normalizeValidateParams(type, rules, pureValid);
534
+ if (normalized.pureValid) {
535
+ return validate(normalized.type, normalized.rawRules, true);
536
+ }
537
+ return validate(
538
+ normalized.type,
539
+ {
540
+ ...normalized.rulesObject,
541
+ trigger: normalized.rulesObject.trigger ?? []
542
+ },
543
+ normalized.pureValid
544
+ );
538
545
  }
539
546
  var ValidateType = /* @__PURE__ */ ((ValidateType2) => {
540
547
  ValidateType2["REQUIRED"] = "required";
548
+ ValidateType2["CHANGE"] = "change";
541
549
  ValidateType2["PASSWORD"] = "password";
542
550
  ValidateType2["NUMBER"] = "number";
543
551
  ValidateType2["POSITIVE"] = "positive";
@@ -555,25 +563,31 @@ var ValidateType = /* @__PURE__ */ ((ValidateType2) => {
555
563
  return ValidateType2;
556
564
  })(ValidateType || {});
557
565
  function validate(type = "required", rules = {}, pureValid = false) {
558
- const rulesObject = typeof rules === "object" && rules !== null ? rules : {};
559
- let trigger = rulesObject.trigger || [];
566
+ const normalized = normalizeValidateParams(type, rules, pureValid);
567
+ const rulesObject = normalized.rulesObject;
568
+ const rawRules = normalized.rawRules;
569
+ const validType = normalized.type;
570
+ const isPureValid = normalized.pureValid;
571
+ const trigger = rulesObject.trigger ?? ["blur", "change"];
560
572
  const typeMaps = Object.values(ValidateType);
561
- let parseRequired = rulesObject.required ?? true;
562
- if (!typeMaps.includes(type)) {
573
+ const parseRequired = rulesObject.required ?? true;
574
+ const defaultRequiredMessage = validType === "change" /* CHANGE */ ? "\u8BF7\u9009\u62E9" : "\u8BF7\u8F93\u5165";
575
+ const getPureValue = () => Object.prototype.hasOwnProperty.call(rulesObject, "value") ? rulesObject.value : rawRules;
576
+ if (!typeMaps.includes(validType)) {
563
577
  return {
564
578
  required: parseRequired,
565
- message: type,
579
+ message: validType,
566
580
  trigger
567
581
  };
568
582
  }
569
- if (type === "required" /* REQUIRED */) {
583
+ if (validType === "required" /* REQUIRED */ || validType === "change" /* CHANGE */) {
570
584
  return {
571
585
  required: parseRequired,
572
- message: rulesObject.message ?? "\u8BF7\u8F93\u5165",
586
+ message: rulesObject.message ?? defaultRequiredMessage,
573
587
  trigger
574
588
  };
575
589
  }
576
- if (type === "password" /* PASSWORD */) {
590
+ if (validType === "password" /* PASSWORD */) {
577
591
  const validateName = (rule, value, callback) => {
578
592
  let validFlag = /^[a-zA-Z0-9_-]+$/.test(value);
579
593
  if (!validFlag) {
@@ -587,41 +601,46 @@ function validate(type = "required", rules = {}, pureValid = false) {
587
601
  trigger
588
602
  };
589
603
  }
590
- if (type === "positive" /* POSITIVE */ || type === "number" /* NUMBER */) {
591
- return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u6574\u6570", pureValid, /^[1-9]+\d*$/);
604
+ if (validType === "positive" /* POSITIVE */ || validType === "number" /* NUMBER */) {
605
+ return _validValue(getPureValue(), "\u8BF7\u8F93\u5165\u6B63\u6574\u6570", isPureValid, /^[1-9]+\d*$/);
592
606
  }
593
- if (type === "zeroPositive" /* ZERO_POSITIVE */) {
594
- return _validValue(rules, "\u8BF7\u8F93\u5165\u975E\u8D1F\u6574\u6570", pureValid, /^(0|[1-9]+\d*)$/);
607
+ if (validType === "zeroPositive" /* ZERO_POSITIVE */) {
608
+ return _validValue(getPureValue(), "\u8BF7\u8F93\u5165\u975E\u8D1F\u6574\u6570", isPureValid, /^(0|[1-9]+\d*)$/);
595
609
  }
596
- if (type === "integer" /* INTEGER */) {
597
- return _validValue(rules, "\u8BF7\u8F93\u5165\u6574\u6570", pureValid, /^(0|[-]?[1-9]\d*)$/);
610
+ if (validType === "integer" /* INTEGER */) {
611
+ return _validValue(getPureValue(), "\u8BF7\u8F93\u5165\u6574\u6570", isPureValid, /^(0|[-]?[1-9]\d*)$/);
598
612
  }
599
- if (type === "decimal" /* DECIMAL */) {
600
- 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}/);
613
+ if (validType === "decimal" /* DECIMAL */) {
614
+ return _validValue(
615
+ getPureValue(),
616
+ "\u8BF7\u8F93\u5165\u975E\u8D1F\u6570\u5B57, \u5305\u542B\u5C0F\u6570\u4E14\u6700\u591A2\u4F4D",
617
+ isPureValid,
618
+ /(0|[1-9]\d*)(\.\d{1, 2})?|0\.\d{1,2}/
619
+ );
601
620
  }
602
- if (type === "mobile" /* MOBILE */) {
603
- return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7", pureValid, /^[1][0-9]{10}$/);
621
+ if (validType === "mobile" /* MOBILE */) {
622
+ return _validValue(getPureValue(), "\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7", isPureValid, /^[1][0-9]{10}$/);
604
623
  }
605
- if (type === "email" /* EMAIL */) {
606
- return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u786E\u7684email", pureValid, /^[^\s@]+@[^\s@]+\.[^\s@]+$/);
624
+ if (validType === "email" /* EMAIL */) {
625
+ return _validValue(getPureValue(), "\u8BF7\u8F93\u5165\u6B63\u786E\u7684email", isPureValid, /^[^\s@]+@[^\s@]+\.[^\s@]+$/);
607
626
  }
608
- if (type === "ip" /* IP */) {
627
+ if (validType === "ip" /* IP */) {
609
628
  return _validValue(
610
- rules,
629
+ getPureValue(),
611
630
  "\u8BF7\u8F93\u5165\u6B63\u786E\u7684ip\u5730\u5740",
612
- pureValid,
631
+ isPureValid,
613
632
  /^((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]?)$/
614
633
  );
615
634
  }
616
- if (type === "port" /* PORT */) {
635
+ if (validType === "port" /* PORT */) {
617
636
  return _validValue(
618
- rules,
637
+ getPureValue(),
619
638
  "\u8BF7\u8F93\u51651-65535\u7684\u7AEF\u53E3\u53F7",
620
- pureValid,
639
+ isPureValid,
621
640
  /^([1-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-5][0-5][0-3][0-5])$/
622
641
  );
623
642
  }
624
- if (type === "between" /* BETWEEN */) {
643
+ if (validType === "between" /* BETWEEN */) {
625
644
  let minValue = rulesObject.min ?? "";
626
645
  let maxValue = rulesObject.max ?? "";
627
646
  const validateBetween = (rule, value, callback) => {
@@ -643,7 +662,7 @@ function validate(type = "required", rules = {}, pureValid = false) {
643
662
  required: parseRequired
644
663
  };
645
664
  }
646
- if (type === "length" /* LENGTH */) {
665
+ if (validType === "length" /* LENGTH */) {
647
666
  return {
648
667
  min: rulesObject.min,
649
668
  max: rulesObject.max,
@@ -652,7 +671,7 @@ function validate(type = "required", rules = {}, pureValid = false) {
652
671
  required: parseRequired
653
672
  };
654
673
  }
655
- if (type === "same" /* SAME */) {
674
+ if (validType === "same" /* SAME */) {
656
675
  const validateSame = (rule, value, callback) => {
657
676
  let isSame = value === rulesObject.value;
658
677
  if (!isSame) {
@@ -671,33 +690,46 @@ function validate(type = "required", rules = {}, pureValid = false) {
671
690
  };
672
691
  return res;
673
692
  }
674
- if (type === "custom" /* CUSTOM */) {
675
- if (pureValid) {
676
- return _validValue(rulesObject.value, rulesObject.message, pureValid, rulesObject.reg);
677
- } else {
678
- return _validValue(rulesObject, rulesObject.message, pureValid, rulesObject.reg);
679
- }
693
+ if (validType === "custom" /* CUSTOM */) {
694
+ return _validValue(getPureValue(), rulesObject.message, isPureValid, rulesObject.reg);
680
695
  }
681
- function _validValue(rules2, msg, pureValid2, reg) {
682
- if (pureValid2 === true) {
683
- return reg.test(rules2);
696
+ function _validValue(value, msg, pureValid2, reg) {
697
+ if (pureValid2) {
698
+ return reg.test(value);
684
699
  }
685
- const validatePhone = (rule, value, callback) => {
686
- let validFlag = reg.test(value);
700
+ const validatePhone = (rule, value2, callback) => {
701
+ let validFlag = reg.test(value2);
687
702
  if (!validFlag) {
688
- callback(new Error(rules2.message ?? msg));
703
+ callback(new Error(rulesObject.message ?? msg));
689
704
  } else {
690
705
  callback();
691
706
  }
692
707
  };
693
708
  return {
694
709
  validator: validatePhone,
695
- required: rules2.required ?? true,
710
+ required: rulesObject.required ?? true,
696
711
  trigger
697
712
  };
698
713
  }
699
714
  return {};
700
715
  }
716
+ function normalizeValidateParams(type, rules, pureValid) {
717
+ if (typeof type === "object" && type !== null) {
718
+ const rulesObject = type;
719
+ return {
720
+ type: rulesObject.type || "required" /* REQUIRED */,
721
+ rulesObject,
722
+ rawRules: rulesObject,
723
+ pureValid: typeof rules === "boolean" ? rules : pureValid
724
+ };
725
+ }
726
+ return {
727
+ type,
728
+ rulesObject: typeof rules === "object" && rules !== null ? rules : {},
729
+ rawRules: rules,
730
+ pureValid
731
+ };
732
+ }
701
733
  const copy = (text, toastParams = {}) => {
702
734
  const textarea = document.createElement("textarea");
703
735
  textarea.value = text;
@@ -946,11 +978,11 @@ function getVariable(propertyName, fallback = "") {
946
978
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
947
979
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
948
980
  {
949
- return "2026-07-01 13:13:26";
981
+ return "2026-07-02 11:57:59";
950
982
  }
951
983
  }
952
984
  function test() {
953
985
  return `build time: ${getUtilsBuildTime()}`;
954
986
  }
955
987
 
956
- export { $toast as $, formatDurationTime as A, formatImg as B, formatTextToHtml as C, formatThousands as D, formatTime as E, formatToFixed as F, clone as a, confirm as b, clearStorage as c, copy as d, debounce as e, delay as f, getStorage as g, getType as h, getUtilsBuildTime as i, getVariable as j, isEmpty as k, log as l, merge as m, mockValue as n, throttle as o, processWidth as p, toLine as q, random as r, setStorage as s, test as t, tryCatch as u, validate as v, validateForm as w, validateTrigger as x, formatBytes as y, formatBytesConvert as z };
988
+ export { $toast as $, formatDurationTime as A, formatImg as B, formatTextToHtml as C, formatThousands as D, formatTime as E, formatToFixed as F, clone as a, confirm as b, clearStorage as c, copy as d, debounce as e, delay as f, getStorage as g, getType as h, getUtilsBuildTime as i, getVariable as j, isEmpty as k, log as l, merge as m, mockValue as n, throttle as o, processWidth as p, toLine as q, random as r, setStorage as s, test as t, tryCatch as u, validate as v, validateForm as w, validateOnSubmit as x, formatBytes as y, formatBytesConvert as z };
@@ -190,7 +190,7 @@ function formatImg(photoName, addPath = "", { basePath = "assets/images" } = {})
190
190
  const addLastSlash = addPath.endsWith("/") || !addPath ? addPath : `${addPath}/`;
191
191
  const addLastBasePathSlash = basePath.endsWith("/") || !basePath ? basePath : `${basePath}/`;
192
192
  const mergeSrc = `${addLastSlash}${photoName}`;
193
- return new URL(`../${addLastBasePathSlash}${mergeSrc}`, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/utils.BaNHAtTs.cjs', document.baseURI).href))).href;
193
+ return new URL(`../${addLastBasePathSlash}${mergeSrc}`, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('shared/utils.D_mBxLLy.cjs', document.baseURI).href))).href;
194
194
  }
195
195
  function formatToFixed(value, options) {
196
196
  if (typeof options === "number") {
@@ -532,15 +532,23 @@ function delay(delay2 = 0, fn) {
532
532
  }, delay2)
533
533
  );
534
534
  }
535
- function validateTrigger(type = "required", rules = {}, pureValid = false) {
536
- let mergeRules = {
537
- trigger: ["blur", "change"],
538
- ...rules
539
- };
540
- return validate(type, mergeRules, pureValid);
535
+ function validateOnSubmit(type = "required", rules = {}, pureValid = false) {
536
+ const normalized = normalizeValidateParams(type, rules, pureValid);
537
+ if (normalized.pureValid) {
538
+ return validate(normalized.type, normalized.rawRules, true);
539
+ }
540
+ return validate(
541
+ normalized.type,
542
+ {
543
+ ...normalized.rulesObject,
544
+ trigger: normalized.rulesObject.trigger ?? []
545
+ },
546
+ normalized.pureValid
547
+ );
541
548
  }
542
549
  var ValidateType = /* @__PURE__ */ ((ValidateType2) => {
543
550
  ValidateType2["REQUIRED"] = "required";
551
+ ValidateType2["CHANGE"] = "change";
544
552
  ValidateType2["PASSWORD"] = "password";
545
553
  ValidateType2["NUMBER"] = "number";
546
554
  ValidateType2["POSITIVE"] = "positive";
@@ -558,25 +566,31 @@ var ValidateType = /* @__PURE__ */ ((ValidateType2) => {
558
566
  return ValidateType2;
559
567
  })(ValidateType || {});
560
568
  function validate(type = "required", rules = {}, pureValid = false) {
561
- const rulesObject = typeof rules === "object" && rules !== null ? rules : {};
562
- let trigger = rulesObject.trigger || [];
569
+ const normalized = normalizeValidateParams(type, rules, pureValid);
570
+ const rulesObject = normalized.rulesObject;
571
+ const rawRules = normalized.rawRules;
572
+ const validType = normalized.type;
573
+ const isPureValid = normalized.pureValid;
574
+ const trigger = rulesObject.trigger ?? ["blur", "change"];
563
575
  const typeMaps = Object.values(ValidateType);
564
- let parseRequired = rulesObject.required ?? true;
565
- if (!typeMaps.includes(type)) {
576
+ const parseRequired = rulesObject.required ?? true;
577
+ const defaultRequiredMessage = validType === "change" /* CHANGE */ ? "\u8BF7\u9009\u62E9" : "\u8BF7\u8F93\u5165";
578
+ const getPureValue = () => Object.prototype.hasOwnProperty.call(rulesObject, "value") ? rulesObject.value : rawRules;
579
+ if (!typeMaps.includes(validType)) {
566
580
  return {
567
581
  required: parseRequired,
568
- message: type,
582
+ message: validType,
569
583
  trigger
570
584
  };
571
585
  }
572
- if (type === "required" /* REQUIRED */) {
586
+ if (validType === "required" /* REQUIRED */ || validType === "change" /* CHANGE */) {
573
587
  return {
574
588
  required: parseRequired,
575
- message: rulesObject.message ?? "\u8BF7\u8F93\u5165",
589
+ message: rulesObject.message ?? defaultRequiredMessage,
576
590
  trigger
577
591
  };
578
592
  }
579
- if (type === "password" /* PASSWORD */) {
593
+ if (validType === "password" /* PASSWORD */) {
580
594
  const validateName = (rule, value, callback) => {
581
595
  let validFlag = /^[a-zA-Z0-9_-]+$/.test(value);
582
596
  if (!validFlag) {
@@ -590,41 +604,46 @@ function validate(type = "required", rules = {}, pureValid = false) {
590
604
  trigger
591
605
  };
592
606
  }
593
- if (type === "positive" /* POSITIVE */ || type === "number" /* NUMBER */) {
594
- return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u6574\u6570", pureValid, /^[1-9]+\d*$/);
607
+ if (validType === "positive" /* POSITIVE */ || validType === "number" /* NUMBER */) {
608
+ return _validValue(getPureValue(), "\u8BF7\u8F93\u5165\u6B63\u6574\u6570", isPureValid, /^[1-9]+\d*$/);
595
609
  }
596
- if (type === "zeroPositive" /* ZERO_POSITIVE */) {
597
- return _validValue(rules, "\u8BF7\u8F93\u5165\u975E\u8D1F\u6574\u6570", pureValid, /^(0|[1-9]+\d*)$/);
610
+ if (validType === "zeroPositive" /* ZERO_POSITIVE */) {
611
+ return _validValue(getPureValue(), "\u8BF7\u8F93\u5165\u975E\u8D1F\u6574\u6570", isPureValid, /^(0|[1-9]+\d*)$/);
598
612
  }
599
- if (type === "integer" /* INTEGER */) {
600
- return _validValue(rules, "\u8BF7\u8F93\u5165\u6574\u6570", pureValid, /^(0|[-]?[1-9]\d*)$/);
613
+ if (validType === "integer" /* INTEGER */) {
614
+ return _validValue(getPureValue(), "\u8BF7\u8F93\u5165\u6574\u6570", isPureValid, /^(0|[-]?[1-9]\d*)$/);
601
615
  }
602
- if (type === "decimal" /* DECIMAL */) {
603
- 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}/);
616
+ if (validType === "decimal" /* DECIMAL */) {
617
+ return _validValue(
618
+ getPureValue(),
619
+ "\u8BF7\u8F93\u5165\u975E\u8D1F\u6570\u5B57, \u5305\u542B\u5C0F\u6570\u4E14\u6700\u591A2\u4F4D",
620
+ isPureValid,
621
+ /(0|[1-9]\d*)(\.\d{1, 2})?|0\.\d{1,2}/
622
+ );
604
623
  }
605
- if (type === "mobile" /* MOBILE */) {
606
- return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7", pureValid, /^[1][0-9]{10}$/);
624
+ if (validType === "mobile" /* MOBILE */) {
625
+ return _validValue(getPureValue(), "\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7", isPureValid, /^[1][0-9]{10}$/);
607
626
  }
608
- if (type === "email" /* EMAIL */) {
609
- return _validValue(rules, "\u8BF7\u8F93\u5165\u6B63\u786E\u7684email", pureValid, /^[^\s@]+@[^\s@]+\.[^\s@]+$/);
627
+ if (validType === "email" /* EMAIL */) {
628
+ return _validValue(getPureValue(), "\u8BF7\u8F93\u5165\u6B63\u786E\u7684email", isPureValid, /^[^\s@]+@[^\s@]+\.[^\s@]+$/);
610
629
  }
611
- if (type === "ip" /* IP */) {
630
+ if (validType === "ip" /* IP */) {
612
631
  return _validValue(
613
- rules,
632
+ getPureValue(),
614
633
  "\u8BF7\u8F93\u5165\u6B63\u786E\u7684ip\u5730\u5740",
615
- pureValid,
634
+ isPureValid,
616
635
  /^((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]?)$/
617
636
  );
618
637
  }
619
- if (type === "port" /* PORT */) {
638
+ if (validType === "port" /* PORT */) {
620
639
  return _validValue(
621
- rules,
640
+ getPureValue(),
622
641
  "\u8BF7\u8F93\u51651-65535\u7684\u7AEF\u53E3\u53F7",
623
- pureValid,
642
+ isPureValid,
624
643
  /^([1-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-5][0-5][0-3][0-5])$/
625
644
  );
626
645
  }
627
- if (type === "between" /* BETWEEN */) {
646
+ if (validType === "between" /* BETWEEN */) {
628
647
  let minValue = rulesObject.min ?? "";
629
648
  let maxValue = rulesObject.max ?? "";
630
649
  const validateBetween = (rule, value, callback) => {
@@ -646,7 +665,7 @@ function validate(type = "required", rules = {}, pureValid = false) {
646
665
  required: parseRequired
647
666
  };
648
667
  }
649
- if (type === "length" /* LENGTH */) {
668
+ if (validType === "length" /* LENGTH */) {
650
669
  return {
651
670
  min: rulesObject.min,
652
671
  max: rulesObject.max,
@@ -655,7 +674,7 @@ function validate(type = "required", rules = {}, pureValid = false) {
655
674
  required: parseRequired
656
675
  };
657
676
  }
658
- if (type === "same" /* SAME */) {
677
+ if (validType === "same" /* SAME */) {
659
678
  const validateSame = (rule, value, callback) => {
660
679
  let isSame = value === rulesObject.value;
661
680
  if (!isSame) {
@@ -674,33 +693,46 @@ function validate(type = "required", rules = {}, pureValid = false) {
674
693
  };
675
694
  return res;
676
695
  }
677
- if (type === "custom" /* CUSTOM */) {
678
- if (pureValid) {
679
- return _validValue(rulesObject.value, rulesObject.message, pureValid, rulesObject.reg);
680
- } else {
681
- return _validValue(rulesObject, rulesObject.message, pureValid, rulesObject.reg);
682
- }
696
+ if (validType === "custom" /* CUSTOM */) {
697
+ return _validValue(getPureValue(), rulesObject.message, isPureValid, rulesObject.reg);
683
698
  }
684
- function _validValue(rules2, msg, pureValid2, reg) {
685
- if (pureValid2 === true) {
686
- return reg.test(rules2);
699
+ function _validValue(value, msg, pureValid2, reg) {
700
+ if (pureValid2) {
701
+ return reg.test(value);
687
702
  }
688
- const validatePhone = (rule, value, callback) => {
689
- let validFlag = reg.test(value);
703
+ const validatePhone = (rule, value2, callback) => {
704
+ let validFlag = reg.test(value2);
690
705
  if (!validFlag) {
691
- callback(new Error(rules2.message ?? msg));
706
+ callback(new Error(rulesObject.message ?? msg));
692
707
  } else {
693
708
  callback();
694
709
  }
695
710
  };
696
711
  return {
697
712
  validator: validatePhone,
698
- required: rules2.required ?? true,
713
+ required: rulesObject.required ?? true,
699
714
  trigger
700
715
  };
701
716
  }
702
717
  return {};
703
718
  }
719
+ function normalizeValidateParams(type, rules, pureValid) {
720
+ if (typeof type === "object" && type !== null) {
721
+ const rulesObject = type;
722
+ return {
723
+ type: rulesObject.type || "required" /* REQUIRED */,
724
+ rulesObject,
725
+ rawRules: rulesObject,
726
+ pureValid: typeof rules === "boolean" ? rules : pureValid
727
+ };
728
+ }
729
+ return {
730
+ type,
731
+ rulesObject: typeof rules === "object" && rules !== null ? rules : {},
732
+ rawRules: rules,
733
+ pureValid
734
+ };
735
+ }
704
736
  const copy = (text, toastParams = {}) => {
705
737
  const textarea = document.createElement("textarea");
706
738
  textarea.value = text;
@@ -949,7 +981,7 @@ function getVariable(propertyName, fallback = "") {
949
981
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
950
982
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
951
983
  {
952
- return "2026-07-01 13:13:26";
984
+ return "2026-07-02 11:57:59";
953
985
  }
954
986
  }
955
987
  function test() {
@@ -988,4 +1020,4 @@ exports.toLine = toLine;
988
1020
  exports.tryCatch = tryCatch;
989
1021
  exports.validate = validate;
990
1022
  exports.validateForm = validateForm;
991
- exports.validateTrigger = validateTrigger;
1023
+ exports.validateOnSubmit = validateOnSubmit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sybz-components/utils",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "utils of sybz-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",