@unicom-cloud/utils 0.1.24 → 0.1.25

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.
Files changed (290) hide show
  1. package/case-name/index.js +1 -1
  2. package/caseName.js +1 -1
  3. package/class-name/index.js +1 -1
  4. package/className.js +1 -1
  5. package/clipboard-copy/index.js +1 -1
  6. package/clipboardCopy.js +1 -1
  7. package/constant/address.js +1 -1
  8. package/constant/chineseCharacters.js +1 -1
  9. package/constant/constellations.js +1 -1
  10. package/constant/domain.js +1 -1
  11. package/constant/emoji.js +1 -1
  12. package/constant/identity.js +1 -1
  13. package/constant/index.js +1 -1
  14. package/constant/keyboardCode.js +1 -1
  15. package/constant/licensePlate.js +1 -1
  16. package/constant/name.js +1 -1
  17. package/constant/platform.js +1 -1
  18. package/constant/protocol.js +1 -1
  19. package/constant/ui.js +1 -1
  20. package/constant.js +1 -1
  21. package/content-disposition/index.js +1 -1
  22. package/contentDisposition.js +1 -1
  23. package/cookie/index.js +1 -1
  24. package/cookie/src/index.js +1 -1
  25. package/cookie.js +1 -1
  26. package/date/convertTime.js +1 -1
  27. package/date/convertToDuration.js +1 -1
  28. package/date/index.js +1 -1
  29. package/date.js +1 -1
  30. package/decimal/decimal.js +22 -22
  31. package/decimal/index.js +1 -1
  32. package/decimal.js +1 -1
  33. package/dom-helpers/activeElement.js +1 -1
  34. package/dom-helpers/addClass.js +1 -1
  35. package/dom-helpers/addEventListener.js +1 -1
  36. package/dom-helpers/animate.js +1 -1
  37. package/dom-helpers/animationFrame.js +1 -1
  38. package/dom-helpers/attribute.js +1 -1
  39. package/dom-helpers/camelize.js +1 -1
  40. package/dom-helpers/camelizeStyle.js +1 -1
  41. package/dom-helpers/canUseDOM.js +1 -1
  42. package/dom-helpers/childElements.js +1 -1
  43. package/dom-helpers/childNodes.js +1 -1
  44. package/dom-helpers/clear.js +1 -1
  45. package/dom-helpers/closest.js +1 -1
  46. package/dom-helpers/collectElements.js +1 -1
  47. package/dom-helpers/collectSiblings.js +1 -1
  48. package/dom-helpers/contains.js +1 -1
  49. package/dom-helpers/css.js +1 -1
  50. package/dom-helpers/filterEventHandler.js +1 -1
  51. package/dom-helpers/getComputedStyle.js +1 -1
  52. package/dom-helpers/getScrollAccessor.js +1 -1
  53. package/dom-helpers/hasClass.js +1 -1
  54. package/dom-helpers/height.js +1 -1
  55. package/dom-helpers/hyphenate.js +1 -1
  56. package/dom-helpers/hyphenateStyle.js +1 -1
  57. package/dom-helpers/index.js +1 -1
  58. package/dom-helpers/insertAfter.js +1 -1
  59. package/dom-helpers/isDocument.js +1 -1
  60. package/dom-helpers/isInput.js +1 -1
  61. package/dom-helpers/isTransform.js +1 -1
  62. package/dom-helpers/isVisible.js +1 -1
  63. package/dom-helpers/isWindow.js +1 -1
  64. package/dom-helpers/listen.js +1 -1
  65. package/dom-helpers/matches.js +1 -1
  66. package/dom-helpers/nextUntil.js +1 -1
  67. package/dom-helpers/offset.js +1 -1
  68. package/dom-helpers/offsetParent.js +1 -1
  69. package/dom-helpers/ownerDocument.js +1 -1
  70. package/dom-helpers/ownerWindow.js +1 -1
  71. package/dom-helpers/parents.js +1 -1
  72. package/dom-helpers/position.js +1 -1
  73. package/dom-helpers/prepend.js +1 -1
  74. package/dom-helpers/querySelectorAll.js +1 -1
  75. package/dom-helpers/reflow.js +1 -1
  76. package/dom-helpers/remove.js +1 -1
  77. package/dom-helpers/removeClass.js +1 -1
  78. package/dom-helpers/removeEventListener.js +1 -1
  79. package/dom-helpers/scrollLeft.js +1 -1
  80. package/dom-helpers/scrollParent.js +1 -1
  81. package/dom-helpers/scrollTo.js +1 -1
  82. package/dom-helpers/scrollTop.js +1 -1
  83. package/dom-helpers/scrollbarSize.js +1 -1
  84. package/dom-helpers/siblings.js +1 -1
  85. package/dom-helpers/text.js +1 -1
  86. package/dom-helpers/toggleClass.js +1 -1
  87. package/dom-helpers/transitionEnd.js +1 -1
  88. package/dom-helpers/triggerEvent.js +1 -1
  89. package/dom-helpers/types.js +5 -1
  90. package/dom-helpers/width.js +1 -1
  91. package/domHelpers.js +1 -1
  92. package/emitter/index.js +1 -1
  93. package/emitter/src/index.js +1 -1
  94. package/emitter.js +1 -1
  95. package/file/fileToURL.js +1 -1
  96. package/file/index.js +1 -1
  97. package/file/saveAs.js +1 -1
  98. package/file.js +1 -1
  99. package/idb/index.js +1 -1
  100. package/idb.js +1 -1
  101. package/index.js +1 -1
  102. package/invariant/index.js +1 -1
  103. package/invariant.js +1 -1
  104. package/is/index.js +1 -1
  105. package/is.js +1 -1
  106. package/js-cookie/index.js +1 -1
  107. package/js-cookie/src/api.js +1 -1
  108. package/js-cookie/src/assign.js +1 -1
  109. package/js-cookie/src/converter.js +1 -1
  110. package/jsCookie.js +1 -1
  111. package/lunar/index.js +1 -1
  112. package/lunar/lib/Holiday.js +1 -1
  113. package/lunar/lib/HolidayUtil.js +1 -1
  114. package/lunar/lib/I18n.js +1 -1
  115. package/lunar/lib/JieQi.js +1 -1
  116. package/lunar/lib/Lunar.js +1 -1
  117. package/lunar/lib/LunarMonth.js +1 -1
  118. package/lunar/lib/LunarTime.js +1 -1
  119. package/lunar/lib/LunarUtil.js +1 -1
  120. package/lunar/lib/LunarYear.js +1 -1
  121. package/lunar/lib/ShouXingUtil.js +1 -1
  122. package/lunar/lib/Solar.js +1 -1
  123. package/lunar/lib/SolarHalfYear.js +1 -1
  124. package/lunar/lib/SolarMonth.js +1 -1
  125. package/lunar/lib/SolarSeason.js +1 -1
  126. package/lunar/lib/SolarUtil.js +1 -1
  127. package/lunar/lib/SolarWeek.js +1 -1
  128. package/lunar/lib/SolarYear.js +1 -1
  129. package/lunar/lib/index.js +1 -1
  130. package/lunar.js +1 -1
  131. package/math/index.js +1 -1
  132. package/math.js +1 -1
  133. package/md5/index.js +1 -1
  134. package/md5.js +1 -1
  135. package/mock/MockWebSocket.js +1 -1
  136. package/mock/MockXMLHttpRequest.js +1 -1
  137. package/mock/index.js +1 -1
  138. package/mock.js +1 -1
  139. package/normalize-wheel/ExecutionEnvironment.js +1 -1
  140. package/normalize-wheel/UserAgent_DEPRECATED.js +1 -1
  141. package/normalize-wheel/index.js +1 -1
  142. package/normalize-wheel/isEventSupported.js +10 -14
  143. package/normalizeWheel.js +1 -1
  144. package/number-to-chinese/index.js +1 -1
  145. package/numberToChinese.js +1 -1
  146. package/nzh/cn.js +1 -1
  147. package/nzh/hk.js +1 -1
  148. package/nzh/index.js +1 -1
  149. package/nzh/nzh.js +1 -1
  150. package/nzh/src/autoGet.js +1 -1
  151. package/nzh/src/index.js +1 -1
  152. package/nzh/src/langs/cn_b.js +1 -1
  153. package/nzh/src/langs/cn_s.js +1 -1
  154. package/nzh/src/langs/hk_b.js +1 -1
  155. package/nzh/src/langs/hk_s.js +1 -1
  156. package/nzh/src/utils.js +1 -1
  157. package/nzh.js +1 -1
  158. package/object-keys-sort/index.js +1 -1
  159. package/objectKeysSort.js +1 -1
  160. package/package.json +1 -1
  161. package/pinyin/index.js +1 -1
  162. package/pinyin/simplified.js +1 -1
  163. package/pinyin/src/core.js +1 -1
  164. package/pinyin/src/simplified.js +1 -1
  165. package/pinyin/src/simplified_dict.js +1 -1
  166. package/pinyin/src/traditional.js +1 -1
  167. package/pinyin/src/traditional_dict.js +1 -1
  168. package/pinyin/traditional.js +1 -1
  169. package/pinyin.js +1 -1
  170. package/query-string/base.js +1 -1
  171. package/query-string/index.js +1 -1
  172. package/query-string/splitOnFirst.js +1 -1
  173. package/queryString.js +1 -1
  174. package/random/address.js +1 -1
  175. package/random/constellation.js +1 -1
  176. package/random/image.js +1 -1
  177. package/random/index.js +1 -1
  178. package/random/licensePlate.js +1 -1
  179. package/random/name.js +1 -1
  180. package/random/number.js +1 -1
  181. package/random/text.js +1 -1
  182. package/random/time.js +1 -1
  183. package/random/web.js +1 -1
  184. package/random.js +1 -1
  185. package/screenfull/index.js +1 -1
  186. package/screenfull.js +1 -1
  187. package/sleep/index.js +1 -1
  188. package/sleep.js +1 -1
  189. package/snapdom/index.js +1 -1
  190. package/snapdom/src/api/preCache.js +51 -49
  191. package/snapdom/src/api/snapdom.js +171 -67
  192. package/snapdom/src/core/cache.js +2 -2
  193. package/snapdom/src/core/capture.js +249 -234
  194. package/snapdom/src/core/clone.js +151 -120
  195. package/snapdom/src/core/context.js +10 -8
  196. package/snapdom/src/core/plugins.js +69 -0
  197. package/snapdom/src/core/prepare.js +2 -2
  198. package/snapdom/src/exporters/download.js +1 -1
  199. package/snapdom/src/exporters/toBlob.js +1 -1
  200. package/snapdom/src/exporters/toCanvas.js +40 -40
  201. package/snapdom/src/exporters/toImg.js +1 -1
  202. package/snapdom/src/modules/CSSVar.js +66 -40
  203. package/snapdom/src/modules/background.js +39 -23
  204. package/snapdom/src/modules/changeCSS.js +1 -1
  205. package/snapdom/src/modules/counter.js +100 -86
  206. package/snapdom/src/modules/fonts.js +4 -4
  207. package/snapdom/src/modules/iconFonts.js +98 -14
  208. package/snapdom/src/modules/images.js +1 -1
  209. package/snapdom/src/modules/lineClamp.js +1 -1
  210. package/snapdom/src/modules/pseudo.js +147 -138
  211. package/snapdom/src/modules/rasterize.js +1 -1
  212. package/snapdom/src/modules/snapFetch.js +1 -1
  213. package/snapdom/src/modules/styles.js +1 -1
  214. package/snapdom/src/modules/svgDefs.js +86 -39
  215. package/snapdom/src/utils/browser.js +1 -1
  216. package/snapdom/src/utils/css.js +1 -1
  217. package/snapdom/src/utils/helpers.js +1 -1
  218. package/snapdom/src/utils/image.js +1 -1
  219. package/snapdom/types/snapdom.d.ts +253 -184
  220. package/snapdom.js +1 -1
  221. package/tinycolor/index.js +1 -1
  222. package/tinycolor/src/conversion.js +1 -1
  223. package/tinycolor/src/css-color-names.js +1 -1
  224. package/tinycolor/src/format-input.js +1 -1
  225. package/tinycolor/src/from-ratio.js +1 -1
  226. package/tinycolor/src/index.js +1 -1
  227. package/tinycolor/src/random.js +1 -1
  228. package/tinycolor/src/readability.js +1 -1
  229. package/tinycolor/src/to-ms-filter.js +1 -1
  230. package/tinycolor/src/utils.js +1 -1
  231. package/tinycolor.js +1 -1
  232. package/tree/index.js +1 -1
  233. package/tree/search/index.js +1 -1
  234. package/tree.js +1 -1
  235. package/tween/index.js +8 -0
  236. package/tween/src/easing.js +62 -0
  237. package/tween/src/tween.js +46 -0
  238. package/tween.js +8 -0
  239. package/types/dom-helpers/types.d.ts +2 -0
  240. package/types/normalize-wheel/index.d.ts +1 -1
  241. package/types/snapdom/src/api/snapdom.d.ts +4 -0
  242. package/types/snapdom/src/core/capture.d.ts +4 -18
  243. package/types/snapdom/src/core/context.d.ts +4 -4
  244. package/types/snapdom/src/core/exporters.d.ts +33 -0
  245. package/types/snapdom/src/core/plugins.d.ts +59 -0
  246. package/types/snapdom/src/modules/CSSVar.d.ts +3 -7
  247. package/types/snapdom/src/modules/iconFonts.d.ts +34 -0
  248. package/types/snapdom/src/modules/svgDefs.d.ts +9 -15
  249. package/types/tween/index.d.ts +1 -0
  250. package/types/tween/src/easing.d.ts +22 -0
  251. package/types/tween/src/index.d.ts +3 -0
  252. package/types/tween/src/tween.d.ts +22 -0
  253. package/types/validate/index.d.ts +3 -0
  254. package/types/validate/src/index.d.ts +39 -0
  255. package/types/validate/src/interface.d.ts +53 -0
  256. package/types/validate/src/locale/en-US.d.ts +47 -0
  257. package/types/validate/src/locale/zh-CN.d.ts +47 -0
  258. package/types/validate/src/message.d.ts +2 -0
  259. package/types/validate/src/rules/array.d.ts +12 -0
  260. package/types/validate/src/rules/base.d.ts +25 -0
  261. package/types/validate/src/rules/boolean.d.ts +8 -0
  262. package/types/validate/src/rules/custom.d.ts +7 -0
  263. package/types/validate/src/rules/number.d.ts +12 -0
  264. package/types/validate/src/rules/object.d.ts +9 -0
  265. package/types/validate/src/rules/string.d.ts +12 -0
  266. package/types/validate/src/rules/type.d.ts +9 -0
  267. package/types/validate/src/utils.d.ts +3 -0
  268. package/ui-color/compareColorByRange.js +1 -1
  269. package/ui-color/index.js +1 -1
  270. package/uiColor.js +1 -1
  271. package/url-toolkit/index.js +1 -1
  272. package/url-toolkit/src/url-toolkit.js +1 -1
  273. package/urlToolkit.js +1 -1
  274. package/validate/index.js +28 -0
  275. package/validate/src/index.js +106 -0
  276. package/validate/src/locale/en-US.js +50 -0
  277. package/validate/src/locale/zh-CN.js +50 -0
  278. package/validate/src/message.js +5 -0
  279. package/validate/src/rules/array.js +73 -0
  280. package/validate/src/rules/base.js +69 -0
  281. package/validate/src/rules/boolean.js +29 -0
  282. package/validate/src/rules/custom.js +26 -0
  283. package/validate/src/rules/number.js +54 -0
  284. package/validate/src/rules/object.js +39 -0
  285. package/validate/src/rules/string.js +54 -0
  286. package/validate/src/rules/type.js +35 -0
  287. package/validate/src/utils.js +8 -0
  288. package/validate.js +28 -0
  289. package/version/index.js +1 -1
  290. package/version.js +1 -1
@@ -0,0 +1,25 @@
1
+ import { InnerValidateOptions, ValidateMessagesTemplateType, ValidateOptions, ValidatorError } from './../interface';
2
+ /**
3
+ * @param options.trim trim string value
4
+ * @param options.ignoreEmptyString used form type
5
+ * @param options.message
6
+ * @param options.type
7
+ */
8
+ declare abstract class Base {
9
+ object: unknown;
10
+ message: ValidateOptions['message'];
11
+ type: ValidateOptions['type'];
12
+ error: null | ValidatorError;
13
+ _not?: boolean;
14
+ validateMessages: ValidateMessagesTemplateType;
15
+ field?: string;
16
+ constructor(object: unknown, options: InnerValidateOptions);
17
+ get not(): this;
18
+ get isRequired(): this;
19
+ get end(): ValidatorError | null;
20
+ addError(message: unknown): void;
21
+ getValidateMsg: (keyPath: string, info?: unknown) => unknown;
22
+ validate(expression: boolean, errorMessage: unknown): this;
23
+ collect(callback: (error: null | ValidatorError) => void): void;
24
+ }
25
+ export default Base;
@@ -0,0 +1,8 @@
1
+ import { InnerValidateOptions } from './../interface';
2
+ import Base from './base';
3
+ declare class BooleanValidator extends Base {
4
+ constructor(object: unknown, options: InnerValidateOptions);
5
+ get true(): this;
6
+ get false(): this;
7
+ }
8
+ export default BooleanValidator;
@@ -0,0 +1,7 @@
1
+ import { CustomValidatorType, InnerValidateOptions, ValidatorError } from './../interface';
2
+ import Base from './base';
3
+ declare class CustomValidator extends Base {
4
+ constructor(object: unknown, options: InnerValidateOptions);
5
+ validate_(validator: CustomValidatorType, callback?: (message?: ValidatorError | null) => void): ValidatorError | (Promise<void> | this)[] | null | undefined;
6
+ }
7
+ export default CustomValidator;
@@ -0,0 +1,12 @@
1
+ import { InnerValidateOptions } from './../interface';
2
+ import Base from './base';
3
+ declare class NumberValidator extends Base {
4
+ constructor(object: unknown, options: InnerValidateOptions);
5
+ min(num: number): this;
6
+ max(num: number): this;
7
+ equal(num: number): this;
8
+ range(min: number, max: number): this;
9
+ get positive(): NumberValidator;
10
+ get negative(): NumberValidator;
11
+ }
12
+ export default NumberValidator;
@@ -0,0 +1,9 @@
1
+ import { InnerValidateOptions } from './../interface';
2
+ import Base from './base';
3
+ declare class ObjectValidator extends Base {
4
+ constructor(object: unknown, options: InnerValidateOptions);
5
+ deepEqual(other: unknown): this;
6
+ hasKeys(keys: string[]): this;
7
+ get empty(): this;
8
+ }
9
+ export default ObjectValidator;
@@ -0,0 +1,12 @@
1
+ import { InnerValidateOptions } from './../interface';
2
+ import Base from './base';
3
+ declare class StringValidator extends Base {
4
+ constructor(object: unknown, options: InnerValidateOptions);
5
+ maxLength(length: number): this;
6
+ minLength(length: number): this;
7
+ length(length: number): this;
8
+ match(pattern: RegExp): this;
9
+ get uppercase(): StringValidator;
10
+ get lowercase(): StringValidator;
11
+ }
12
+ export default StringValidator;
@@ -0,0 +1,9 @@
1
+ import { InnerValidateOptions } from './../interface';
2
+ import Base from './base';
3
+ declare class TypeValidator extends Base {
4
+ constructor(object: unknown, options: InnerValidateOptions);
5
+ get email(): this;
6
+ get url(): this;
7
+ get ip(): this;
8
+ }
9
+ export default TypeValidator;
@@ -0,0 +1,3 @@
1
+ import type { ValidateMessagesTemplateType, ValidateMessagesType } from './interface';
2
+ export declare const mergeTemplate: <T = ValidateMessagesType>(defaultValidateMessages: T, validateMessages: ValidateMessagesType) => T;
3
+ export declare const getTemplate: (validateMessages: ValidateMessagesTemplateType, keyPath: string) => any;
@@ -1,4 +1,4 @@
1
- /* 2025-10-28 09:57:10 */
1
+ /* 2025-11-03 10:27:31 */
2
2
  function i(r = [34797, 15747172]) {
3
3
  return (n = 1) => {
4
4
  const o = r, t = Math.log(256) / Math.log(2), e = o[0] >>> t * 2 & 255, g = o[0] >>> t * 1 & 255, l = o[0] >>> t * 0 & 255, c = o[1] >>> t * 2 & 255, s = o[1] >>> t * 1 & 255, f = o[1] >>> t * 0 & 255, a = c - (c - e) * n, b = s - (s - g) * n, h = f - (f - l) * n;
package/ui-color/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* 2025-10-28 09:57:10 */
1
+ /* 2025-11-03 10:27:31 */
2
2
  import { TinyColor as e } from "../tinycolor/src/index.js";
3
3
  import { default as Q } from "./compareColorByRange.js";
4
4
  const c = 10, f = {
package/uiColor.js CHANGED
@@ -1,4 +1,4 @@
1
- /* 2025-10-28 09:57:10 */
1
+ /* 2025-11-03 10:27:31 */
2
2
  import "./tinycolor/src/index.js";
3
3
  import { default as o } from "./ui-color/compareColorByRange.js";
4
4
  import { LENGTH as t, PRIMARY_COLOR_KEY_MAPPING as p, blue as g, colorPresets as n, colors as m, cyan as s, generate as y, generateDark as P, gold as c, gray as d, grayPresets as i, green as u, lime as R, magenta as f, orange as k, orangered as _, palette as x, paletteDark as A, pinkpurple as C, primary as D, purple as E, red as G, yellow as I } from "./ui-color/index.js";
@@ -1,4 +1,4 @@
1
- /* 2025-10-28 09:57:10 */
1
+ /* 2025-11-03 10:27:31 */
2
2
  import { buildAbsoluteURL as e, buildURLFromParts as l, default as o, normalizePath as t, parseURL as u } from "./src/url-toolkit.js";
3
3
  export {
4
4
  e as buildAbsoluteURL,
@@ -1,4 +1,4 @@
1
- /* 2025-10-28 09:57:10 */
1
+ /* 2025-11-03 10:27:31 */
2
2
  const l = /^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/, p = /^(?=([^\/?#]*))\1([^]*)$/, f = /(?:\/|^)\.(?=\/)/g, m = /(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g;
3
3
  function E(r, a, s) {
4
4
  if (s = s || {}, r = r.trim(), a = a.trim(), !a) {
package/urlToolkit.js CHANGED
@@ -1,4 +1,4 @@
1
- /* 2025-10-28 09:57:10 */
1
+ /* 2025-11-03 10:27:31 */
2
2
  import { buildAbsoluteURL as e, buildURLFromParts as l, default as o, normalizePath as t, parseURL as u } from "./url-toolkit/src/url-toolkit.js";
3
3
  export {
4
4
  e as buildAbsoluteURL,
@@ -0,0 +1,28 @@
1
+ /* 2025-11-03 10:27:31 */
2
+ import { Schema as t, default as o } from "./src/index.js";
3
+ import { default as l } from "./src/rules/array.js";
4
+ import { default as d } from "./src/rules/boolean.js";
5
+ import { default as u } from "./src/rules/custom.js";
6
+ import { default as p, default as i, default as x } from "./src/locale/zh-CN.js";
7
+ import { default as c } from "./src/rules/number.js";
8
+ import { default as n } from "./src/rules/object.js";
9
+ import { default as S } from "./src/rules/string.js";
10
+ import { default as h } from "./src/rules/type.js";
11
+ import { default as C } from "./src/locale/en-US.js";
12
+ import { mergeTemplate as T } from "./src/utils.js";
13
+ export {
14
+ l as ArrayValidator,
15
+ d as BooleanValidator,
16
+ u as CustomValidator,
17
+ p as DefaultValidateMessage,
18
+ c as NumberValidator,
19
+ n as ObjectValidator,
20
+ t as Schema,
21
+ S as StringValidator,
22
+ h as TypeValidator,
23
+ o as default,
24
+ i as defaultValidateLocale,
25
+ C as enUSValidateLocale,
26
+ T as mergeTemplate,
27
+ x as zhCNValidateLocale
28
+ };
@@ -0,0 +1,106 @@
1
+ /* 2025-11-03 10:27:31 */
2
+ import V from "lodash/defaultsDeep";
3
+ import u from "lodash/isArray.js";
4
+ import E from "lodash/isFunction.js";
5
+ import v from "lodash/isObjectLike.js";
6
+ import C from "./rules/array.js";
7
+ import M from "./rules/boolean.js";
8
+ import S from "./rules/custom.js";
9
+ import q from "./rules/number.js";
10
+ import O from "./rules/object.js";
11
+ import A from "./rules/string.js";
12
+ import P from "./rules/type.js";
13
+ import { mergeTemplate as y } from "./utils.js";
14
+ const f = (l, e) => new b(l, { field: "value", ...e });
15
+ f.globalConfig = {};
16
+ f.setGlobalConfig = (l) => {
17
+ f.globalConfig = V(
18
+ {},
19
+ l,
20
+ f.globalConfig
21
+ );
22
+ };
23
+ class b {
24
+ constructor(e, a) {
25
+ const n = f.globalConfig, s = {
26
+ ...n,
27
+ ...a,
28
+ validateMessages: y(
29
+ n.validateMessages,
30
+ a.validateMessages
31
+ )
32
+ };
33
+ this.string = new A(e, s), this.number = new q(e, s), this.array = new C(e, s), this.object = new O(e, s), this.boolean = new M(e, s), this.type = new P(e, s), this.custom = new S(e, s);
34
+ }
35
+ }
36
+ class U {
37
+ constructor(e, a = {}) {
38
+ this.schema = e, this.options = a;
39
+ }
40
+ // 更新校验信息
41
+ messages(e) {
42
+ this.options = {
43
+ ...this.options,
44
+ validateMessages: y(
45
+ this.options.validateMessages,
46
+ e
47
+ )
48
+ };
49
+ }
50
+ validate(e, a) {
51
+ if (!v(e)) return;
52
+ const n = [];
53
+ let s = null;
54
+ function m(t, h) {
55
+ s || (s = {}), s && (!s[t] || h.requiredError) && (s[t] = h);
56
+ }
57
+ this.schema && Object.entries(this.schema).forEach(([t, h], T, x) => {
58
+ if (u(this.schema[t]))
59
+ for (let c = 0; c < this.schema[t].length; c++) {
60
+ const o = this.schema[t][c], g = o.type, w = o.message;
61
+ if (!g) {
62
+ if (!o.validator) throw `You must specify a type to field ${t}!`;
63
+ }
64
+ const p = {
65
+ ...this.options,
66
+ message: w,
67
+ field: t
68
+ };
69
+ "ignoreEmptyString" in o && (p.ignoreEmptyString = o.ignoreEmptyString), "strict" in o && (p.strict = o.strict);
70
+ const d = new b(e[t], p);
71
+ let i = d.type[g] || null;
72
+ if (!i) if (o.validator) {
73
+ i = d.custom.validate_(o.validator), u(i) && i[0]?.then ? n.push({
74
+ function: i[0],
75
+ _this: i[1],
76
+ key: t
77
+ }) : i && m(t, i);
78
+ continue;
79
+ } else
80
+ i = d[g];
81
+ if (Object.entries(o).forEach(([r, B], D, F) => {
82
+ o.required && (i = i.isRequired), r !== "message" && i?.[r] && o[r] && v(i[r]) && (i = i[r]), i?.[r] && o[r] !== void 0 && E(i[r]) && (i = i[r](o[r]));
83
+ }), i.collect((r) => {
84
+ r && m(t, r);
85
+ }), s)
86
+ break;
87
+ }
88
+ }), n.length > 0 ? Promise.all(n.map((t) => t.function)).then(() => {
89
+ n.forEach((t) => {
90
+ "error" in t._this && t._this.error && m(t.key, t._this.error);
91
+ }), a?.(s);
92
+ }) : a?.(s);
93
+ }
94
+ }
95
+ export {
96
+ C as ArrayValidator,
97
+ M as BooleanValidator,
98
+ S as CustomValidator,
99
+ q as NumberValidator,
100
+ O as ObjectValidator,
101
+ U as Schema,
102
+ A as StringValidator,
103
+ P as TypeValidator,
104
+ f as default,
105
+ y as mergeTemplate
106
+ };
@@ -0,0 +1,50 @@
1
+ /* 2025-11-03 10:27:31 */
2
+ const e = "#{field} is not a #{type} type", t = {
3
+ required: "#{field} is required",
4
+ type: {
5
+ ip: e,
6
+ email: e,
7
+ url: e,
8
+ string: e,
9
+ number: e,
10
+ array: e,
11
+ object: e,
12
+ boolean: e
13
+ },
14
+ number: {
15
+ min: "`#{value}` is not greater than `#{min}`",
16
+ max: "`#{value}` is not less than `#{max}`",
17
+ equal: "`#{value}` is not equal to `#{equal}`",
18
+ range: "`#{value}` is not in range `#{min} ~ #{max}`",
19
+ positive: "`#{value}` is not a positive number",
20
+ negative: "`#{value}` is not a negative number"
21
+ },
22
+ string: {
23
+ maxLength: "#{field} cannot be longer than #{maxLength} characters",
24
+ minLength: "#{field} must be at least #{minLength} characters",
25
+ length: "#{field} must be exactly #{length} characters",
26
+ match: "`#{value}` does not match pattern #{pattern}",
27
+ uppercase: "`#{value}` must be all uppercase",
28
+ lowercase: "`#{value}` must be all lowercased"
29
+ },
30
+ array: {
31
+ length: "#{field} must be exactly #{length} in length",
32
+ minLength: "#{field} cannot be less than #{minLength} in length",
33
+ maxLength: "#{field} cannot be greater than #{maxLength} in length",
34
+ includes: "#{field} is not includes #{includes}",
35
+ deepEqual: "#{field} is not deep equal with #{deepEqual}",
36
+ empty: "#{field} is not an empty array"
37
+ },
38
+ object: {
39
+ deepEqual: "#{field} is not deep equal to expected value",
40
+ hasKeys: "#{field} does not contain required fields",
41
+ empty: "#{field} is not an empty object"
42
+ },
43
+ boolean: {
44
+ true: "Expect true but got `#{value}`",
45
+ false: "Expect false but got `#{value}`"
46
+ }
47
+ };
48
+ export {
49
+ t as default
50
+ };
@@ -0,0 +1,50 @@
1
+ /* 2025-11-03 10:27:31 */
2
+ const e = {
3
+ required: "#{field} 是必填项",
4
+ type: {
5
+ string: "#{field} 不是合法的文本类型",
6
+ number: "#{field} 不是合法的数字类型",
7
+ boolean: "#{field} 不是合法的布尔类型",
8
+ array: "#{field} 不是合法的数组类型",
9
+ object: "#{field} 不是合法的对象类型",
10
+ url: "#{field} 不是合法的 url 地址",
11
+ email: "#{field} 不是合法的邮箱地址",
12
+ ip: "#{field} 不是合法的 IP 地址"
13
+ },
14
+ number: {
15
+ min: "`#{value}` 小于最小值 `#{min}`",
16
+ max: "`#{value}` 大于最大值 `#{max}`",
17
+ equal: "`#{value}` 不等于 `#{equal}`",
18
+ range: "`#{value}` 不在 `#{min} ~ #{max}` 范围内",
19
+ positive: "`#{value}` 不是正数",
20
+ negative: "`#{value}` 不是负数"
21
+ },
22
+ array: {
23
+ length: "#{field} 个数不等于 #{length}",
24
+ minLength: "#{field} 个数最少为 #{minLength}",
25
+ maxLength: "#{field} 个数最多为 #{maxLength}",
26
+ includes: "#{field} 不包含 #{includes}",
27
+ deepEqual: "#{field} 不等于 #{deepEqual}",
28
+ empty: "#{field} 不是空数组"
29
+ },
30
+ string: {
31
+ minLength: "字符数最少为 #{minLength}",
32
+ maxLength: "字符数最多为 #{maxLength}",
33
+ length: "字符数必须是 #{length}",
34
+ match: "`#{value}` 不符合模式 #{pattern}",
35
+ uppercase: "`#{value}` 必须全大写",
36
+ lowercase: "`#{value}` 必须全小写"
37
+ },
38
+ object: {
39
+ deepEqual: "#{field} 不等于期望值",
40
+ hasKeys: "#{field} 不包含必须字段",
41
+ empty: "#{field} 不是对象"
42
+ },
43
+ boolean: {
44
+ true: "期望是 `true`",
45
+ false: "期望是 `false`"
46
+ }
47
+ };
48
+ export {
49
+ e as default
50
+ };
@@ -0,0 +1,5 @@
1
+ /* 2025-11-03 10:27:31 */
2
+ import e from "./locale/zh-CN.js";
3
+ export {
4
+ e as default
5
+ };
@@ -0,0 +1,73 @@
1
+ /* 2025-11-03 10:27:31 */
2
+ import i from "lodash/isArray.js";
3
+ import a from "lodash/isEqual.js";
4
+ import { isEmptyArray as s } from "../../../is/index.js";
5
+ import h from "./base.js";
6
+ class d extends h {
7
+ constructor(t, e) {
8
+ super(t, {
9
+ ...e,
10
+ type: "array"
11
+ }), this.validate(
12
+ e && e.strict ? i(this.object) : !0,
13
+ this.getValidateMsg("type.array", {
14
+ value: this.object,
15
+ type: this.type
16
+ })
17
+ );
18
+ }
19
+ length(t) {
20
+ return this.object ? this.validate(
21
+ this.object.length === t,
22
+ this.getValidateMsg("array.length", {
23
+ value: this.object,
24
+ length: t
25
+ })
26
+ ) : this;
27
+ }
28
+ minLength(t) {
29
+ return this.object ? this.validate(
30
+ this.object.length >= t,
31
+ this.getValidateMsg("array.minLength", {
32
+ value: this.object,
33
+ minLength: t
34
+ })
35
+ ) : this;
36
+ }
37
+ maxLength(t) {
38
+ return this.object ? this.validate(
39
+ this.object.length <= t,
40
+ this.getValidateMsg("array.maxLength", {
41
+ value: this.object,
42
+ maxLength: t
43
+ })
44
+ ) : this;
45
+ }
46
+ includes(t) {
47
+ return this.object ? this.validate(
48
+ t.every((e) => this.object.indexOf(e) !== -1),
49
+ this.getValidateMsg("array.includes", {
50
+ value: this.object,
51
+ includes: t
52
+ })
53
+ ) : this;
54
+ }
55
+ deepEqual(t) {
56
+ return this.object ? this.validate(
57
+ a(this.object, t),
58
+ this.getValidateMsg("array.deepEqual", {
59
+ value: this.object,
60
+ deepEqual: t
61
+ })
62
+ ) : this;
63
+ }
64
+ get empty() {
65
+ return this.validate(
66
+ s(this.object),
67
+ this.getValidateMsg("array.empty", { value: this.object })
68
+ );
69
+ }
70
+ }
71
+ export {
72
+ d as default
73
+ };
@@ -0,0 +1,69 @@
1
+ /* 2025-11-03 10:27:31 */
2
+ import n from "lodash/isArray.js";
3
+ import f from "lodash/isFunction.js";
4
+ import a from "lodash/isObject.js";
5
+ import l from "lodash/isString.js";
6
+ import { isEmptyValue as u, isEmptyArray as c } from "../../../is/index.js";
7
+ import d from "../locale/zh-CN.js";
8
+ import { getTemplate as g, mergeTemplate as p } from "../utils.js";
9
+ class T {
10
+ constructor(t, e) {
11
+ this.getValidateMsg = (h, m = {}) => {
12
+ const r = Object.assign({}, m, {
13
+ value: this.object,
14
+ field: this.field,
15
+ type: this.type
16
+ }), s = g(this.validateMessages, h);
17
+ return f(s) ? s(r) : l(s) ? s.replace(/#\{.+?\}/g, (o) => {
18
+ const i = o.slice(2, -1);
19
+ if (i in r) {
20
+ if (a(r[i]) || n(r[i]))
21
+ try {
22
+ return JSON.stringify(r[i]);
23
+ } catch {
24
+ return r[i];
25
+ }
26
+ return String(r[i]);
27
+ }
28
+ return o;
29
+ }) : s;
30
+ }, a(e) && l(t) && e.trim ? this.object = t.trim() : a(e) && e.ignoreEmptyString && t === "" ? this.object = void 0 : this.object = t, this.message = e.message, this.type = e.type, this.error = null, this.field = e.field || e.type, this.validateMessages = p(
31
+ d,
32
+ e.validateMessages
33
+ );
34
+ }
35
+ get not() {
36
+ return this._not = !this._not, this;
37
+ }
38
+ get isRequired() {
39
+ if (u(this.object) || c(this.object)) {
40
+ const t = this.getValidateMsg("required");
41
+ this.error = {
42
+ value: this.object,
43
+ type: this.type,
44
+ requiredError: !0,
45
+ message: this.message || (a(t) ? t : `${this._not ? "[NOT MODE]:" : ""}${t}`)
46
+ };
47
+ }
48
+ return this;
49
+ }
50
+ get end() {
51
+ return this.error;
52
+ }
53
+ addError(t) {
54
+ this.error || t && (this.error = {
55
+ value: this.object,
56
+ type: this.type,
57
+ message: this.message || (a(t) ? t : `${this._not ? "[NOT MODE]:" : ""}${t}`)
58
+ });
59
+ }
60
+ validate(t, e) {
61
+ return (this._not ? t : !t) && this.addError(e), this;
62
+ }
63
+ collect(t) {
64
+ t?.(this.error);
65
+ }
66
+ }
67
+ export {
68
+ T as default
69
+ };
@@ -0,0 +1,29 @@
1
+ /* 2025-11-03 10:27:31 */
2
+ import a from "lodash/isBoolean.js";
3
+ import s from "./base.js";
4
+ class r extends s {
5
+ constructor(e, t) {
6
+ super(e, {
7
+ ...t,
8
+ type: "boolean"
9
+ }), this.validate(
10
+ t?.strict ? a(this.object) : !0,
11
+ this.getValidateMsg("type.boolean")
12
+ );
13
+ }
14
+ get true() {
15
+ return this.validate(
16
+ this.object === !0,
17
+ this.getValidateMsg("boolean.true")
18
+ );
19
+ }
20
+ get false() {
21
+ return this.validate(
22
+ this.object === !1,
23
+ this.getValidateMsg("boolean.false")
24
+ );
25
+ }
26
+ }
27
+ export {
28
+ r as default
29
+ };
@@ -0,0 +1,26 @@
1
+ /* 2025-11-03 10:27:31 */
2
+ import o from "./base.js";
3
+ class n extends o {
4
+ constructor(t, r) {
5
+ super(t, {
6
+ ...r,
7
+ type: "custom"
8
+ });
9
+ }
10
+ validate_(t, r) {
11
+ if (t) {
12
+ const e = t(this.object, this.addError.bind(this));
13
+ return e && e.then ? (r && e.then(
14
+ () => {
15
+ r?.(this.error);
16
+ },
17
+ (s) => {
18
+ console.error(s);
19
+ }
20
+ ), [e, this]) : (r?.(this.error), this.error);
21
+ }
22
+ }
23
+ }
24
+ export {
25
+ n as default
26
+ };
@@ -0,0 +1,54 @@
1
+ /* 2025-11-03 10:27:31 */
2
+ import s from "lodash/isNumber.js";
3
+ import { isEmptyValue as i } from "../../../is/index.js";
4
+ import a from "./base.js";
5
+ class l extends a {
6
+ constructor(t, e) {
7
+ super(t, {
8
+ ...e,
9
+ type: "number"
10
+ }), this.validate(
11
+ e && e.strict ? s(this.object) : !0,
12
+ this.getValidateMsg("type.number")
13
+ );
14
+ }
15
+ min(t) {
16
+ return i(this.object) ? this : this.validate(
17
+ this.object >= t,
18
+ this.getValidateMsg("number.min", { min: t })
19
+ );
20
+ }
21
+ max(t) {
22
+ return i(this.object) ? this : this.validate(
23
+ this.object <= t,
24
+ this.getValidateMsg("number.max", { max: t })
25
+ );
26
+ }
27
+ equal(t) {
28
+ return i(this.object) ? this : this.validate(
29
+ this.object === t,
30
+ this.getValidateMsg("number.equal", { equal: t })
31
+ );
32
+ }
33
+ range(t, e) {
34
+ return i(this.object) ? this : this.validate(
35
+ this.object >= t && this.object <= e,
36
+ this.getValidateMsg("number.range", { min: t, max: e })
37
+ );
38
+ }
39
+ get positive() {
40
+ return i(this.object) ? this : this.validate(
41
+ this.object > 0,
42
+ this.getValidateMsg("number.positive")
43
+ );
44
+ }
45
+ get negative() {
46
+ return i(this.object) ? this : this.validate(
47
+ this.object < 0,
48
+ this.getValidateMsg("number.negative")
49
+ );
50
+ }
51
+ }
52
+ export {
53
+ l as default
54
+ };