@sybz-components/utils 0.0.10 → 0.0.12

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.DUIw9c4e.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
  *
@@ -450,19 +455,47 @@ declare function toLine(text: string, connect?: string): string;
450
455
  */
451
456
  declare function processWidth(initValue: WidthInput, isBase: true): string;
452
457
  declare function processWidth(initValue: WidthInput, isBase?: false): WidthStyleResult | {};
458
+ interface ThrottleOptions {
459
+ /**
460
+ * 是否在首次调用时立即执行,默认 `true`。
461
+ */
462
+ leading?: boolean;
463
+ /**
464
+ * 是否在节流周期结束时执行最后一次调用,默认 `true`。
465
+ */
466
+ trailing?: boolean;
467
+ }
468
+ type ThrottleOptionsInput = boolean | ThrottleOptions;
469
+ type ThrottledFunction<T extends Func> = ((...args: Parameters<T>) => ReturnType<T> | undefined) & {
470
+ cancel: () => void;
471
+ flush: () => ReturnType<T> | undefined;
472
+ };
453
473
  /**
454
474
  * 创建节流函数。
455
475
  *
456
476
  * @param fn 需要节流执行的函数。
457
477
  * @param delay 节流间隔,单位毫秒,默认 `1000`。
458
- * @returns 节流后的函数。
478
+ * @param options 节流选项。传 `false` 等同于 `{ leading: false }`。
479
+ * @param resultCallback 每次真正执行后触发的结果回调。
480
+ * @returns 带 `cancel()` / `flush()` 方法的节流函数。
459
481
  *
460
482
  * @example
461
483
  * const onResize = throttle(() => {
462
484
  * console.log('resize')
463
485
  * }, 300)
486
+ *
487
+ * @example
488
+ * const save = throttle(saveDraft, 1000, { leading: false, trailing: true })
489
+ *
490
+ * @example
491
+ * const track = throttle(trackPosition, 200, { trailing: false }, (result) => {
492
+ * console.log(result)
493
+ * })
494
+ *
495
+ * track.cancel()
496
+ * track.flush()
464
497
  */
465
- declare function throttle<T extends Func>(fn: T, delay?: number): (...args: Parameters<T>) => void;
498
+ declare function throttle<T extends Func>(fn: T, delay?: number, options?: ThrottleOptionsInput, resultCallback?: (result: ReturnType<T>) => void): ThrottledFunction<T>;
466
499
  /**
467
500
  * 统一处理 Promise 或任务函数执行结果。
468
501
  *
@@ -508,6 +541,13 @@ type DebouncedFunction<T extends Func> = ((...args: Parameters<T>) => Promise<Aw
508
541
  * }, 300)
509
542
  *
510
543
  * await search('sybz')
544
+ *
545
+ * @example
546
+ * const submit = debounce(saveForm, 500, true, (result) => {
547
+ * console.log(result)
548
+ * })
549
+ *
550
+ * submit.cancel()
511
551
  */
512
552
  declare function debounce<T extends Func>(func: T, delay?: number, immediate?: boolean, resultCallback?: (result: ReturnType<T>) => void): DebouncedFunction<T>;
513
553
  /**
@@ -559,4 +599,4 @@ declare function getUtilsBuildTime(fallback?: string): string;
559
599
  */
560
600
  declare function test(): string;
561
601
 
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 };
602
+ 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
  *
@@ -450,19 +455,47 @@ declare function toLine(text: string, connect?: string): string;
450
455
  */
451
456
  declare function processWidth(initValue: WidthInput, isBase: true): string;
452
457
  declare function processWidth(initValue: WidthInput, isBase?: false): WidthStyleResult | {};
458
+ interface ThrottleOptions {
459
+ /**
460
+ * 是否在首次调用时立即执行,默认 `true`。
461
+ */
462
+ leading?: boolean;
463
+ /**
464
+ * 是否在节流周期结束时执行最后一次调用,默认 `true`。
465
+ */
466
+ trailing?: boolean;
467
+ }
468
+ type ThrottleOptionsInput = boolean | ThrottleOptions;
469
+ type ThrottledFunction<T extends Func> = ((...args: Parameters<T>) => ReturnType<T> | undefined) & {
470
+ cancel: () => void;
471
+ flush: () => ReturnType<T> | undefined;
472
+ };
453
473
  /**
454
474
  * 创建节流函数。
455
475
  *
456
476
  * @param fn 需要节流执行的函数。
457
477
  * @param delay 节流间隔,单位毫秒,默认 `1000`。
458
- * @returns 节流后的函数。
478
+ * @param options 节流选项。传 `false` 等同于 `{ leading: false }`。
479
+ * @param resultCallback 每次真正执行后触发的结果回调。
480
+ * @returns 带 `cancel()` / `flush()` 方法的节流函数。
459
481
  *
460
482
  * @example
461
483
  * const onResize = throttle(() => {
462
484
  * console.log('resize')
463
485
  * }, 300)
486
+ *
487
+ * @example
488
+ * const save = throttle(saveDraft, 1000, { leading: false, trailing: true })
489
+ *
490
+ * @example
491
+ * const track = throttle(trackPosition, 200, { trailing: false }, (result) => {
492
+ * console.log(result)
493
+ * })
494
+ *
495
+ * track.cancel()
496
+ * track.flush()
464
497
  */
465
- declare function throttle<T extends Func>(fn: T, delay?: number): (...args: Parameters<T>) => void;
498
+ declare function throttle<T extends Func>(fn: T, delay?: number, options?: ThrottleOptionsInput, resultCallback?: (result: ReturnType<T>) => void): ThrottledFunction<T>;
466
499
  /**
467
500
  * 统一处理 Promise 或任务函数执行结果。
468
501
  *
@@ -508,6 +541,13 @@ type DebouncedFunction<T extends Func> = ((...args: Parameters<T>) => Promise<Aw
508
541
  * }, 300)
509
542
  *
510
543
  * await search('sybz')
544
+ *
545
+ * @example
546
+ * const submit = debounce(saveForm, 500, true, (result) => {
547
+ * console.log(result)
548
+ * })
549
+ *
550
+ * submit.cancel()
511
551
  */
512
552
  declare function debounce<T extends Func>(func: T, delay?: number, immediate?: boolean, resultCallback?: (result: ReturnType<T>) => void): DebouncedFunction<T>;
513
553
  /**
@@ -559,4 +599,4 @@ declare function getUtilsBuildTime(fallback?: string): string;
559
599
  */
560
600
  declare function test(): string;
561
601
 
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 };
602
+ 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
  *
@@ -450,19 +455,47 @@ declare function toLine(text: string, connect?: string): string;
450
455
  */
451
456
  declare function processWidth(initValue: WidthInput, isBase: true): string;
452
457
  declare function processWidth(initValue: WidthInput, isBase?: false): WidthStyleResult | {};
458
+ interface ThrottleOptions {
459
+ /**
460
+ * 是否在首次调用时立即执行,默认 `true`。
461
+ */
462
+ leading?: boolean;
463
+ /**
464
+ * 是否在节流周期结束时执行最后一次调用,默认 `true`。
465
+ */
466
+ trailing?: boolean;
467
+ }
468
+ type ThrottleOptionsInput = boolean | ThrottleOptions;
469
+ type ThrottledFunction<T extends Func> = ((...args: Parameters<T>) => ReturnType<T> | undefined) & {
470
+ cancel: () => void;
471
+ flush: () => ReturnType<T> | undefined;
472
+ };
453
473
  /**
454
474
  * 创建节流函数。
455
475
  *
456
476
  * @param fn 需要节流执行的函数。
457
477
  * @param delay 节流间隔,单位毫秒,默认 `1000`。
458
- * @returns 节流后的函数。
478
+ * @param options 节流选项。传 `false` 等同于 `{ leading: false }`。
479
+ * @param resultCallback 每次真正执行后触发的结果回调。
480
+ * @returns 带 `cancel()` / `flush()` 方法的节流函数。
459
481
  *
460
482
  * @example
461
483
  * const onResize = throttle(() => {
462
484
  * console.log('resize')
463
485
  * }, 300)
486
+ *
487
+ * @example
488
+ * const save = throttle(saveDraft, 1000, { leading: false, trailing: true })
489
+ *
490
+ * @example
491
+ * const track = throttle(trackPosition, 200, { trailing: false }, (result) => {
492
+ * console.log(result)
493
+ * })
494
+ *
495
+ * track.cancel()
496
+ * track.flush()
464
497
  */
465
- declare function throttle<T extends Func>(fn: T, delay?: number): (...args: Parameters<T>) => void;
498
+ declare function throttle<T extends Func>(fn: T, delay?: number, options?: ThrottleOptionsInput, resultCallback?: (result: ReturnType<T>) => void): ThrottledFunction<T>;
466
499
  /**
467
500
  * 统一处理 Promise 或任务函数执行结果。
468
501
  *
@@ -508,6 +541,13 @@ type DebouncedFunction<T extends Func> = ((...args: Parameters<T>) => Promise<Aw
508
541
  * }, 300)
509
542
  *
510
543
  * await search('sybz')
544
+ *
545
+ * @example
546
+ * const submit = debounce(saveForm, 500, true, (result) => {
547
+ * console.log(result)
548
+ * })
549
+ *
550
+ * submit.cancel()
511
551
  */
512
552
  declare function debounce<T extends Func>(func: T, delay?: number, immediate?: boolean, resultCallback?: (result: ReturnType<T>) => void): DebouncedFunction<T>;
513
553
  /**
@@ -559,4 +599,4 @@ declare function getUtilsBuildTime(fallback?: string): string;
559
599
  */
560
600
  declare function test(): string;
561
601
 
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 };
602
+ 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.CTnx12Vx.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.DUIw9c4e.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.CTnx12Vx.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.DUIw9c4e.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.CTnx12Vx.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;
@@ -782,23 +814,79 @@ function processWidth(initValue, isBase = false) {
782
814
  }
783
815
  return isBase ? res : { width: res };
784
816
  }
785
- function throttle(fn, delay2 = 1e3) {
786
- let last = 0;
817
+ const normalizeThrottleOptions = (options = {}) => {
818
+ const normalized = typeof options === "boolean" ? { leading: options } : options;
819
+ return {
820
+ leading: normalized.leading !== false,
821
+ trailing: normalized.trailing !== false
822
+ };
823
+ };
824
+ function throttle(fn, delay2 = 1e3, options = {}, resultCallback) {
825
+ const { leading, trailing } = normalizeThrottleOptions(options);
787
826
  let timer = void 0;
788
- return function(...args) {
789
- let context = this;
790
- let now = +/* @__PURE__ */ new Date();
791
- if (now - last < delay2) {
827
+ let previous;
828
+ let lastArgs;
829
+ let lastThis;
830
+ let result;
831
+ const cancel = () => {
832
+ if (timer) {
792
833
  clearTimeout(timer);
793
- timer = setTimeout(function() {
794
- last = now;
795
- fn.apply(context, args);
796
- }, delay2);
797
- } else {
798
- last = now;
799
- fn.apply(context, args);
834
+ timer = void 0;
800
835
  }
836
+ previous = void 0;
837
+ lastArgs = void 0;
838
+ lastThis = void 0;
839
+ };
840
+ const invoke = () => {
841
+ if (!lastArgs) return result;
842
+ previous = Date.now();
843
+ const args = lastArgs;
844
+ const context = lastThis;
845
+ lastArgs = void 0;
846
+ lastThis = void 0;
847
+ result = fn.apply(context, args);
848
+ resultCallback?.(result);
849
+ return result;
850
+ };
851
+ const flush = () => {
852
+ if (timer) {
853
+ clearTimeout(timer);
854
+ timer = void 0;
855
+ }
856
+ return invoke();
857
+ };
858
+ const throttled = function(...args) {
859
+ const now = Date.now();
860
+ lastArgs = args;
861
+ lastThis = this;
862
+ if (previous === void 0) {
863
+ if (leading) {
864
+ return invoke();
865
+ }
866
+ previous = now;
867
+ }
868
+ const remaining = delay2 - (now - previous);
869
+ if (remaining <= 0 || remaining > delay2) {
870
+ if (timer) {
871
+ clearTimeout(timer);
872
+ timer = void 0;
873
+ }
874
+ return invoke();
875
+ }
876
+ if (!timer && trailing) {
877
+ timer = setTimeout(() => {
878
+ timer = void 0;
879
+ if (!leading) {
880
+ previous = void 0;
881
+ }
882
+ invoke();
883
+ }, remaining);
884
+ }
885
+ return result;
801
886
  };
887
+ throttled.cancel = cancel;
888
+ throttled.flush = flush;
889
+ return throttled;
802
890
  }
803
891
  async function tryCatch(task, sendLoading) {
804
892
  const updateLoading = (value) => {
@@ -946,11 +1034,11 @@ function getVariable(propertyName, fallback = "") {
946
1034
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
947
1035
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
948
1036
  {
949
- return "2026-07-01 13:13:26";
1037
+ return "2026-07-02 16:09:23";
950
1038
  }
951
1039
  }
952
1040
  function test() {
953
1041
  return `build time: ${getUtilsBuildTime()}`;
954
1042
  }
955
1043
 
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 };
1044
+ 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.DUIw9c4e.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;
@@ -785,23 +817,79 @@ function processWidth(initValue, isBase = false) {
785
817
  }
786
818
  return isBase ? res : { width: res };
787
819
  }
788
- function throttle(fn, delay2 = 1e3) {
789
- let last = 0;
820
+ const normalizeThrottleOptions = (options = {}) => {
821
+ const normalized = typeof options === "boolean" ? { leading: options } : options;
822
+ return {
823
+ leading: normalized.leading !== false,
824
+ trailing: normalized.trailing !== false
825
+ };
826
+ };
827
+ function throttle(fn, delay2 = 1e3, options = {}, resultCallback) {
828
+ const { leading, trailing } = normalizeThrottleOptions(options);
790
829
  let timer = void 0;
791
- return function(...args) {
792
- let context = this;
793
- let now = +/* @__PURE__ */ new Date();
794
- if (now - last < delay2) {
830
+ let previous;
831
+ let lastArgs;
832
+ let lastThis;
833
+ let result;
834
+ const cancel = () => {
835
+ if (timer) {
795
836
  clearTimeout(timer);
796
- timer = setTimeout(function() {
797
- last = now;
798
- fn.apply(context, args);
799
- }, delay2);
800
- } else {
801
- last = now;
802
- fn.apply(context, args);
837
+ timer = void 0;
803
838
  }
839
+ previous = void 0;
840
+ lastArgs = void 0;
841
+ lastThis = void 0;
842
+ };
843
+ const invoke = () => {
844
+ if (!lastArgs) return result;
845
+ previous = Date.now();
846
+ const args = lastArgs;
847
+ const context = lastThis;
848
+ lastArgs = void 0;
849
+ lastThis = void 0;
850
+ result = fn.apply(context, args);
851
+ resultCallback?.(result);
852
+ return result;
853
+ };
854
+ const flush = () => {
855
+ if (timer) {
856
+ clearTimeout(timer);
857
+ timer = void 0;
858
+ }
859
+ return invoke();
860
+ };
861
+ const throttled = function(...args) {
862
+ const now = Date.now();
863
+ lastArgs = args;
864
+ lastThis = this;
865
+ if (previous === void 0) {
866
+ if (leading) {
867
+ return invoke();
868
+ }
869
+ previous = now;
870
+ }
871
+ const remaining = delay2 - (now - previous);
872
+ if (remaining <= 0 || remaining > delay2) {
873
+ if (timer) {
874
+ clearTimeout(timer);
875
+ timer = void 0;
876
+ }
877
+ return invoke();
878
+ }
879
+ if (!timer && trailing) {
880
+ timer = setTimeout(() => {
881
+ timer = void 0;
882
+ if (!leading) {
883
+ previous = void 0;
884
+ }
885
+ invoke();
886
+ }, remaining);
887
+ }
888
+ return result;
804
889
  };
890
+ throttled.cancel = cancel;
891
+ throttled.flush = flush;
892
+ return throttled;
805
893
  }
806
894
  async function tryCatch(task, sendLoading) {
807
895
  const updateLoading = (value) => {
@@ -949,7 +1037,7 @@ function getVariable(propertyName, fallback = "") {
949
1037
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
950
1038
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
951
1039
  {
952
- return "2026-07-01 13:13:26";
1040
+ return "2026-07-02 16:09:23";
953
1041
  }
954
1042
  }
955
1043
  function test() {
@@ -988,4 +1076,4 @@ exports.toLine = toLine;
988
1076
  exports.tryCatch = tryCatch;
989
1077
  exports.validate = validate;
990
1078
  exports.validateForm = validateForm;
991
- exports.validateTrigger = validateTrigger;
1079
+ 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.12",
4
4
  "description": "utils of sybz-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",