@regle/rules 1.17.3 → 1.17.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @regle/rules v1.17.3
2
+ * @regle/rules v1.17.4
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
@@ -698,7 +698,7 @@ declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [before:
698
698
  * })
699
699
  * ```
700
700
  *
701
- * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#datebetweeen Documentation}
701
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#datebetween Documentation}
702
702
  */
703
703
  declare const dateBetween: RegleRuleWithParamsDefinition<string | Date, [before: MaybeInput<string | Date>, after: MaybeInput<string | Date>, options?: CommonComparisonOptions], false, boolean, MaybeInput<string | Date>>;
704
704
  /**
@@ -1442,7 +1442,7 @@ declare const string: RegleRuleDefinition<unknown, [], false, boolean, MaybeInpu
1442
1442
  *
1443
1443
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#type Documentation}
1444
1444
  */
1445
- declare function type<T>(): RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<T>>;
1445
+ declare function type$1<T>(): RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<T>>;
1446
1446
  /**
1447
1447
  * Validates uppercase strings.
1448
1448
  *
@@ -1458,4 +1458,4 @@ declare function type<T>(): RegleRuleDefinition<unknown, [], false, boolean, May
1458
1458
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#uppercase Documentation}
1459
1459
  */
1460
1460
  declare const uppercase: RegleRuleDefinition<string, [], false, boolean, unknown, string>;
1461
- export { EnumLike, UrlOptions, alpha, alphaNum, and, applyIf, assignIf, between, boolean, checked, contains, date, dateAfter, dateBefore, dateBetween, decimal, email, emoji, endsWith, exactDigits, exactLength, exactValue, file, fileType, getSize, hexadecimal, hostname, httpUrl, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, lowercase, macAddress, matchRegex, maxFileSize, maxLength, maxValue, minFileSize, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, uppercase, url, withAsync, withMessage, withParams, withTooltip };
1461
+ export { EnumLike, UrlOptions, alpha, alphaNum, and, applyIf, assignIf, between, boolean, checked, contains, date, dateAfter, dateBefore, dateBetween, decimal, email, emoji, endsWith, exactDigits, exactLength, exactValue, file, fileType, getSize, hexadecimal, hostname, httpUrl, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, lowercase, macAddress, matchRegex, maxFileSize, maxLength, maxValue, minFileSize, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type$1 as type, uppercase, url, withAsync, withMessage, withParams, withTooltip };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @regle/rules v1.17.3
2
+ * @regle/rules v1.17.4
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
@@ -485,6 +485,98 @@ function isString(value) {
485
485
  return true;
486
486
  }
487
487
 
488
+ /**
489
+ * Factory function to create value comparison rules (minValue/maxValue).
490
+ * Reduces duplication between similar comparison rules.
491
+ */
492
+ function createValueComparisonRule({ type: type$1, direction }) {
493
+ const compare = (value, limit, allowEqual) => {
494
+ if (direction === "min") return allowEqual ? value >= limit : value > limit;
495
+ return allowEqual ? value <= limit : value < limit;
496
+ };
497
+ const getMessage = (limit, allowEqual) => {
498
+ if (direction === "min") return allowEqual ? `The value must be greater than or equal to ${limit}` : `The value must be greater than ${limit}`;
499
+ return allowEqual ? `The value must be less than or equal to ${limit}` : `The value must be less than ${limit}`;
500
+ };
501
+ return createRule({
502
+ type: type$1,
503
+ validator: (value, limit, options) => {
504
+ const { allowEqual = true } = options ?? {};
505
+ if (isFilled(value) && isFilled(limit)) {
506
+ if (!isNaN(toNumber(value)) && !isNaN(toNumber(limit))) return compare(toNumber(value), toNumber(limit), allowEqual);
507
+ console.warn(`[${type$1}] Value or parameter isn't a number, got value: ${value}, parameter: ${limit}`);
508
+ return true;
509
+ }
510
+ return true;
511
+ },
512
+ message: ({ $params: [limit, options] }) => {
513
+ const { allowEqual = true } = options ?? {};
514
+ return getMessage(limit, allowEqual);
515
+ }
516
+ });
517
+ }
518
+
519
+ /**
520
+ * Factory function to create length comparison rules (minLength/maxLength).
521
+ * Reduces duplication between similar length rules.
522
+ */
523
+ function createLengthRule({ type: type$1, direction }) {
524
+ const compare = (size, limit, allowEqual) => {
525
+ if (direction === "min") return allowEqual ? size >= limit : size > limit;
526
+ return allowEqual ? size <= limit : size < limit;
527
+ };
528
+ const getMessage = (value, limit) => {
529
+ if (Array.isArray(value)) return direction === "min" ? `The list must have at least ${limit} items` : `The list must have at most ${limit} items`;
530
+ return direction === "min" ? `The value must be at least ${limit} characters long` : `The value must be at most ${limit} characters long`;
531
+ };
532
+ return createRule({
533
+ type: type$1,
534
+ validator: (value, limit, options) => {
535
+ const { allowEqual = true } = options ?? {};
536
+ if (isFilled(value, false) && isFilled(limit)) {
537
+ if (isNumber(limit)) return compare(getSize(value), limit, allowEqual);
538
+ console.warn(`[${type$1}] Parameter isn't a number, got parameter: ${limit}`);
539
+ return true;
540
+ }
541
+ return true;
542
+ },
543
+ message: ({ $value, $params: [limit] }) => {
544
+ return getMessage($value, limit);
545
+ }
546
+ });
547
+ }
548
+
549
+ /**
550
+ * Factory function to create string operation rules (contains/startsWith/endsWith).
551
+ * Reduces duplication between similar string validation rules.
552
+ */
553
+ function createStringOperationRule({ type: type$1, operation }) {
554
+ const operationFn = (value, part) => {
555
+ switch (operation) {
556
+ case "contains": return value.includes(part);
557
+ case "startsWith": return value.startsWith(part);
558
+ case "endsWith": return value.endsWith(part);
559
+ }
560
+ };
561
+ const getMessage = (part) => {
562
+ switch (operation) {
563
+ case "contains": return `The value must contain ${part}`;
564
+ case "startsWith": return `The value must start with ${part}`;
565
+ case "endsWith": return `The value must end with ${part}`;
566
+ }
567
+ };
568
+ return createRule({
569
+ type: type$1,
570
+ validator(value, part) {
571
+ if (isFilled(value) && isFilled(part) && isString(value) && isString(part)) return operationFn(value, part);
572
+ return true;
573
+ },
574
+ message({ $params: [part] }) {
575
+ return getMessage(part);
576
+ }
577
+ });
578
+ }
579
+
488
580
  /**
489
581
  * The `and` operator combines multiple rules and validates successfully only if **all** provided rules are valid.
490
582
  *
@@ -817,7 +909,7 @@ const alpha = createRule({
817
909
  if (options?.allowSymbols) return matchRegex(value, ALPHA_SYMBOL_REGEX);
818
910
  return matchRegex(value, ALPHA_REGEX);
819
911
  },
820
- message: "The value is not alphabetical"
912
+ message: "The value must be alphabetical"
821
913
  });
822
914
 
823
915
  /**
@@ -967,15 +1059,9 @@ const checked = createRule({
967
1059
  *
968
1060
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#contains Documentation}
969
1061
  */
970
- const contains = createRule({
1062
+ const contains = createStringOperationRule({
971
1063
  type: "contains",
972
- validator(value, part) {
973
- if (isFilled(value) && isFilled(part) && isString(value) && isString(part)) return value.includes(part);
974
- return true;
975
- },
976
- message({ $params: [part] }) {
977
- return `The value must contain ${part}`;
978
- }
1064
+ operation: "contains"
979
1065
  });
980
1066
 
981
1067
  /**
@@ -1130,7 +1216,7 @@ const dateBefore = createRule({
1130
1216
  * })
1131
1217
  * ```
1132
1218
  *
1133
- * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#datebetweeen Documentation}
1219
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#datebetween Documentation}
1134
1220
  */
1135
1221
  const dateBetween = createRule({
1136
1222
  type: "dateBetween",
@@ -1188,7 +1274,7 @@ const email = createRule({
1188
1274
  if (isEmpty(value)) return true;
1189
1275
  return matchRegex(value, EMAIL_REGEX);
1190
1276
  },
1191
- message: "The value must be an valid email address"
1277
+ message: "The value must be a valid email address"
1192
1278
  });
1193
1279
 
1194
1280
  /**
@@ -1230,15 +1316,9 @@ const emoji = createRule({
1230
1316
  *
1231
1317
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#endswith Documentation}
1232
1318
  */
1233
- const endsWith = createRule({
1319
+ const endsWith = createStringOperationRule({
1234
1320
  type: "endsWith",
1235
- validator(value, part) {
1236
- if (isFilled(value) && isFilled(part) && isString(value) && isString(part)) return value.endsWith(part);
1237
- return true;
1238
- },
1239
- message({ $params: [part] }) {
1240
- return `The value must end with ${part}`;
1241
- }
1321
+ operation: "endsWith"
1242
1322
  });
1243
1323
 
1244
1324
  /**
@@ -1318,7 +1398,7 @@ const exactLength = createRule({
1318
1398
  return true;
1319
1399
  },
1320
1400
  message: ({ $params: [count] }) => {
1321
- return `The value should be exactly ${count} characters long`;
1401
+ return `The value must be exactly ${count} characters long`;
1322
1402
  }
1323
1403
  });
1324
1404
 
@@ -1502,7 +1582,7 @@ const url = createRule({
1502
1582
  return false;
1503
1583
  }
1504
1584
  },
1505
- message: "The value is not a valid URL address"
1585
+ message: "The value must be a valid URL"
1506
1586
  });
1507
1587
 
1508
1588
  /**
@@ -1632,7 +1712,7 @@ const lowercase = createRule({
1632
1712
  if (isEmpty(value)) return true;
1633
1713
  return matchRegex(value, LOWERCASE_REGEX);
1634
1714
  },
1635
- message: "The value is not a valid lowercase string"
1715
+ message: "The value must be lowercase"
1636
1716
  });
1637
1717
 
1638
1718
  /**
@@ -1728,22 +1808,9 @@ const maxFileSize = createRule({
1728
1808
  *
1729
1809
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#maxlength Documentation}
1730
1810
  */
1731
- const maxLength = createRule({
1811
+ const maxLength = createLengthRule({
1732
1812
  type: "maxLength",
1733
- validator: (value, max, options) => {
1734
- const { allowEqual = true } = options ?? {};
1735
- if (isFilled(value, false) && isFilled(max)) {
1736
- if (isNumber(max)) if (allowEqual) return getSize(value) <= max;
1737
- else return getSize(value) < max;
1738
- console.warn(`[maxLength] Value or parameter isn't a number, got value: ${value}, parameter: ${max}`);
1739
- return true;
1740
- }
1741
- return true;
1742
- },
1743
- message: ({ $value, $params: [count] }) => {
1744
- if (Array.isArray($value)) return `This list should have maximum ${count} items`;
1745
- return `The value length should not exceed ${count}`;
1746
- }
1813
+ direction: "max"
1747
1814
  });
1748
1815
 
1749
1816
  /**
@@ -1772,23 +1839,9 @@ const maxLength = createRule({
1772
1839
  *
1773
1840
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#maxvalue Documentation}
1774
1841
  */
1775
- const maxValue = createRule({
1842
+ const maxValue = createValueComparisonRule({
1776
1843
  type: "maxValue",
1777
- validator: (value, max, options) => {
1778
- const { allowEqual = true } = options ?? {};
1779
- if (isFilled(value) && isFilled(max)) {
1780
- if (!isNaN(toNumber(value)) && !isNaN(toNumber(max))) if (allowEqual) return toNumber(value) <= toNumber(max);
1781
- else return toNumber(value) < toNumber(max);
1782
- console.warn(`[maxValue] Value or parameter isn't a number, got value: ${value}, parameter: ${max}`);
1783
- return true;
1784
- }
1785
- return true;
1786
- },
1787
- message: ({ $params: [max, options] }) => {
1788
- const { allowEqual = true } = options ?? {};
1789
- if (allowEqual) return `The value must be less than or equal to ${max}`;
1790
- else return `The value must be less than ${max}`;
1791
- }
1844
+ direction: "max"
1792
1845
  });
1793
1846
 
1794
1847
  /**
@@ -1852,22 +1905,9 @@ const minFileSize = createRule({
1852
1905
  *
1853
1906
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#minlength Documentation}
1854
1907
  */
1855
- const minLength = createRule({
1908
+ const minLength = createLengthRule({
1856
1909
  type: "minLength",
1857
- validator: (value, min, options) => {
1858
- const { allowEqual = true } = options ?? {};
1859
- if (isFilled(value, false) && isFilled(min)) {
1860
- if (isNumber(min)) if (allowEqual) return getSize(value) >= min;
1861
- else return getSize(value) > min;
1862
- console.warn(`[minLength] Parameter isn't a number, got parameter: ${min}`);
1863
- return true;
1864
- }
1865
- return true;
1866
- },
1867
- message: ({ $value, $params: [min] }) => {
1868
- if (Array.isArray($value)) return `The list should have at least ${min} items`;
1869
- return `The value length should be at least ${min}`;
1870
- }
1910
+ direction: "min"
1871
1911
  });
1872
1912
 
1873
1913
  /**
@@ -1896,23 +1936,9 @@ const minLength = createRule({
1896
1936
  *
1897
1937
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#minvalue Documentation}
1898
1938
  */
1899
- const minValue = createRule({
1939
+ const minValue = createValueComparisonRule({
1900
1940
  type: "minValue",
1901
- validator: (value, min, options) => {
1902
- const { allowEqual = true } = options ?? {};
1903
- if (isFilled(value) && isFilled(min)) {
1904
- if (!isNaN(toNumber(value)) && !isNaN(toNumber(min))) if (allowEqual) return toNumber(value) >= toNumber(min);
1905
- else return toNumber(value) > toNumber(min);
1906
- console.warn(`[minValue] Value or parameter isn't a number, got value: ${value}, parameter: ${min}`);
1907
- return true;
1908
- }
1909
- return true;
1910
- },
1911
- message: ({ $params: [min, options] }) => {
1912
- const { allowEqual = true } = options ?? {};
1913
- if (allowEqual) return `The value must be greater than or equal to ${min}`;
1914
- else return `The value must be greater than ${min}`;
1915
- }
1941
+ direction: "min"
1916
1942
  });
1917
1943
 
1918
1944
  function getValidEnumValues(obj) {
@@ -1945,7 +1971,7 @@ function nativeEnum(enumLike) {
1945
1971
  return withMessage(withParams((value, enumLike$1) => {
1946
1972
  if (isFilled(value) && !isEmpty(enumLike$1)) return getValidEnumValues(enumLike$1).includes(value);
1947
1973
  return true;
1948
- }, [computed(() => toValue(enumLike))]), ({ $params: [enumLike$1] }) => `The value should be one of those options: ${Object.values(enumLike$1).join(", ")}.`);
1974
+ }, [computed(() => toValue(enumLike))]), ({ $params: [enumLike$1] }) => `The value must be one of the following: ${Object.values(enumLike$1).join(", ")}`);
1949
1975
  }
1950
1976
 
1951
1977
  /**
@@ -2023,7 +2049,7 @@ const oneOf = createRule({
2023
2049
  if (isFilled(value) && isFilled(options, false)) return options.includes(value);
2024
2050
  return true;
2025
2051
  },
2026
- message: ({ $params: [options] }) => `The value should be one of those options: ${options.join(", ")}.`
2052
+ message: ({ $params: [options] }) => `The value must be one of the following: ${options.join(", ")}`
2027
2053
  });
2028
2054
 
2029
2055
  /**
@@ -2052,7 +2078,7 @@ const regex = createRule({
2052
2078
  if (isFilled(value)) return matchRegex(value, ...Array.isArray(regexp) ? regexp : [regexp]);
2053
2079
  return true;
2054
2080
  },
2055
- message: "The value does not match the required pattern"
2081
+ message: "The value must match the required pattern"
2056
2082
  });
2057
2083
 
2058
2084
  /**
@@ -2200,15 +2226,9 @@ const sameAs = createRule({
2200
2226
  *
2201
2227
  * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#startswith Documentation}
2202
2228
  */
2203
- const startsWith = createRule({
2229
+ const startsWith = createStringOperationRule({
2204
2230
  type: "startsWith",
2205
- validator(value, part) {
2206
- if (isFilled(value) && isFilled(part) && isString(value) && isString(part)) return value.startsWith(part);
2207
- return true;
2208
- },
2209
- message({ $params: [part] }) {
2210
- return `The value must start with ${part}`;
2211
- }
2231
+ operation: "startsWith"
2212
2232
  });
2213
2233
 
2214
2234
  /**
@@ -2283,7 +2303,7 @@ const uppercase = createRule({
2283
2303
  if (isEmpty(value)) return true;
2284
2304
  return matchRegex(value, UPPERCASE_REGEX);
2285
2305
  },
2286
- message: "The value is not a valid uppercase string"
2306
+ message: "The value must be uppercase"
2287
2307
  });
2288
2308
 
2289
2309
  export { alpha, alphaNum, and, applyIf, assignIf, between, boolean, checked, contains, date, dateAfter, dateBefore, dateBetween, decimal, email, emoji, endsWith, exactDigits, exactLength, exactValue, file, fileType, getSize, hexadecimal, hostname, httpUrl, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, lowercase, macAddress, matchRegex, maxFileSize, maxLength, maxValue, minFileSize, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, uppercase, url, withAsync, withMessage, withParams, withTooltip };
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @regle/rules v1.17.3
2
+ * @regle/rules v1.17.4
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
6
6
 
7
- import{InternalRuleType as e,createRule as t,unwrapRuleParameters as n}from"@regle/core";import{computed as r,toValue as i,unref as a}from"vue";function o(n,r){let i,a,o,s,c=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_async:c}=n;let l=t({type:i,validator:a,active:o,message:r,async:c}),u=[...s??[]];if(l._params=u,l._message_patched=!0,typeof l==`function`){if(s!=null){let e=l(...u);return e._message_patched=!0,e}return l}else return l}function s(n,r){let i,a,o,s,c,l=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_message:c,_async:l}=n;let u=t({type:i,validator:a,active:o,message:c,tooltip:r,async:l}),d=[...s??[]];if(u._params=d,u._tooltip_patched=!0,typeof u==`function`){let e=u(...d);return u._tooltip_patched=!0,e}else return u}function c(n,r){let i,a,o=[],s=``;typeof n==`function`?(a=async(e,...t)=>n(e,...t),o=[r]):({_type:i,_message:s}=n,o=o=n._params?.concat(r),a=async(...e)=>n.validator(e));let c=t({type:i??e.Async,validator:a,message:s,async:!0});return c._params=c._params?.concat(o),c(...r??[])}function l(n,r){let i,a,o=[],s=``;typeof n==`function`?(e.Inline,a=(e,...t)=>n(e,...t),o=[r]):({_type:i,validator:a,_message:s}=n,o=o=n._params?.concat(r));let c=t({type:e.Inline,validator:a,message:s});return c._params=c._params?.concat(o),c(...r)}function u(e){return e?.constructor?.name==`File`}function d(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):u(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function f(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function ee(e){return(f(e)||typeof e==`function`)&&`_validator`in e}function p(r,i){let a,o,s=[],c=``,l=!1;typeof i==`function`&&!(`_validator`in i)?(a=e.Inline,o=i,s=[r]):ee(i)&&({_type:a,validator:o,_message:c,_async:l,_params:s}=i,s=(s??[])?.concat([r]));function u(e,...t){let[i]=n([r]);return i?o(e,...t):!0}function d(){let[e]=n([r]);return e}let f=t({type:a,validator:u,active:d,message:c,async:l}),p=[...s??[]];return f._params=p,typeof f==`function`?f(...p):f}function m(e){if(d(e))return!1;let t=null;if(e instanceof Date)t=e;else if(typeof e==`string`){let n=new Date(e);if(n.toString()===`Invalid Date`)return!1;t=n}return!!t}function h(e){let t=Object.prototype.toString.call(e);return e==null?new Date(NaN):e instanceof Date||typeof e==`object`&&t===`[object Date]`?new Date(e.getTime()):typeof e==`number`||t===`[object Number]`||typeof e==`string`||t===`[object String]`?new Date(e):new Date(NaN)}function g(e){return e===void 0?`0 bytes`:e<1024?`${e} bytes`:e<1024*1024?`${(e/1024).toFixed(2)} kb`:e<1024*1024*1024?`${(e/1024/1024).toFixed(2)} mb`:`${(e/1024/1024/1024).toFixed(2)} gb`}function _(e,t=!0){return!d(typeof e==`string`?e.trim():e,t)}function v(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function y(e,...t){if(d(e))return!0;let n=typeof e==`number`?e.toString():e;return t.every(e=>(e.lastIndex=0,e.test(n)))}function b(e){let t=a(e);return Array.isArray(t)?t.length:typeof t==`object`?Object.keys(t).length:typeof t==`number`?isNaN(t)?0:t:String(t).length}function x(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function S(e){return e==null?!1:typeof e==`string`}function C(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e?.some(e=>typeof e!=`boolean`)?{$valid:e.every(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.every(e=>!!e)}let o;o=e.length?n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)):e=>!1;let s=t({type:`and`,validator:o,message:`The value does not match all of the provided validators`}),c=[...r??[]];return s._params=c,typeof s==`function`?s(...c):s}function w(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>typeof e==`function`?null:e._params).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e.some(e=>typeof e!=`boolean`)?{$valid:e.some(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.some(e=>!!e)}let o=t({type:`or`,validator:n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)),message:`The value does not match any of the provided validators`}),s=[...r??[]];return o._params=s,typeof o==`function`?o(...s):o}function te(e,n){let r,i,a,o,s;typeof e==`function`?(i=e,s=e.constructor.name===`AsyncFunction`):({_type:r,validator:i,_params:o}=e,s=e._async),a=s?async(e,...t)=>_(e)?!await i(e,...t):!0:(e,...t)=>_(e)?!i(e,...t):!0;let c=t({type:`not`,validator:a,message:n??`Error`}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function T(e,t,n){return Object.entries(i(t)).map(([t,r])=>typeof r==`function`||f(r)&&`_validator`in r?[t,p(n?e:()=>!i(e),r)]:[t,r])}function ne(e,t,n){return r(()=>{let r=T(e,t,!0),i=n?T(e,n,!1):[];return Object.fromEntries([...r,...i])})}const E=/^https?$/,D=/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,O=/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i;function k(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const A=/^[^A-Z]*$/,j=/^[^a-z]*$/,M=/^[0-9a-fA-F]*$/,N=/^[a-zA-Z]*$/,P=/^[\w.]+$/,F=/^[a-zA-Z0-9]*$/,I=/^[a-zA-Z0-9_]*$/,L=/^[-]?\d*(\.\d+)?$/,R=/^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?: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]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i,z=/(^[0-9]*$)|(^-[0-9]+$)/,B=/^\d*(\.\d+)?$/,V=t({type:`alpha`,validator(e,t){return d(e)?!0:t?.allowSymbols?y(e,P):y(e,N)},message:`The value is not alphabetical`}),H=t({type:`alphaNum`,validator(e,t){return d(e)?!0:t?.allowSymbols?y(e,I):y(e,F)},message:`The value must be alpha-numeric`}),U=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(_(e)&&_(t)&&_(n)){let r=x(e),a=x(t),o=x(n);return v(r)&&v(a)&&v(o)?i?r>=a&&r<=o:r>a&&r<o:!0}return!0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`}),W=t({type:`boolean`,validator:e=>_(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),G=t({type:`checked`,validator:e=>_(e)?e===!0:!0,message:`The field must be checked`}),K=t({type:`contains`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.includes(t):!0},message({$params:[e]}){return`The value must contain ${e}`}}),q=t({type:`date`,validator:e=>_(e)?e instanceof Date:!0,message:`The value must be a native Date`});function J(){return navigator.languages==null?navigator.language:navigator.languages[0]}function Y(e){return e?new Intl.DateTimeFormat(J(),{dateStyle:`short`}).format(new Date(e)):`?`}const X=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)?m(e)&&m(t)?(r?h(e).getTime()>=h(t).getTime():h(e).getTime()>h(t).getTime())?!0:{$valid:!1,error:`date-not-after`}:{$valid:!1,error:`value-or-parameter-not-a-date`}:!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be after ${Y(e)}`}),Z=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)?m(e)&&m(t)?(r?h(e).getTime()<=h(t).getTime():h(e).getTime()<h(t).getTime())?!0:{$valid:!1,error:`date-not-before`}:{$valid:!1,error:`value-or-parameter-not-a-date`}:!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be before ${Y(e)}`}),re=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return m(e)&&m(t)&&m(n)?i?h(e).getTime()>=h(t).getTime()&&h(e).getTime()<=h(n).getTime():h(e).getTime()>h(t).getTime()&&h(e).getTime()<h(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${Y(e)} and ${Y(t)}`}),ie=t({type:`decimal`,validator(e){return d(e)?!0:y(e,L)},message:`The value must be decimal`}),ae=t({type:`email`,validator(e){return d(e)?!0:y(e,R)},message:`The value must be an valid email address`}),oe=t({type:`emoji`,validator(e){return d(e)?!0:k().test(e)},message:`The value should be a valid emoji`}),se=t({type:`endsWith`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.endsWith(t):!0},message({$params:[e]}){return`The value must end with ${e}`}}),ce=t({type:`exactDigits`,validator:(e,t)=>{if(_(e,!1)&&_(t)){if(v(t)){let n=RegExp(`^\\d{${t}}$`);return y(e.toString(),n)}return!0}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),le=t({type:`exactLength`,validator:(e,t)=>_(e,!1)&&_(t)?v(t)?b(e)===t:!1:!0,message:({$params:[e]})=>`The value should be exactly ${e} characters long`}),ue=t({type:`exactValue`,validator:(e,t)=>_(e)&&_(t)&&v(t)&&!isNaN(x(e))?x(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),de=t({type:`file`,validator:e=>_(e)?u(e):!0,message:`The value must be a native File`}),fe=t({type:`fileType`,validator:(e,t)=>_(e)&&u(e)?t.includes(e.type):!0,message({$params:[e]}){return`File type is not allowed. Allowed types are: ${e.map(e=>e.split(`/`)[1]).join(`, `)}.`}}),pe=t({type:`hexadecimal`,validator(e){return d(e)?!0:y(e,M)},message:`The value must be hexadecimal`}),me=t({type:`hostname`,validator(e){return d(e)?!0:y(e,D)},message:`The value is not a valid hostname`}),Q=t({type:`url`,validator(e,t={}){try{if(d(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!D.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:y(e,O)}catch{return!1}},message:`The value is not a valid URL address`}),he=t({type:`httpUrl`,validator(e,t={}){if(d(e))return!0;let{protocol:n=E}=t||{};return Q({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),ge=t({type:`integer`,validator(e){return d(e)?!0:y(e,z)},message:`The value must be an integer`});function _e(e){if(e.length>3||e.length===0||e[0]===`0`&&e!==`0`||!e.match(/^\d+$/))return!1;let t=e|0;return t>=0&&t<=255}const ve=t({type:`ipv4Address`,validator(e){if(d(e))return!0;if(typeof e!=`string`)return!1;let t=e.split(`.`);return t.length===4&&t.every(_e)},message:`The value is not a valid IPv4 address`});function ye(e){return o(l((e,t)=>_(e)&&_(t)?t===e:!0,[r(()=>i(e))]),({$params:[e]})=>`Value should be ${e}.`)}const be=t({type:`lowercase`,validator(e){return d(e)?!0:y(e,A)},message:`The value is not a valid lowercase string`}),xe=t({type:`macAddress`,validator(e,t=`:`){if(d(e))return!0;if(typeof e!=`string`)return!1;let n=typeof t==`string`&&t!==``?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return n!==null&&(n.length===6||n.length===8)&&n.every(Se)},message:`The value is not a valid MAC Address`}),Se=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),Ce=t({type:`maxFileSize`,validator:(e,t)=>_(e)&&u(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${g(t)}) cannot exceed ${g(e)}`}}),we=t({type:`maxLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e,!1)&&_(t)&&v(t)?r?b(e)<=t:b(e)<t:!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`}),Te=t({type:`maxValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)&&!isNaN(x(e))&&!isNaN(x(t))?r?x(e)<=x(t):x(e)<x(t):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}}),Ee=t({type:`minFileSize`,validator:(e,t)=>_(e)&&u(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${g(t)}) must be at least ${g(e)}`}}),De=t({type:`minLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e,!1)&&_(t)&&v(t)?r?b(e)>=t:b(e)>t:!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`The list should have at least ${t} items`:`The value length should be at least ${t}`}),Oe=t({type:`minValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)&&!isNaN(x(e))&&!isNaN(x(t))?r?x(e)>=x(t):x(e)>x(t):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});function ke(e){let t=Object.keys(e).filter(t=>typeof e[e[t]]!=`number`),n={};for(let r of t)n[r]=e[r];return Object.values(n)}function Ae(e){return o(l((e,t)=>_(e)&&!d(t)?ke(t).includes(e):!0,[r(()=>i(e))]),({$params:[e]})=>`The value should be one of those options: ${Object.values(e).join(`, `)}.`)}const je=t({type:`number`,validator:e=>_(e)?v(e):!0,message:`The value must be a native number`}),Me=t({type:`numeric`,validator(e){return d(e)?!0:y(e,B)},message:`The value must be numeric`}),Ne=t({type:`oneOf`,validator(e,t){return _(e)&&_(t,!1)?t.includes(e):!0},message:({$params:[e]})=>`The value should be one of those options: ${e.join(`, `)}.`}),Pe=t({type:`regex`,validator(e,t){return _(e)?y(e,...Array.isArray(t)?t:[t]):!0},message:`The value does not match the required pattern`}),$=t({type:`required`,validator:e=>_(e),message:`This field is required`}),Fe=t({type:`required`,validator(e,t){return t?_(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),Ie=t({type:`required`,validator(e,t){return t?!0:_(e)},message:`This field is required`,active({$params:[e]}){return!e}}),Le=t({type:`sameAs`,validator(e,t,n){return d(e)?!0:e===t},message({$params:[e,t=`other`]}){return`The value must be equal to the ${t} value`}}),Re=t({type:`startsWith`,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?e.startsWith(t):!0},message({$params:[e]}){return`The value must start with ${e}`}}),ze=t({type:`string`,validator:e=>_(e)?typeof e==`string`:!0,message:`The value must be a string`});function Be(){return(()=>!0)}const Ve=t({type:`uppercase`,validator(e){return d(e)?!0:y(e,j)},message:`The value is not a valid uppercase string`});export{V as alpha,H as alphaNum,C as and,p as applyIf,ne as assignIf,U as between,W as boolean,G as checked,K as contains,q as date,X as dateAfter,Z as dateBefore,re as dateBetween,ie as decimal,ae as email,oe as emoji,se as endsWith,ce as exactDigits,le as exactLength,ue as exactValue,de as file,fe as fileType,b as getSize,pe as hexadecimal,me as hostname,he as httpUrl,ge as integer,ve as ipv4Address,m as isDate,d as isEmpty,_ as isFilled,v as isNumber,ye as literal,be as lowercase,xe as macAddress,y as matchRegex,Ce as maxFileSize,we as maxLength,Te as maxValue,Ee as minFileSize,De as minLength,Oe as minValue,Ae as nativeEnum,te as not,je as number,Me as numeric,Ne as oneOf,w as or,Pe as regex,$ as required,Fe as requiredIf,Ie as requiredUnless,Le as sameAs,Re as startsWith,ze as string,h as toDate,x as toNumber,Be as type,Ve as uppercase,Q as url,c as withAsync,o as withMessage,l as withParams,s as withTooltip};
7
+ import{InternalRuleType as e,createRule as t,unwrapRuleParameters as n}from"@regle/core";import{computed as r,toValue as i,unref as a}from"vue";function o(n,r){let i,a,o,s,c=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_async:c}=n;let l=t({type:i,validator:a,active:o,message:r,async:c}),u=[...s??[]];if(l._params=u,l._message_patched=!0,typeof l==`function`){if(s!=null){let e=l(...u);return e._message_patched=!0,e}return l}else return l}function s(n,r){let i,a,o,s,c,l=!1;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_message:c,_async:l}=n;let u=t({type:i,validator:a,active:o,message:c,tooltip:r,async:l}),d=[...s??[]];if(u._params=d,u._tooltip_patched=!0,typeof u==`function`){let e=u(...d);return u._tooltip_patched=!0,e}else return u}function c(n,r){let i,a,o=[],s=``;typeof n==`function`?(a=async(e,...t)=>n(e,...t),o=[r]):({_type:i,_message:s}=n,o=o=n._params?.concat(r),a=async(...e)=>n.validator(e));let c=t({type:i??e.Async,validator:a,message:s,async:!0});return c._params=c._params?.concat(o),c(...r??[])}function l(n,r){let i,a,o=[],s=``;typeof n==`function`?(e.Inline,a=(e,...t)=>n(e,...t),o=[r]):({_type:i,validator:a,_message:s}=n,o=o=n._params?.concat(r));let c=t({type:e.Inline,validator:a,message:s});return c._params=c._params?.concat(o),c(...r)}function u(e){return e?.constructor?.name==`File`}function d(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):u(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function f(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function ee(e){return(f(e)||typeof e==`function`)&&`_validator`in e}function p(r,i){let a,o,s=[],c=``,l=!1;typeof i==`function`&&!(`_validator`in i)?(a=e.Inline,o=i,s=[r]):ee(i)&&({_type:a,validator:o,_message:c,_async:l,_params:s}=i,s=(s??[])?.concat([r]));function u(e,...t){let[i]=n([r]);return i?o(e,...t):!0}function d(){let[e]=n([r]);return e}let f=t({type:a,validator:u,active:d,message:c,async:l}),p=[...s??[]];return f._params=p,typeof f==`function`?f(...p):f}function m(e){if(d(e))return!1;let t=null;if(e instanceof Date)t=e;else if(typeof e==`string`){let n=new Date(e);if(n.toString()===`Invalid Date`)return!1;t=n}return!!t}function h(e){let t=Object.prototype.toString.call(e);return e==null?new Date(NaN):e instanceof Date||typeof e==`object`&&t===`[object Date]`?new Date(e.getTime()):typeof e==`number`||t===`[object Number]`||typeof e==`string`||t===`[object String]`?new Date(e):new Date(NaN)}function g(e){return e===void 0?`0 bytes`:e<1024?`${e} bytes`:e<1024*1024?`${(e/1024).toFixed(2)} kb`:e<1024*1024*1024?`${(e/1024/1024).toFixed(2)} mb`:`${(e/1024/1024/1024).toFixed(2)} gb`}function _(e,t=!0){return!d(typeof e==`string`?e.trim():e,t)}function v(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function y(e,...t){if(d(e))return!0;let n=typeof e==`number`?e.toString():e;return t.every(e=>(e.lastIndex=0,e.test(n)))}function b(e){let t=a(e);return Array.isArray(t)?t.length:typeof t==`object`?Object.keys(t).length:typeof t==`number`?isNaN(t)?0:t:String(t).length}function x(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function S(e){return e==null?!1:typeof e==`string`}function C({type:e,direction:n}){let r=(e,t,r)=>n===`min`?r?e>=t:e>t:r?e<=t:e<t,i=(e,t)=>n===`min`?t?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`:t?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`;return t({type:e,validator:(e,t,n)=>{let{allowEqual:i=!0}=n??{};return _(e)&&_(t)&&!isNaN(x(e))&&!isNaN(x(t))?r(x(e),x(t),i):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return i(e,n)}})}function w({type:e,direction:n}){let r=(e,t,r)=>n===`min`?r?e>=t:e>t:r?e<=t:e<t,i=(e,t)=>Array.isArray(e)?n===`min`?`The list must have at least ${t} items`:`The list must have at most ${t} items`:n===`min`?`The value must be at least ${t} characters long`:`The value must be at most ${t} characters long`;return t({type:e,validator:(e,t,n)=>{let{allowEqual:i=!0}=n??{};return _(e,!1)&&_(t)&&v(t)?r(b(e),t,i):!0},message:({$value:e,$params:[t]})=>i(e,t)})}function T({type:e,operation:n}){let r=(e,t)=>{switch(n){case`contains`:return e.includes(t);case`startsWith`:return e.startsWith(t);case`endsWith`:return e.endsWith(t)}},i=e=>{switch(n){case`contains`:return`The value must contain ${e}`;case`startsWith`:return`The value must start with ${e}`;case`endsWith`:return`The value must end with ${e}`}};return t({type:e,validator(e,t){return _(e)&&_(t)&&S(e)&&S(t)?r(e,t):!0},message({$params:[e]}){return i(e)}})}function E(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e?.some(e=>typeof e!=`boolean`)?{$valid:e.every(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.every(e=>!!e)}let o;o=e.length?n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)):e=>!1;let s=t({type:`and`,validator:o,message:`The value does not match all of the provided validators`}),c=[...r??[]];return s._params=c,typeof s==`function`?s(...c):s}function te(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>typeof e==`function`?null:e._params).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e.some(e=>typeof e!=`boolean`)?{$valid:e.some(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.some(e=>!!e)}let o=t({type:`or`,validator:n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)),message:`The value does not match any of the provided validators`}),s=[...r??[]];return o._params=s,typeof o==`function`?o(...s):o}function ne(e,n){let r,i,a,o,s;typeof e==`function`?(i=e,s=e.constructor.name===`AsyncFunction`):({_type:r,validator:i,_params:o}=e,s=e._async),a=s?async(e,...t)=>_(e)?!await i(e,...t):!0:(e,...t)=>_(e)?!i(e,...t):!0;let c=t({type:`not`,validator:a,message:n??`Error`}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function D(e,t,n){return Object.entries(i(t)).map(([t,r])=>typeof r==`function`||f(r)&&`_validator`in r?[t,p(n?e:()=>!i(e),r)]:[t,r])}function re(e,t,n){return r(()=>{let r=D(e,t,!0),i=n?D(e,n,!1):[];return Object.fromEntries([...r,...i])})}const O=/^https?$/,k=/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,A=/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i;function j(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const M=/^[^A-Z]*$/,N=/^[^a-z]*$/,P=/^[0-9a-fA-F]*$/,F=/^[a-zA-Z]*$/,I=/^[\w.]+$/,L=/^[a-zA-Z0-9]*$/,R=/^[a-zA-Z0-9_]*$/,z=/^[-]?\d*(\.\d+)?$/,B=/^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?: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]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i,V=/(^[0-9]*$)|(^-[0-9]+$)/,H=/^\d*(\.\d+)?$/,U=t({type:`alpha`,validator(e,t){return d(e)?!0:t?.allowSymbols?y(e,I):y(e,F)},message:`The value must be alphabetical`}),W=t({type:`alphaNum`,validator(e,t){return d(e)?!0:t?.allowSymbols?y(e,R):y(e,L)},message:`The value must be alpha-numeric`}),G=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(_(e)&&_(t)&&_(n)){let r=x(e),a=x(t),o=x(n);return v(r)&&v(a)&&v(o)?i?r>=a&&r<=o:r>a&&r<o:!0}return!0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`}),K=t({type:`boolean`,validator:e=>_(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),q=t({type:`checked`,validator:e=>_(e)?e===!0:!0,message:`The field must be checked`}),J=T({type:`contains`,operation:`contains`}),Y=t({type:`date`,validator:e=>_(e)?e instanceof Date:!0,message:`The value must be a native Date`});function X(){return navigator.languages==null?navigator.language:navigator.languages[0]}function Z(e){return e?new Intl.DateTimeFormat(X(),{dateStyle:`short`}).format(new Date(e)):`?`}const ie=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)?m(e)&&m(t)?(r?h(e).getTime()>=h(t).getTime():h(e).getTime()>h(t).getTime())?!0:{$valid:!1,error:`date-not-after`}:{$valid:!1,error:`value-or-parameter-not-a-date`}:!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be after ${Z(e)}`}),ae=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return _(e)&&_(t)?m(e)&&m(t)?(r?h(e).getTime()<=h(t).getTime():h(e).getTime()<h(t).getTime())?!0:{$valid:!1,error:`date-not-before`}:{$valid:!1,error:`value-or-parameter-not-a-date`}:!0},message:({$params:[e],error:t})=>t===`value-or-parameter-not-a-date`?`The values must be dates`:`The date must be before ${Z(e)}`}),oe=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return m(e)&&m(t)&&m(n)?i?h(e).getTime()>=h(t).getTime()&&h(e).getTime()<=h(n).getTime():h(e).getTime()>h(t).getTime()&&h(e).getTime()<h(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${Z(e)} and ${Z(t)}`}),se=t({type:`decimal`,validator(e){return d(e)?!0:y(e,z)},message:`The value must be decimal`}),ce=t({type:`email`,validator(e){return d(e)?!0:y(e,B)},message:`The value must be a valid email address`}),le=t({type:`emoji`,validator(e){return d(e)?!0:j().test(e)},message:`The value should be a valid emoji`}),ue=T({type:`endsWith`,operation:`endsWith`}),de=t({type:`exactDigits`,validator:(e,t)=>{if(_(e,!1)&&_(t)){if(v(t)){let n=RegExp(`^\\d{${t}}$`);return y(e.toString(),n)}return!0}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),fe=t({type:`exactLength`,validator:(e,t)=>_(e,!1)&&_(t)?v(t)?b(e)===t:!1:!0,message:({$params:[e]})=>`The value must be exactly ${e} characters long`}),pe=t({type:`exactValue`,validator:(e,t)=>_(e)&&_(t)&&v(t)&&!isNaN(x(e))?x(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),me=t({type:`file`,validator:e=>_(e)?u(e):!0,message:`The value must be a native File`}),he=t({type:`fileType`,validator:(e,t)=>_(e)&&u(e)?t.includes(e.type):!0,message({$params:[e]}){return`File type is not allowed. Allowed types are: ${e.map(e=>e.split(`/`)[1]).join(`, `)}.`}}),ge=t({type:`hexadecimal`,validator(e){return d(e)?!0:y(e,P)},message:`The value must be hexadecimal`}),_e=t({type:`hostname`,validator(e){return d(e)?!0:y(e,k)},message:`The value is not a valid hostname`}),Q=t({type:`url`,validator(e,t={}){try{if(d(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!k.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:y(e,A)}catch{return!1}},message:`The value must be a valid URL`}),ve=t({type:`httpUrl`,validator(e,t={}){if(d(e))return!0;let{protocol:n=O}=t||{};return Q({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),ye=t({type:`integer`,validator(e){return d(e)?!0:y(e,V)},message:`The value must be an integer`});function be(e){if(e.length>3||e.length===0||e[0]===`0`&&e!==`0`||!e.match(/^\d+$/))return!1;let t=e|0;return t>=0&&t<=255}const xe=t({type:`ipv4Address`,validator(e){if(d(e))return!0;if(typeof e!=`string`)return!1;let t=e.split(`.`);return t.length===4&&t.every(be)},message:`The value is not a valid IPv4 address`});function Se(e){return o(l((e,t)=>_(e)&&_(t)?t===e:!0,[r(()=>i(e))]),({$params:[e]})=>`Value should be ${e}.`)}const Ce=t({type:`lowercase`,validator(e){return d(e)?!0:y(e,M)},message:`The value must be lowercase`}),we=t({type:`macAddress`,validator(e,t=`:`){if(d(e))return!0;if(typeof e!=`string`)return!1;let n=typeof t==`string`&&t!==``?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return n!==null&&(n.length===6||n.length===8)&&n.every(Te)},message:`The value is not a valid MAC Address`}),Te=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),Ee=t({type:`maxFileSize`,validator:(e,t)=>_(e)&&u(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${g(t)}) cannot exceed ${g(e)}`}}),De=w({type:`maxLength`,direction:`max`}),Oe=C({type:`maxValue`,direction:`max`}),ke=t({type:`minFileSize`,validator:(e,t)=>_(e)&&u(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${g(t)}) must be at least ${g(e)}`}}),Ae=w({type:`minLength`,direction:`min`}),je=C({type:`minValue`,direction:`min`});function Me(e){let t=Object.keys(e).filter(t=>typeof e[e[t]]!=`number`),n={};for(let r of t)n[r]=e[r];return Object.values(n)}function Ne(e){return o(l((e,t)=>_(e)&&!d(t)?Me(t).includes(e):!0,[r(()=>i(e))]),({$params:[e]})=>`The value must be one of the following: ${Object.values(e).join(`, `)}`)}const Pe=t({type:`number`,validator:e=>_(e)?v(e):!0,message:`The value must be a native number`}),$=t({type:`numeric`,validator(e){return d(e)?!0:y(e,H)},message:`The value must be numeric`}),Fe=t({type:`oneOf`,validator(e,t){return _(e)&&_(t,!1)?t.includes(e):!0},message:({$params:[e]})=>`The value must be one of the following: ${e.join(`, `)}`}),Ie=t({type:`regex`,validator(e,t){return _(e)?y(e,...Array.isArray(t)?t:[t]):!0},message:`The value must match the required pattern`}),Le=t({type:`required`,validator:e=>_(e),message:`This field is required`}),Re=t({type:`required`,validator(e,t){return t?_(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),ze=t({type:`required`,validator(e,t){return t?!0:_(e)},message:`This field is required`,active({$params:[e]}){return!e}}),Be=t({type:`sameAs`,validator(e,t,n){return d(e)?!0:e===t},message({$params:[e,t=`other`]}){return`The value must be equal to the ${t} value`}}),Ve=T({type:`startsWith`,operation:`startsWith`}),He=t({type:`string`,validator:e=>_(e)?typeof e==`string`:!0,message:`The value must be a string`});function Ue(){return(()=>!0)}const We=t({type:`uppercase`,validator(e){return d(e)?!0:y(e,N)},message:`The value must be uppercase`});export{U as alpha,W as alphaNum,E as and,p as applyIf,re as assignIf,G as between,K as boolean,q as checked,J as contains,Y as date,ie as dateAfter,ae as dateBefore,oe as dateBetween,se as decimal,ce as email,le as emoji,ue as endsWith,de as exactDigits,fe as exactLength,pe as exactValue,me as file,he as fileType,b as getSize,ge as hexadecimal,_e as hostname,ve as httpUrl,ye as integer,xe as ipv4Address,m as isDate,d as isEmpty,_ as isFilled,v as isNumber,Se as literal,Ce as lowercase,we as macAddress,y as matchRegex,Ee as maxFileSize,De as maxLength,Oe as maxValue,ke as minFileSize,Ae as minLength,je as minValue,Ne as nativeEnum,ne as not,Pe as number,$ as numeric,Fe as oneOf,te as or,Ie as regex,Le as required,Re as requiredIf,ze as requiredUnless,Be as sameAs,Ve as startsWith,He as string,h as toDate,x as toNumber,Ue as type,We as uppercase,Q as url,c as withAsync,o as withMessage,l as withParams,s as withTooltip};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regle/rules",
3
- "version": "1.17.3",
3
+ "version": "1.17.4",
4
4
  "description": "Collection of rules and helpers for Regle",
5
5
  "homepage": "https://reglejs.dev/",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "type-fest": "5.4.1",
39
- "@regle/core": "1.17.3"
39
+ "@regle/core": "1.17.4"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "22.19.7",