@regle/rules 1.19.0 → 1.19.2
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/regle-rules.d.ts +12 -7
- package/dist/regle-rules.js +6 -3
- package/dist/regle-rules.min.js +2 -2
- package/package.json +2 -2
package/dist/regle-rules.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/rules v1.19.
|
|
2
|
+
* @regle/rules v1.19.2
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -486,6 +486,7 @@ declare function xor<TRules extends [FormRuleDeclaration<any, any>, ...FormRuleD
|
|
|
486
486
|
* @see {@link https://reglejs.dev/core-concepts/rules/rules-operators#not Documentation}
|
|
487
487
|
*/
|
|
488
488
|
declare function not<TType extends string | unknown = unknown, TValue = unknown, TParams extends any[] = [], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = RegleRuleMetadataDefinition, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise<infer M> ? M : TReturn), TAsync extends boolean = (TReturn extends Promise<any> ? true : false)>(rule: RegleRuleDefinition<TType, TValue, TParams, TAsync, TMetadata> | InlineRuleDeclaration<TValue, TParams, TReturn>, message?: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleDefinition<IsUnknown<TType> extends true ? 'not' : `not:${TType & string}`, TValue, TParams, TAsync, TMetadata>;
|
|
489
|
+
type MapRulesToUnsafeRules<TRules extends RegleRuleDecl<any, any>> = { [K in keyof TRules]: TRules[K] extends RegleRuleDefinition<infer TType, infer TValue, infer TParams, infer TAsync, infer TMetadata, infer TInput, infer TFilteredValue, boolean> ? RegleRuleDefinition<TType, TValue, TParams, TAsync, TMetadata, TInput, TFilteredValue, false> : TRules[K] };
|
|
489
490
|
/**
|
|
490
491
|
* The `assignIf` is a shorthand for conditional destructuring assignment.
|
|
491
492
|
* It allows applying **multiple rules** to a field conditionally.
|
|
@@ -508,7 +509,7 @@ declare function not<TType extends string | unknown = unknown, TValue = unknown,
|
|
|
508
509
|
*
|
|
509
510
|
* @see {@link https://reglejs.dev/core-concepts/rules/rules-operators#assignif Documentation}
|
|
510
511
|
*/
|
|
511
|
-
declare function assignIf<TValue extends unknown = any, TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>, TRulesDelc extends RegleRuleDecl<TValue, TCustomRules> = RegleRuleDecl<TValue, TCustomRules>>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rules: MaybeRefOrGetter<TRulesDelc>, otherwiseRules?: MaybeRefOrGetter<TRulesDelc>): TRulesDelc
|
|
512
|
+
declare function assignIf<TValue extends unknown = any, TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>, TRulesDelc extends RegleRuleDecl<TValue, TCustomRules> = RegleRuleDecl<TValue, TCustomRules>>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rules: MaybeRefOrGetter<TRulesDelc>, otherwiseRules?: MaybeRefOrGetter<TRulesDelc>): MapRulesToUnsafeRules<TRulesDelc>;
|
|
512
513
|
type PipeTupleToObject<TArray extends unknown[]> = { [Key in keyof TArray as TArray[Key] extends RegleRuleDefinition<infer TType extends string, any, any> ? `${TType & string}` : `anonymous${Key & (`${number}` | (IsTuple<TArray> extends true ? never : number))}`]: TArray[Key] };
|
|
513
514
|
interface PipeOptions {
|
|
514
515
|
debounce?: number;
|
|
@@ -584,8 +585,8 @@ declare const alpha: RegleRuleWithParamsDefinition<'alpha', string, [options?: C
|
|
|
584
585
|
* @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#alphanum Documentation}
|
|
585
586
|
*/
|
|
586
587
|
declare const alphaNum: RegleRuleWithParamsDefinition<'alphaNum', string | number, [options?: CommonAlphaOptions | undefined], false, boolean, MaybeInput<string>>;
|
|
587
|
-
interface AtLeastOneFn extends RegleRuleWithParamsDefinition<'atLeastOne', Record<string, unknown> | object, [keys?: string[] | undefined], false, boolean, false, Record<string, unknown> | object> {
|
|
588
|
-
<T extends Maybe<Record<string, unknown> | object> = Record<string, unknown>>(keys?: MaybeRefOrGetter<(keyof NoInfer<T> & string)[]>): RegleRuleDefinition<'atLeastOne', T, [keys?: (keyof NoInfer<T> & string)[] | undefined], false, boolean, false, T>;
|
|
588
|
+
interface AtLeastOneFn extends RegleRuleWithParamsDefinition<'atLeastOne', Record<string, unknown> | object, [keys?: readonly string[] | undefined], false, boolean, false, Record<string, unknown> | object> {
|
|
589
|
+
<T extends Maybe<Record<string, unknown> | object> = Record<string, unknown>>(keys?: MaybeRefOrGetter<readonly (keyof NoInfer<T> & string)[] | undefined>): RegleRuleDefinition<'atLeastOne', T, [keys?: readonly (keyof NoInfer<T> & string)[] | undefined], false, boolean, false, T>;
|
|
589
590
|
}
|
|
590
591
|
/**
|
|
591
592
|
* Checks if at least one key is filled in the object.
|
|
@@ -1300,7 +1301,7 @@ type EnumLike = {
|
|
|
1300
1301
|
*
|
|
1301
1302
|
* @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#nativeenum Documentation}
|
|
1302
1303
|
*/
|
|
1303
|
-
declare function nativeEnum<T extends EnumLike>(enumLike: T): RegleRuleDefinition<'nativeEnum',
|
|
1304
|
+
declare function nativeEnum<T extends EnumLike>(enumLike: T): RegleRuleDefinition<'nativeEnum', T[keyof T], [enumLike: T], false, boolean, MaybeInput<T[keyof T]>, string | number>;
|
|
1304
1305
|
/**
|
|
1305
1306
|
* Requires a value to be a native number type.
|
|
1306
1307
|
*
|
|
@@ -1336,10 +1337,14 @@ declare const number: RegleRuleDefinition<'number', unknown, [], false, boolean,
|
|
|
1336
1337
|
* @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#numeric Documentation}
|
|
1337
1338
|
*/
|
|
1338
1339
|
declare const numeric: RegleRuleDefinition<'numeric', string | number, [], false, boolean, MaybeInput<string | number>>;
|
|
1340
|
+
type EnumOneOfLike<TValue extends unknown> = {
|
|
1341
|
+
readonly [k: string]: TValue;
|
|
1342
|
+
};
|
|
1339
1343
|
interface OneOfFn {
|
|
1344
|
+
<TEnum extends EnumOneOfLike<unknown>>(options: TEnum): RegleRuleDefinition<'oneOf', TEnum[keyof TEnum], [options: TEnum[keyof TEnum]], false, boolean, MaybeInput<TEnum[keyof TEnum]>, string | number>;
|
|
1340
1345
|
<const TValues extends NonEmptyTuple<string | number> | NonEmptyTuple<string> | NonEmptyTuple<number>>(options: MaybeReadonly<MaybeRefOrGetter<[...TValues]>>): RegleRuleDefinition<'oneOf', TValues[number], [options: TValues], false, boolean, MaybeInput<TValues[number]>, string | number>;
|
|
1341
1346
|
/** Keep this definition without generics for inference */
|
|
1342
|
-
(options: MaybeReadonly<MaybeRefOrGetter<[...[string | number, ...(string | number)[]]]>>): RegleRuleDefinition<'oneOf', string | number, [options: readonly [string | number, ...(string | number)[]]], false, boolean, MaybeInput<string | number>, string | number>;
|
|
1347
|
+
(options: MaybeReadonly<MaybeRefOrGetter<[...[string | number, ...(string | number)[]]]>> | EnumOneOfLike<unknown>): RegleRuleDefinition<'oneOf', string | number, [options: readonly [string | number, ...(string | number)[]]], false, boolean, MaybeInput<string | number>, string | number>;
|
|
1343
1348
|
}
|
|
1344
1349
|
/**
|
|
1345
1350
|
* Allow only one of the values from a fixed Array of possible entries.
|
|
@@ -1549,4 +1554,4 @@ declare function type<T>(): RegleRuleDefinition<'type', unknown, [], false, bool
|
|
|
1549
1554
|
* @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#uppercase Documentation}
|
|
1550
1555
|
*/
|
|
1551
1556
|
declare const uppercase: RegleRuleDefinition<'uppercase', string, [], false, boolean, unknown, string>;
|
|
1552
|
-
export { EnumLike, UrlOptions, alpha, alphaNum, and, applyIf, assignIf, atLeastOne, 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, pipe, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, uppercase, url, withAsync, withMessage, withParams, withTooltip, xor };
|
|
1557
|
+
export { EnumLike, EnumOneOfLike, UrlOptions, alpha, alphaNum, and, applyIf, assignIf, atLeastOne, 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, pipe, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, uppercase, url, withAsync, withMessage, withParams, withTooltip, xor };
|
package/dist/regle-rules.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/rules v1.19.
|
|
2
|
+
* @regle/rules v1.19.2
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -2201,10 +2201,13 @@ const numeric = createRule({
|
|
|
2201
2201
|
const oneOf = createRule({
|
|
2202
2202
|
type: "oneOf",
|
|
2203
2203
|
validator(value, options) {
|
|
2204
|
-
if (isFilled(value) && isFilled(options, false)) return options.includes(value);
|
|
2204
|
+
if (isFilled(value) && isFilled(options, false)) if (Array.isArray(options)) return options.includes(value);
|
|
2205
|
+
else return Object.values(options).includes(value);
|
|
2205
2206
|
return true;
|
|
2206
2207
|
},
|
|
2207
|
-
message: ({ $params: [options] }) =>
|
|
2208
|
+
message: ({ $params: [options] }) => {
|
|
2209
|
+
return `The value must be one of the following: ${(Array.isArray(options) ? options : Object.values(options)).join(", ")}`;
|
|
2210
|
+
}
|
|
2208
2211
|
});
|
|
2209
2212
|
|
|
2210
2213
|
/**
|
package/dist/regle-rules.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/rules v1.19.
|
|
2
|
+
* @regle/rules v1.19.2
|
|
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{capitalize as r,computed as i,effectScope as a,onScopeDispose as o,ref as s,toValue as c,unref as l}from"vue";function u(e){return e?.constructor?.name==`File`}function d(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):u(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:f(e)?e==null?!0:n?Object.keys(e).length===0:!1:!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 p(e){return(f(e)||typeof e==`function`)&&`_validator`in e}function m(t){let n,r,i=[],a=``,o=!1,s;if(typeof t==`function`&&!(`_validator`in t))n=e.Inline,r=t,o=t.constructor.name===`AsyncFunction`;else if(p(t))({_type:n,validator:r,_message:a,_async:o,_params:i,_active:s}=t);else throw Error(`Cannot extract validator from invalid rule`);return{_type:n,validator:r,_params:i,_message:a,_async:o,_active:s}}function h(e,n){let{_type:r,validator:i,_active:a,_params:o,_async:s}=m(e),c=t({type:r,validator:i,active:a,message:n,async:s}),l=o??[];if(c._params=l,c._message_patched=!0,typeof c==`function`){if(o!=null){let e=c(...l);return e._message_patched=!0,e}return c}else return c}function g(e,n){let{_type:r,validator:i,_active:a,_params:o,_message:s,_async:c}=m(e),l=t({type:r,validator:i,active:a,message:s,tooltip:n,async:c}),u=o??[];if(l._params=u,l._tooltip_patched=!0,typeof l==`function`){let e=l(...u);return l._tooltip_patched=!0,e}else return l}function _(n,r){let i,{_type:a,_params:o,_message:s,_active:c}=m(n);i=typeof n==`function`?async(e,...t)=>n(e,...t):async(...e)=>n.validator(e);let l=(o??[])?.concat(r),u=t({type:a??e.Async,validator:i,message:s,async:!0,active:c});return u._params=l,u(...r??[])}function v(n,r){let i,{_type:a,_params:o,_message:s,_active:c,_async:l}=m(n);i=typeof n==`function`?(e,...t)=>n(e,...t):n.validator;let u=(o??[])?.concat(r),d=t({type:a??e.Inline,validator:i,message:s,active:c,async:l});return d._params=u,d(...r)}function y(e,r,i){let{_type:a,validator:o,_params:s,_message:c,_async:l}=m(r),u=(s??[]).concat(i?.hideParams?[]:[e]);function d(t,...r){let[i]=n([e]);return i?o(t,...r):!0}function f(){let[t]=n([e]);return t}let p=t({type:a,validator:d,active:f,message:c,async:l});return p._params=u,typeof p==`function`?p(...u):p}function b(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 x(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 ee(e,t,{immediate:n=!1,trackDebounceRef:r}={}){let i,a=(...a)=>{r&&(r.value=!0);function o(){r&&(r.value=!1)}return new Promise((r,s)=>{function c(e){r(e),o()}if(clearTimeout(i),i=setTimeout(()=>{if(o(),i=void 0,!n)try{Promise.resolve(e.apply(this,[...a])).then(c).catch(e=>s(e)).finally(o)}catch(e){s(e)}},t),n){o();try{Promise.resolve(e.apply(this,[...a])).then(c).catch(e=>s(e)).finally(o)}catch(e){s(e)}}})};return a.cancel=()=>{clearTimeout(i),i=void 0,r&&(r.value=!1)},a}function S(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 C(e,t=!0,n=!0){return!d(typeof e==`string`?e.trim():e,t,n)}function w(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function T(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 E(e){let t=l(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 D(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function O(e){return e==null?!1:typeof e==`string`}function te(e){return e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async)}function k(e){return e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e)}function A(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,i+e))),e&&(i+=e)}return r}function j(e,t,n){let r=e=>typeof e==`boolean`?!!e:e.$valid;return n===`xor`?t.length>1?t.filter(r).length===1:t.every(r):t[n===`and`?`every`:`some`](r)}function M(e,t,n){return t.some(e=>typeof e!=`boolean`)?{$valid:j(e,t,n),...t.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:j(e,t,n)}function N(e,n){let{mode:r,message:i}=n,a=te(e),o=k(e),s;s=e.length?a?async(t,...n)=>M(t,await Promise.all(A(e,t,...n)),r):(t,...n)=>M(t,A(e,t,...n),r):e=>!1;let c=t({type:r,validator:s,message:i}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function ne(...e){return N(e,{mode:`and`,message:`The value does not match all of the provided validators`})}function re(...e){return N(e,{mode:`or`,message:`The value does not match any of the provided validators`})}function ie(...e){return N(e,{mode:`xor`,message:`The value does not match exactly one of the provided validators`})}function ae(e,n){let i,{_type:a,validator:o,_params:s,_async:c,_active:l}=m(e);i=c?async(e,...t)=>{if(C(e))try{return!await o(e,...t)}catch{return!0}return!0}:(e,...t)=>C(e)?!o(e,...t):!0;let u=t({type:a?`not(${r(a)})`:void 0,validator:i,message:n??`Error`,active:l,async:c}),d=[...s??[]];return u._params=d,typeof u==`function`?u(...d):u}function P(e,t,n){return Object.entries(c(t)).map(([t,r])=>typeof r==`function`||f(r)&&`_validator`in r?[t,y(n?e:()=>!c(e),r)]:[t,r])}function oe(e,t,n){let r=P(e,t,!0),i=n?P(e,n,!1):[];return Object.fromEntries([...r,...i])}function F(e,t,n){return e.run(()=>i(()=>n===0?!0:Array.from(t.value.entries()).slice(0,n).every(([,e])=>e===!0)))}function I({validator:e,index:t,isAsync:n,mappedResults:r,options:i}){return n?ee(async(n,...i)=>{r.value.set(t,!1);let a=await e(n,...i),o=typeof a==`boolean`?a:a?.$valid??!1;return r.value.set(t,o),a},i?.debounce??200):(n,...i)=>{r.value.set(t,!1);let a=e(n,...i);if(a instanceof Promise)return!1;let o=typeof a==`boolean`?a:a?.$valid??!1;return r.value.set(t,o),a}}function L(...n){let r=[],i=s(new Map),c=[],l=n[0],u=Array.isArray(l)?l:n,d=Array.isArray(l)&&f(n[1])?n[1]:void 0;for(let[e,n]of u.entries()){let o=a();c.push(o);let{_type:s,validator:l,_params:u,_message:f,_async:p,_active:h}=m(n),g=t({type:s,validator:I({validator:l,mappedResults:i,index:e,isAsync:p,options:d}),active:h,async:p,message:f});g._params=u;let _;_=typeof g==`function`?g(...u??[]):g;let v=F(o,i,e),b=e>0&&r[e-1]._async,x=y(v,_,{hideParams:!b});r.push(x)}return o(()=>{c.forEach(e=>e.stop()),c=[]}),{...Object.fromEntries(r.map((t,n)=>[t.type&&t.type!==e.Inline?t.type:`anonymous${n}`,t])),$debounce:0}}const R=/^https?$/,z=/^(?=.{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])?)*\.?$/,B=/^(?:(?:(?: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 V(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const H=/^[^A-Z]*$/,U=/^[^a-z]*$/,W=/^[0-9a-fA-F]*$/,G=/^[a-zA-Z]*$/,K=/^[\w.]+$/,q=/^[a-zA-Z0-9]*$/,se=/^[a-zA-Z0-9_]*$/,ce=/^[-]?\d*(\.\d+)?$/,le=/^(?:[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,ue=/(^[0-9]*$)|(^-[0-9]+$)/,de=/^\d*(\.\d+)?$/,fe=t({type:`alpha`,validator(e,t){return d(e)?!0:t?.allowSymbols?T(e,K):T(e,G)},message:`The value must be alphabetical`}),pe=t({type:`alphaNum`,validator(e,t){return d(e)?!0:t?.allowSymbols?T(e,se):T(e,q)},message:`The value must be alpha-numeric`}),me=t({type:`atLeastOne`,validator:(e,t)=>C(e,!0,!1)&&f(e)?t?.length?t.some(t=>C(e[t])):E(e)>0:!0,message:`At least one item is required`}),he=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(C(e)&&C(t)&&C(n)){let r=D(e),a=D(t),o=D(n);return w(r)&&w(a)&&w(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}`}),ge=t({type:`boolean`,validator:e=>C(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),_e=t({type:`checked`,validator:e=>e===!0,message:`The field must be checked`,required:!0});function J({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 C(e)&&C(t)&&O(e)&&O(t)?r(e,t):!0},message({$params:[e]}){return i(e)}})}const ve=J({type:`contains`,operation:`contains`}),ye=t({type:`date`,validator:e=>C(e)?e instanceof Date:!0,message:`The value must be a native Date`});function be(){return navigator.languages==null?navigator.language??`en-US`:navigator.languages[0]}function Y(e){return e?new Intl.DateTimeFormat(be(),{dateStyle:`short`}).format(new Date(e)):`?`}const xe=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return C(e)&&C(t)?b(e)&&b(t)?(r?x(e).getTime()>=x(t).getTime():x(e).getTime()>x(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)}`}),Se=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return C(e)&&C(t)?b(e)&&b(t)?(r?x(e).getTime()<=x(t).getTime():x(e).getTime()<x(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)}`}),Ce=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return b(e)&&b(t)&&b(n)?i?x(e).getTime()>=x(t).getTime()&&x(e).getTime()<=x(n).getTime():x(e).getTime()>x(t).getTime()&&x(e).getTime()<x(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${Y(e)} and ${Y(t)}`}),we=t({type:`decimal`,validator(e){return d(e)?!0:T(e,ce)},message:`The value must be decimal`}),Te=t({type:`email`,validator(e){return d(e)?!0:T(e,le)},message:`The value must be a valid email address`}),Ee=t({type:`emoji`,validator(e){return d(e)?!0:V().test(e)},message:`The value should be a valid emoji`}),De=J({type:`endsWith`,operation:`endsWith`}),Oe=t({type:`exactDigits`,validator:(e,t)=>{if(C(e,!1)&&C(t)){if(w(t)){let n=RegExp(`^\\d{${t}}$`);return T(e.toString(),n)}return!0}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),ke=t({type:`exactLength`,validator:(e,t)=>C(e,!1)&&C(t)?w(t)?E(e)===t:!1:!0,message:({$params:[e]})=>`The value must be exactly ${e} characters long`}),Ae=t({type:`exactValue`,validator:(e,t)=>C(e)&&C(t)&&w(t)&&!isNaN(D(e))?D(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),je=t({type:`file`,validator:e=>C(e)?u(e):!0,message:`The value must be a native File`}),Me=t({type:`fileType`,validator:(e,t)=>C(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(`, `)}.`}}),Ne=t({type:`hexadecimal`,validator(e){return d(e)?!0:T(e,W)},message:`The value must be hexadecimal`}),Pe=t({type:`hostname`,validator(e){return d(e)?!0:T(e,z)},message:`The value is not a valid hostname`}),X=t({type:`url`,validator(e,t={}){try{if(d(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!z.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:T(e,B)}catch{return!1}},message:`The value must be a valid URL`}),Fe=t({type:`httpUrl`,validator(e,t={}){if(d(e))return!0;let{protocol:n=R}=t||{};return X({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),Ie=t({type:`integer`,validator(e){return d(e)?!0:T(e,ue)},message:`The value must be an integer`});function Le(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 Re=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(Le)},message:`The value is not a valid IPv4 address`});function ze(e){return h(v((e,t)=>C(e)&&C(t)?t===e:!0,[i(()=>c(e))]),({$params:[e]})=>`Value should be ${e}.`)}const Be=t({type:`lowercase`,validator(e){return d(e)?!0:T(e,H)},message:`The value must be lowercase`}),Ve=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(He)},message:`The value is not a valid MAC Address`}),He=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),Ue=t({type:`maxFileSize`,validator:(e,t)=>C(e)&&u(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${S(t)}) cannot exceed ${S(e)}`}});function Z({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 C(e,!1)&&C(t)&&w(t)?r(E(e),t,i):!0},message:({$value:e,$params:[t]})=>i(e,t)})}const We=Z({type:`maxLength`,direction:`max`});function Q({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 C(e)&&C(t)&&!isNaN(D(e))&&!isNaN(D(t))?r(D(e),D(t),i):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return i(e,n)}})}const Ge=Q({type:`maxValue`,direction:`max`}),Ke=t({type:`minFileSize`,validator:(e,t)=>C(e)&&u(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${S(t)}) must be at least ${S(e)}`}}),qe=Z({type:`minLength`,direction:`min`}),Je=Q({type:`minValue`,direction:`min`});function $(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 Ye(e){return h(v((e,t)=>C(e)&&!d(t)?$(t).includes(e):!0,[i(()=>c(e))]),({$params:[e]})=>`The value must be one of the following: ${Object.values(e).join(`, `)}`)}const Xe=t({type:`number`,validator:e=>C(e)?w(e):!0,message:`The value must be a native number`}),Ze=t({type:`numeric`,validator(e){return d(e)?!0:T(e,de)},message:`The value must be numeric`}),Qe=t({type:`oneOf`,validator(e,t){return C(e)&&C(t,!1)?t.includes(e):!0},message:({$params:[e]})=>`The value must be one of the following: ${e.join(`, `)}`}),$e=t({type:`regex`,validator(e,t){return C(e)?T(e,...Array.isArray(t)?t:[t]):!0},message:`The value must match the required pattern`}),et=t({type:`required`,validator:e=>C(e,!0,!1),message:`This field is required`,required:!0}),tt=t({type:`required`,validator(e,t){return t?C(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),nt=t({type:`required`,validator(e,t){return t?!0:C(e)},message:`This field is required`,active({$params:[e]}){return!e}}),rt=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`}}),it=J({type:`startsWith`,operation:`startsWith`}),at=t({type:`string`,validator:e=>C(e)?typeof e==`string`:!0,message:`The value must be a string`});function ot(){return(()=>!0)}const st=t({type:`uppercase`,validator(e){return d(e)?!0:T(e,U)},message:`The value must be uppercase`});export{fe as alpha,pe as alphaNum,ne as and,y as applyIf,oe as assignIf,me as atLeastOne,he as between,ge as boolean,_e as checked,ve as contains,ye as date,xe as dateAfter,Se as dateBefore,Ce as dateBetween,we as decimal,Te as email,Ee as emoji,De as endsWith,Oe as exactDigits,ke as exactLength,Ae as exactValue,je as file,Me as fileType,E as getSize,Ne as hexadecimal,Pe as hostname,Fe as httpUrl,Ie as integer,Re as ipv4Address,b as isDate,d as isEmpty,C as isFilled,w as isNumber,ze as literal,Be as lowercase,Ve as macAddress,T as matchRegex,Ue as maxFileSize,We as maxLength,Ge as maxValue,Ke as minFileSize,qe as minLength,Je as minValue,Ye as nativeEnum,ae as not,Xe as number,Ze as numeric,Qe as oneOf,re as or,L as pipe,$e as regex,et as required,tt as requiredIf,nt as requiredUnless,rt as sameAs,it as startsWith,at as string,x as toDate,D as toNumber,ot as type,st as uppercase,X as url,_ as withAsync,h as withMessage,v as withParams,g as withTooltip,ie as xor};
|
|
7
|
+
import{InternalRuleType as e,createRule as t,unwrapRuleParameters as n}from"@regle/core";import{capitalize as r,computed as i,effectScope as a,onScopeDispose as o,ref as s,toValue as c,unref as l}from"vue";function u(e){return e?.constructor?.name==`File`}function d(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):u(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:f(e)?e==null?!0:n?Object.keys(e).length===0:!1:!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 p(e){return(f(e)||typeof e==`function`)&&`_validator`in e}function m(t){let n,r,i=[],a=``,o=!1,s;if(typeof t==`function`&&!(`_validator`in t))n=e.Inline,r=t,o=t.constructor.name===`AsyncFunction`;else if(p(t))({_type:n,validator:r,_message:a,_async:o,_params:i,_active:s}=t);else throw Error(`Cannot extract validator from invalid rule`);return{_type:n,validator:r,_params:i,_message:a,_async:o,_active:s}}function h(e,n){let{_type:r,validator:i,_active:a,_params:o,_async:s}=m(e),c=t({type:r,validator:i,active:a,message:n,async:s}),l=o??[];if(c._params=l,c._message_patched=!0,typeof c==`function`){if(o!=null){let e=c(...l);return e._message_patched=!0,e}return c}else return c}function g(e,n){let{_type:r,validator:i,_active:a,_params:o,_message:s,_async:c}=m(e),l=t({type:r,validator:i,active:a,message:s,tooltip:n,async:c}),u=o??[];if(l._params=u,l._tooltip_patched=!0,typeof l==`function`){let e=l(...u);return l._tooltip_patched=!0,e}else return l}function _(n,r){let i,{_type:a,_params:o,_message:s,_active:c}=m(n);i=typeof n==`function`?async(e,...t)=>n(e,...t):async(...e)=>n.validator(e);let l=(o??[])?.concat(r),u=t({type:a??e.Async,validator:i,message:s,async:!0,active:c});return u._params=l,u(...r??[])}function v(n,r){let i,{_type:a,_params:o,_message:s,_active:c,_async:l}=m(n);i=typeof n==`function`?(e,...t)=>n(e,...t):n.validator;let u=(o??[])?.concat(r),d=t({type:a??e.Inline,validator:i,message:s,active:c,async:l});return d._params=u,d(...r)}function y(e,r,i){let{_type:a,validator:o,_params:s,_message:c,_async:l}=m(r),u=(s??[]).concat(i?.hideParams?[]:[e]);function d(t,...r){let[i]=n([e]);return i?o(t,...r):!0}function f(){let[t]=n([e]);return t}let p=t({type:a,validator:d,active:f,message:c,async:l});return p._params=u,typeof p==`function`?p(...u):p}function b(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 x(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 ee(e,t,{immediate:n=!1,trackDebounceRef:r}={}){let i,a=(...a)=>{r&&(r.value=!0);function o(){r&&(r.value=!1)}return new Promise((r,s)=>{function c(e){r(e),o()}if(clearTimeout(i),i=setTimeout(()=>{if(o(),i=void 0,!n)try{Promise.resolve(e.apply(this,[...a])).then(c).catch(e=>s(e)).finally(o)}catch(e){s(e)}},t),n){o();try{Promise.resolve(e.apply(this,[...a])).then(c).catch(e=>s(e)).finally(o)}catch(e){s(e)}}})};return a.cancel=()=>{clearTimeout(i),i=void 0,r&&(r.value=!1)},a}function S(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 C(e,t=!0,n=!0){return!d(typeof e==`string`?e.trim():e,t,n)}function w(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function T(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 E(e){let t=l(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 D(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function O(e){return e==null?!1:typeof e==`string`}function te(e){return e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async)}function k(e){return e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e)}function A(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,i+e))),e&&(i+=e)}return r}function j(e,t,n){let r=e=>typeof e==`boolean`?!!e:e.$valid;return n===`xor`?t.length>1?t.filter(r).length===1:t.every(r):t[n===`and`?`every`:`some`](r)}function M(e,t,n){return t.some(e=>typeof e!=`boolean`)?{$valid:j(e,t,n),...t.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:j(e,t,n)}function N(e,n){let{mode:r,message:i}=n,a=te(e),o=k(e),s;s=e.length?a?async(t,...n)=>M(t,await Promise.all(A(e,t,...n)),r):(t,...n)=>M(t,A(e,t,...n),r):e=>!1;let c=t({type:r,validator:s,message:i}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function ne(...e){return N(e,{mode:`and`,message:`The value does not match all of the provided validators`})}function re(...e){return N(e,{mode:`or`,message:`The value does not match any of the provided validators`})}function ie(...e){return N(e,{mode:`xor`,message:`The value does not match exactly one of the provided validators`})}function ae(e,n){let i,{_type:a,validator:o,_params:s,_async:c,_active:l}=m(e);i=c?async(e,...t)=>{if(C(e))try{return!await o(e,...t)}catch{return!0}return!0}:(e,...t)=>C(e)?!o(e,...t):!0;let u=t({type:a?`not(${r(a)})`:void 0,validator:i,message:n??`Error`,active:l,async:c}),d=[...s??[]];return u._params=d,typeof u==`function`?u(...d):u}function P(e,t,n){return Object.entries(c(t)).map(([t,r])=>typeof r==`function`||f(r)&&`_validator`in r?[t,y(n?e:()=>!c(e),r)]:[t,r])}function oe(e,t,n){let r=P(e,t,!0),i=n?P(e,n,!1):[];return Object.fromEntries([...r,...i])}function F(e,t,n){return e.run(()=>i(()=>n===0?!0:Array.from(t.value.entries()).slice(0,n).every(([,e])=>e===!0)))}function I({validator:e,index:t,isAsync:n,mappedResults:r,options:i}){return n?ee(async(n,...i)=>{r.value.set(t,!1);let a=await e(n,...i),o=typeof a==`boolean`?a:a?.$valid??!1;return r.value.set(t,o),a},i?.debounce??200):(n,...i)=>{r.value.set(t,!1);let a=e(n,...i);if(a instanceof Promise)return!1;let o=typeof a==`boolean`?a:a?.$valid??!1;return r.value.set(t,o),a}}function L(...n){let r=[],i=s(new Map),c=[],l=n[0],u=Array.isArray(l)?l:n,d=Array.isArray(l)&&f(n[1])?n[1]:void 0;for(let[e,n]of u.entries()){let o=a();c.push(o);let{_type:s,validator:l,_params:u,_message:f,_async:p,_active:h}=m(n),g=t({type:s,validator:I({validator:l,mappedResults:i,index:e,isAsync:p,options:d}),active:h,async:p,message:f});g._params=u;let _;_=typeof g==`function`?g(...u??[]):g;let v=F(o,i,e),b=e>0&&r[e-1]._async,x=y(v,_,{hideParams:!b});r.push(x)}return o(()=>{c.forEach(e=>e.stop()),c=[]}),{...Object.fromEntries(r.map((t,n)=>[t.type&&t.type!==e.Inline?t.type:`anonymous${n}`,t])),$debounce:0}}const R=/^https?$/,z=/^(?=.{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])?)*\.?$/,B=/^(?:(?:(?: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 V(){return RegExp(`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,`u`)}const H=/^[^A-Z]*$/,U=/^[^a-z]*$/,W=/^[0-9a-fA-F]*$/,G=/^[a-zA-Z]*$/,K=/^[\w.]+$/,q=/^[a-zA-Z0-9]*$/,se=/^[a-zA-Z0-9_]*$/,ce=/^[-]?\d*(\.\d+)?$/,le=/^(?:[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,ue=/(^[0-9]*$)|(^-[0-9]+$)/,de=/^\d*(\.\d+)?$/,fe=t({type:`alpha`,validator(e,t){return d(e)?!0:t?.allowSymbols?T(e,K):T(e,G)},message:`The value must be alphabetical`}),pe=t({type:`alphaNum`,validator(e,t){return d(e)?!0:t?.allowSymbols?T(e,se):T(e,q)},message:`The value must be alpha-numeric`}),me=t({type:`atLeastOne`,validator:(e,t)=>C(e,!0,!1)&&f(e)?t?.length?t.some(t=>C(e[t])):E(e)>0:!0,message:`At least one item is required`}),he=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(C(e)&&C(t)&&C(n)){let r=D(e),a=D(t),o=D(n);return w(r)&&w(a)&&w(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}`}),ge=t({type:`boolean`,validator:e=>C(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),_e=t({type:`checked`,validator:e=>e===!0,message:`The field must be checked`,required:!0});function J({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 C(e)&&C(t)&&O(e)&&O(t)?r(e,t):!0},message({$params:[e]}){return i(e)}})}const ve=J({type:`contains`,operation:`contains`}),ye=t({type:`date`,validator:e=>C(e)?e instanceof Date:!0,message:`The value must be a native Date`});function be(){return navigator.languages==null?navigator.language??`en-US`:navigator.languages[0]}function Y(e){return e?new Intl.DateTimeFormat(be(),{dateStyle:`short`}).format(new Date(e)):`?`}const xe=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return C(e)&&C(t)?b(e)&&b(t)?(r?x(e).getTime()>=x(t).getTime():x(e).getTime()>x(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)}`}),Se=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return C(e)&&C(t)?b(e)&&b(t)?(r?x(e).getTime()<=x(t).getTime():x(e).getTime()<x(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)}`}),Ce=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return b(e)&&b(t)&&b(n)?i?x(e).getTime()>=x(t).getTime()&&x(e).getTime()<=x(n).getTime():x(e).getTime()>x(t).getTime()&&x(e).getTime()<x(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${Y(e)} and ${Y(t)}`}),we=t({type:`decimal`,validator(e){return d(e)?!0:T(e,ce)},message:`The value must be decimal`}),Te=t({type:`email`,validator(e){return d(e)?!0:T(e,le)},message:`The value must be a valid email address`}),Ee=t({type:`emoji`,validator(e){return d(e)?!0:V().test(e)},message:`The value should be a valid emoji`}),De=J({type:`endsWith`,operation:`endsWith`}),Oe=t({type:`exactDigits`,validator:(e,t)=>{if(C(e,!1)&&C(t)){if(w(t)){let n=RegExp(`^\\d{${t}}$`);return T(e.toString(),n)}return!0}return!0},message:({$params:[e]})=>`The value should have exactly ${e} digits`}),ke=t({type:`exactLength`,validator:(e,t)=>C(e,!1)&&C(t)?w(t)?E(e)===t:!1:!0,message:({$params:[e]})=>`The value must be exactly ${e} characters long`}),Ae=t({type:`exactValue`,validator:(e,t)=>C(e)&&C(t)&&w(t)&&!isNaN(D(e))?D(e)===t:!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),je=t({type:`file`,validator:e=>C(e)?u(e):!0,message:`The value must be a native File`}),Me=t({type:`fileType`,validator:(e,t)=>C(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(`, `)}.`}}),Ne=t({type:`hexadecimal`,validator(e){return d(e)?!0:T(e,W)},message:`The value must be hexadecimal`}),Pe=t({type:`hostname`,validator(e){return d(e)?!0:T(e,z)},message:`The value is not a valid hostname`}),X=t({type:`url`,validator(e,t={}){try{if(d(e))return!0;let{protocol:n}=t||{},r=new URL(e);return!z.test(r.hostname)||n&&!n.test(r.protocol.endsWith(`:`)?r.protocol.slice(0,-1):r.protocol)?!1:T(e,B)}catch{return!1}},message:`The value must be a valid URL`}),Fe=t({type:`httpUrl`,validator(e,t={}){if(d(e))return!0;let{protocol:n=R}=t||{};return X({protocol:n}).exec(e)},message:`The value is not a valid http URL address`}),Ie=t({type:`integer`,validator(e){return d(e)?!0:T(e,ue)},message:`The value must be an integer`});function Le(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 Re=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(Le)},message:`The value is not a valid IPv4 address`});function ze(e){return h(v((e,t)=>C(e)&&C(t)?t===e:!0,[i(()=>c(e))]),({$params:[e]})=>`Value should be ${e}.`)}const Be=t({type:`lowercase`,validator(e){return d(e)?!0:T(e,H)},message:`The value must be lowercase`}),Ve=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(He)},message:`The value is not a valid MAC Address`}),He=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),Ue=t({type:`maxFileSize`,validator:(e,t)=>C(e)&&u(e)?{$valid:e.size<=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${S(t)}) cannot exceed ${S(e)}`}});function Z({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 C(e,!1)&&C(t)&&w(t)?r(E(e),t,i):!0},message:({$value:e,$params:[t]})=>i(e,t)})}const We=Z({type:`maxLength`,direction:`max`});function Q({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 C(e)&&C(t)&&!isNaN(D(e))&&!isNaN(D(t))?r(D(e),D(t),i):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return i(e,n)}})}const Ge=Q({type:`maxValue`,direction:`max`}),Ke=t({type:`minFileSize`,validator:(e,t)=>C(e)&&u(e)?{$valid:e.size>=t,fileSize:e.size}:!0,message({$params:[e],fileSize:t}){return`File size (${S(t)}) must be at least ${S(e)}`}}),qe=Z({type:`minLength`,direction:`min`}),Je=Q({type:`minValue`,direction:`min`});function $(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 Ye(e){return h(v((e,t)=>C(e)&&!d(t)?$(t).includes(e):!0,[i(()=>c(e))]),({$params:[e]})=>`The value must be one of the following: ${Object.values(e).join(`, `)}`)}const Xe=t({type:`number`,validator:e=>C(e)?w(e):!0,message:`The value must be a native number`}),Ze=t({type:`numeric`,validator(e){return d(e)?!0:T(e,de)},message:`The value must be numeric`}),Qe=t({type:`oneOf`,validator(e,t){return C(e)&&C(t,!1)?Array.isArray(t)?t.includes(e):Object.values(t).includes(e):!0},message:({$params:[e]})=>`The value must be one of the following: ${(Array.isArray(e)?e:Object.values(e)).join(`, `)}`}),$e=t({type:`regex`,validator(e,t){return C(e)?T(e,...Array.isArray(t)?t:[t]):!0},message:`The value must match the required pattern`}),et=t({type:`required`,validator:e=>C(e,!0,!1),message:`This field is required`,required:!0}),tt=t({type:`required`,validator(e,t){return t?C(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),nt=t({type:`required`,validator(e,t){return t?!0:C(e)},message:`This field is required`,active({$params:[e]}){return!e}}),rt=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`}}),it=J({type:`startsWith`,operation:`startsWith`}),at=t({type:`string`,validator:e=>C(e)?typeof e==`string`:!0,message:`The value must be a string`});function ot(){return(()=>!0)}const st=t({type:`uppercase`,validator(e){return d(e)?!0:T(e,U)},message:`The value must be uppercase`});export{fe as alpha,pe as alphaNum,ne as and,y as applyIf,oe as assignIf,me as atLeastOne,he as between,ge as boolean,_e as checked,ve as contains,ye as date,xe as dateAfter,Se as dateBefore,Ce as dateBetween,we as decimal,Te as email,Ee as emoji,De as endsWith,Oe as exactDigits,ke as exactLength,Ae as exactValue,je as file,Me as fileType,E as getSize,Ne as hexadecimal,Pe as hostname,Fe as httpUrl,Ie as integer,Re as ipv4Address,b as isDate,d as isEmpty,C as isFilled,w as isNumber,ze as literal,Be as lowercase,Ve as macAddress,T as matchRegex,Ue as maxFileSize,We as maxLength,Ge as maxValue,Ke as minFileSize,qe as minLength,Je as minValue,Ye as nativeEnum,ae as not,Xe as number,Ze as numeric,Qe as oneOf,re as or,L as pipe,$e as regex,et as required,tt as requiredIf,nt as requiredUnless,rt as sameAs,it as startsWith,at as string,x as toDate,D as toNumber,ot as type,st as uppercase,X as url,_ as withAsync,h as withMessage,v as withParams,g as withTooltip,ie as xor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/rules",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.2",
|
|
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.4",
|
|
39
|
-
"@regle/core": "1.19.
|
|
39
|
+
"@regle/core": "1.19.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "24.10.13",
|