@regle/rules 1.1.0-beta.2 → 1.1.0-beta.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.
- package/dist/regle-rules.d.ts +14 -47
- package/dist/regle-rules.min.mjs +1 -1
- package/dist/regle-rules.mjs +37 -29
- package/package.json +9 -19
- package/dist/regle-rules.cjs +0 -1022
- package/dist/regle-rules.d.cts +0 -462
- package/dist/regle-rules.min.cjs +0 -1
- package/index.cjs +0 -7
- package/index.js +0 -7
package/dist/regle-rules.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { Ref, MaybeRefOrGetter, MaybeRef } from 'vue';
|
|
|
20
20
|
*/
|
|
21
21
|
declare function withMessage<TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition = TReturn extends Promise<infer M> ? M : TReturn, TAsync extends boolean = TReturn extends Promise<any> ? true : false>(rule: RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetadata>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetadata>;
|
|
22
22
|
declare function withMessage<TValue extends any, TParams extends unknown[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition = TReturn extends Promise<infer M> ? M : TReturn, TAsync extends boolean = TReturn extends Promise<any> ? true : false>(rule: RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
|
|
23
|
-
declare function withMessage<TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>,
|
|
23
|
+
declare function withMessage<TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TAsync extends boolean = TReturn extends Promise<any> ? true : false>(rule: InlineRuleDeclaration<TValue, TParams, TReturn>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TReturn extends Promise<infer M> ? M : TReturn>, string | string[]>): RegleRuleDefinition<TValue, TParams, TAsync, TReturn extends Promise<infer M> ? M : TReturn>;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* The withTooltip wrapper allows you to display additional messages for your field that aren’t necessarily errors. Tooltips are aggregated and accessible via $fields.xxx.$tooltips .
|
|
@@ -117,7 +117,7 @@ declare global {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
declare const emptyObjectSymbol
|
|
120
|
+
declare const emptyObjectSymbol: unique symbol;
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
123
|
Represents a strictly empty plain object, the `{}` value.
|
|
@@ -145,7 +145,7 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
|
|
|
145
145
|
|
|
146
146
|
@category Object
|
|
147
147
|
*/
|
|
148
|
-
type EmptyObject
|
|
148
|
+
type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
149
149
|
|
|
150
150
|
/**
|
|
151
151
|
* This is the inverse of isFilled. It will check if the value is in any way empty (including arrays and objects)
|
|
@@ -155,7 +155,7 @@ type EmptyObject$1 = {[emptyObjectSymbol$1]?: never};
|
|
|
155
155
|
* @param value - the target value
|
|
156
156
|
* @param [considerEmptyArrayInvalid=true] - will return false if set to `false`. (default: `true`)
|
|
157
157
|
*/
|
|
158
|
-
declare function isEmpty(value: unknown, considerEmptyArrayInvalid?: boolean): value is null | undefined | [] | EmptyObject
|
|
158
|
+
declare function isEmpty(value: unknown, considerEmptyArrayInvalid?: boolean): value is null | undefined | [] | EmptyObject;
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
161
|
* This is a useful helper that can check if the provided value is a Date, it is used internally for date rules. This can also check strings.
|
|
@@ -167,43 +167,6 @@ declare function isDate(value: unknown): value is Date;
|
|
|
167
167
|
*/
|
|
168
168
|
declare function toDate(argument: Maybe<Date | number | string>): Date;
|
|
169
169
|
|
|
170
|
-
declare global {
|
|
171
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
172
|
-
interface SymbolConstructor {
|
|
173
|
-
readonly observable: symbol;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
declare const emptyObjectSymbol: unique symbol;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
Represents a strictly empty plain object, the `{}` value.
|
|
181
|
-
|
|
182
|
-
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
|
183
|
-
|
|
184
|
-
@example
|
|
185
|
-
```
|
|
186
|
-
import type {EmptyObject} from 'type-fest';
|
|
187
|
-
|
|
188
|
-
// The following illustrates the problem with `{}`.
|
|
189
|
-
const foo1: {} = {}; // Pass
|
|
190
|
-
const foo2: {} = []; // Pass
|
|
191
|
-
const foo3: {} = 42; // Pass
|
|
192
|
-
const foo4: {} = {a: 1}; // Pass
|
|
193
|
-
|
|
194
|
-
// With `EmptyObject` only the first case is valid.
|
|
195
|
-
const bar1: EmptyObject = {}; // Pass
|
|
196
|
-
const bar2: EmptyObject = 42; // Fail
|
|
197
|
-
const bar3: EmptyObject = []; // Fail
|
|
198
|
-
const bar4: EmptyObject = {a: 1}; // Fail
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
|
202
|
-
|
|
203
|
-
@category Object
|
|
204
|
-
*/
|
|
205
|
-
type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
206
|
-
|
|
207
170
|
type ExtractValueFromRules<T extends any[]> = T extends [infer F, ...infer R] ? F extends RegleRuleDefinition<infer V, any, any, any> ? [V, ...ExtractValueFromRules<R>] : F extends InlineRuleDeclaration<infer V, any> ? [V, ...ExtractValueFromRules<R>] : [F, ...ExtractValueFromRules<R>] : [];
|
|
208
171
|
type ExtractAsyncStatesFromRules<T extends any[]> = T extends [infer F, ...infer R] ? F extends RegleRuleDefinition<any, any, infer A, any> ? [A, ...ExtractValueFromRules<R>] : F extends InlineRuleDeclaration<any, any> ? [ReturnType<F> extends Promise<any> ? true : false, ...ExtractValueFromRules<R>] : [F, ...ExtractValueFromRules<R>] : [];
|
|
209
172
|
type ExtractAsync<T extends [...any[]]> = T extends [infer F, ...infer R] ? F extends true ? true : F extends false ? ExtractAsync<R> : false : false;
|
|
@@ -222,12 +185,12 @@ type UnwrapTuples<T extends any[]> = FilterTuple<T> extends [infer U extends any
|
|
|
222
185
|
/**
|
|
223
186
|
* The and operator combines multiple rules and validates successfully only if all provided rules are valid.
|
|
224
187
|
*/
|
|
225
|
-
declare function and<TRules extends FormRuleDeclaration<any, any>[]>(...rules: [...TRules]): RegleRuleDefinition<ExtractValueFromRules<TRules>[number], UnwrapTuples<ExtractParamsFromRules<TRules>>, GuessAsyncFromRules<TRules>, GuessMetadataFromRules<TRules>>;
|
|
188
|
+
declare function and<const TRules extends [FormRuleDeclaration<any, any>, ...FormRuleDeclaration<any, any>[]]>(...rules: [...TRules]): RegleRuleDefinition<ExtractValueFromRules<TRules>[number], UnwrapTuples<ExtractParamsFromRules<TRules>>, GuessAsyncFromRules<TRules>, GuessMetadataFromRules<TRules>>;
|
|
226
189
|
|
|
227
190
|
/**
|
|
228
191
|
* The or operator validates successfully if at least one of the provided rules is valid.
|
|
229
192
|
*/
|
|
230
|
-
declare function or<TRules extends FormRuleDeclaration<any, any>[]>(...rules: [...TRules]): RegleRuleDefinition<ExtractValueFromRules<TRules>[number], UnwrapTuples<ExtractParamsFromRules<TRules>>, GuessAsyncFromRules<TRules>, GuessMetadataFromRules<TRules>>;
|
|
193
|
+
declare function or<TRules extends [FormRuleDeclaration<any, any>, ...FormRuleDeclaration<any, any>[]]>(...rules: [...TRules]): RegleRuleDefinition<ExtractValueFromRules<TRules>[number], UnwrapTuples<ExtractParamsFromRules<TRules>>, GuessAsyncFromRules<TRules>, GuessMetadataFromRules<TRules>>;
|
|
231
194
|
|
|
232
195
|
/**
|
|
233
196
|
* The not operator passes when the provided rule fails and fails when the rule passes. It can be combined with other rules.
|
|
@@ -259,12 +222,16 @@ declare const requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boo
|
|
|
259
222
|
/**
|
|
260
223
|
* Allows only alphabetic characters.
|
|
261
224
|
* */
|
|
262
|
-
declare const alpha:
|
|
225
|
+
declare const alpha: RegleRuleWithParamsDefinition<string, [
|
|
226
|
+
allowSymbols?: boolean | undefined
|
|
227
|
+
], false, boolean, string>;
|
|
263
228
|
|
|
264
229
|
/**
|
|
265
230
|
* Allows only alphanumeric characters.
|
|
266
231
|
*/
|
|
267
|
-
declare const alphaNum:
|
|
232
|
+
declare const alphaNum: RegleRuleWithParamsDefinition<string | number, [
|
|
233
|
+
allowSymbols?: boolean | undefined
|
|
234
|
+
], false, boolean, string | number>;
|
|
268
235
|
|
|
269
236
|
/**
|
|
270
237
|
* Checks if a number is in specified bounds. min and max are both inclusive.
|
|
@@ -400,7 +367,7 @@ declare const dateBetween: RegleRuleWithParamsDefinition<string | Date, [
|
|
|
400
367
|
/**
|
|
401
368
|
* Validates IPv4 addresses in dotted decimal notation 127.0.0.1.
|
|
402
369
|
*/
|
|
403
|
-
declare const
|
|
370
|
+
declare const ipv4Address: RegleRuleDefinition<string, [], false, boolean, string>;
|
|
404
371
|
|
|
405
372
|
/**
|
|
406
373
|
* Validates MAC addresses. Call as a function to specify a custom separator (e.g., ':' or an empty string for 00ff1122334455).
|
|
@@ -459,4 +426,4 @@ declare function nativeEnum<T extends EnumLike>(enumLike: T): RegleRuleDefinitio
|
|
|
459
426
|
*/
|
|
460
427
|
declare function literal<const TValue extends string | number>(literal: MaybeRefOrGetter<TValue>): RegleRuleDefinition<TValue, [literal: TValue], false, boolean, string | number>;
|
|
461
428
|
|
|
462
|
-
export { type EnumLike, alpha, alphaNum, and, applyIf, between, checked, contains, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, integer,
|
|
429
|
+
export { type EnumLike, alpha, alphaNum, and, applyIf, between, checked, contains, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, nativeEnum, not, numeric, oneOf, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, toDate, toNumber, url, withAsync, withMessage, withParams, withTooltip };
|
package/dist/regle-rules.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref,computed,toValue}from'vue';function h(e,t){let r,n,s,R;typeof e=="function"&&!("_validator"in e)?(r=InternalRuleType.Inline,n=e):{_type:r,validator:n,_active:s,_params:R}=e;let l=createRule({type:r,validator:n,active:s,message:t}),u=[...R??[]];if(l._params=u,l._message_patched=true,typeof l=="function"){let a=l(...u);return a._message_patched=true,a}else return l}function _(e,t){let r,n,s,R,l;typeof e=="function"&&!("_validator"in e)?(r=InternalRuleType.Inline,n=e):{_type:r,validator:n,_active:s,_params:R,_message:l}=e;let u=createRule({type:r,validator:n,active:s,message:l,tooltip:t}),a=[...R??[]];if(u._params=a,u._tooltip_patched=true,typeof u=="function"){let m=u(...a);return u._tooltip_patched=true,m}else return u}function E(e,t){let r,n,s=[],R="";typeof e=="function"?(r=InternalRuleType.Inline,n=async(u,...a)=>e(u,...a),s=[t]):({_type:r,_message:R}=e,s=s=e._params?.concat(t),n=async(...u)=>e.validator(u));let l=createRule({type:InternalRuleType.Async,validator:n,message:R});return l._params=l._params?.concat(s),l(...t??[])}function P(e,t){let r,n,s=[],R="";typeof e=="function"?(r=InternalRuleType.Inline,n=(u,...a)=>e(u,...a),s=[t]):({_type:r,validator:n,_message:R}=e,s=s=e._params?.concat(t));let l=createRule({type:InternalRuleType.Inline,validator:n,message:R});return l._params=l._params?.concat(s),l(...t)}function L(e,t){let r,n,s=[],R="";typeof t=="function"?(r=InternalRuleType.Inline,n=t,s=[e]):({_type:r,validator:n,_message:R}=t,s=t._params?.concat([e]));function l(o,...p){let[b]=unwrapRuleParameters([e]);return b?n(o,...p):true}function u(o){let[p]=unwrapRuleParameters([e]);return p}let a=createRule({type:r,validator:l,active:u,message:R}),m=[...s??[]];return a._params=m,typeof a=="function"?a(...m):a}function f(e,t=true){return e==null?true:e instanceof Date?isNaN(e.getTime()):e.constructor.name=="File"||e.constructor.name=="FileList"?e.size<=0:Array.isArray(e)?t?e.length===0:false:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function x(e){if(f(e))return false;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){let r=new Date(e);if(r.toString()==="Invalid Date")return !1;t=r;}return !!t}catch{return false}}function T(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]"?new Date(e):typeof e=="string"||t==="[object String]"?new Date(e):new Date(NaN)}function i(e,t=true){return !f(typeof e=="string"?e.trim():e,t)}function y(e){return e==null||typeof e!="number"?false:!isNaN(e)}function g(e,...t){if(f(e))return true;let r=typeof e=="number"?e.toString():e;return t.every(n=>(n.lastIndex=0,n.test(r)))}function D(e){let t=unref(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 c(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function q(...e){let t=e.some(a=>typeof a=="function"?a.constructor.name==="AsyncFunction":a._async),r=e.map(a=>{if(typeof a=="function")return null;{let m=a._params;return m?.length?m:[]}}).flat().filter(a=>!!a);function n(a,m,...o){let p=[],b=0;for(let d of a)if(typeof d=="function")p.push(d(m)),b++;else {let M=d._params?.length??0;p.push(d.validator(m,...o.slice(b,M))),M&&(b+=M);}return p}function s(a){return a?.some(o=>typeof o!="boolean")?{$valid:a.every(o=>typeof o=="boolean"?!!o:o.$valid),...a.reduce((o,p)=>{if(typeof p=="boolean")return o;let{$valid:b,...d}=p;return {...o,...d}},{})}:a.every(o=>!!o)}let R;e.length?R=t?async(a,...m)=>{let o=await Promise.all(n(e,a,...m));return s(o)}:(a,...m)=>{let o=n(e,a,...m);return s(o)}:R=a=>false;let l=createRule({type:"and",validator:R,message:"The value does not match all of the provided validators"}),u=[...r??[]];return l._params=u,typeof l=="function"?l(...u):l}function G(...e){let t=e.some(a=>typeof a=="function"?a.constructor.name==="AsyncFunction":a._async),r=e.map(a=>typeof a=="function"?null:a._params).flat().filter(a=>!!a);function n(a,m,...o){let p=[],b=0;for(let d of a)if(typeof d=="function")p.push(d(m)),b++;else {let M=d._params?.length??0;p.push(d.validator(m,...o.slice(b,M))),M&&(b+=M);}return p}function s(a){return a.some(o=>typeof o!="boolean")?{$valid:a.some(o=>typeof o=="boolean"?!!o:o.$valid),...a.reduce((o,p)=>{if(typeof p=="boolean")return o;let{$valid:b,...d}=p;return {...o,...d}},{})}:a.some(o=>!!o)}let l=createRule({type:"or",validator:t?async(a,...m)=>{let o=await Promise.all(n(e,a,...m));return s(o)}:(a,...m)=>{let o=n(e,a,...m);return s(o)},message:"The value does not match any of the provided validators"}),u=[...r??[]];return l._params=u,typeof l=="function"?l(...u):l}function B(e,t){let r,n,s,R,l;typeof e=="function"?(n=e,l=e.constructor.name==="AsyncFunction"):({_type:r,validator:n,_params:R}=e,l=e._async),l?s=async(m,...o)=>i(m)?!await n(m,...o):true:s=(m,...o)=>i(m)?!n(m,...o):true;let u=createRule({type:"not",validator:s,message:t??"Error"}),a=[...R??[]];return u._params=a,typeof u=="function"?u(...a):u}var Jt=createRule({type:"required",validator:e=>i(e),message:"This field is required"});var Yt=createRule({type:"maxLength",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e,false)&&i(t)?y(t)?n?D(e)<=t:D(e)<t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),false):true},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The maximum length allowed is ${t}`});var rr=createRule({type:"required",validator(e,t){return t?i(e):true},message:"This field is required",active({$params:[e]}){return e}});var X=/^[a-zA-Z]*$/,or=createRule({type:"alpha",validator(e){return f(e)?true:g(e,X)},message:"The value is not alphabetical"});var j=/^[a-zA-Z0-9]*$/,mr=createRule({type:"alpha",validator(e){return f(e)?true:g(e,j)},message:"The value must be alpha-numeric"});var yr=createRule({type:"between",validator:(e,t,r,n)=>{let{allowEqual:s=true}=n??{};if(i(e)&&i(t)&&i(r)){let R=c(e),l=c(t),u=c(r);return y(R)&&y(l)&&y(u)?s?R>=l&&R<=u:R>l&&R<u:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${r}`),false)}return true},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var re=/^[-]?\d*(\.\d+)?$/,Tr=createRule({type:"decimal",validator(e){return f(e)?true:g(e,re)},message:"Value must be decimal"});var ae=/^(?:[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,Mr=createRule({type:"email",validator(e){return f(e)?true:g(e,ae)},message:"Value must be an valid email address"});var oe=/(^[0-9]*$)|(^-[0-9]+$)/,Vr=createRule({type:"integer",validator(e){return f(e)?true:g(e,oe)},message:"Value must be an integer"});var vr=createRule({type:"maxValue",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e)&&i(t)?y(t)&&!isNaN(c(e))?n?c(e)<=t:c(e)<t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true},message:({$params:[e,t]})=>{let{allowEqual:r=true}=t??{};return r?`Value must be less than or equal to ${e}`:`Value must be less than ${e}`}});var Nr=createRule({type:"minLength",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e,false)&&i(t)?y(t)?n?D(e)>=t:D(e)>t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),false):true},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have at least ${t} items`:`This field should be at least ${t} characters long`});var Or=createRule({type:"minValue",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e)&&i(t)?y(t)&&!isNaN(c(e))?n?c(e)>=t:c(e)>t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true},message:({$params:[e,t]})=>{let{allowEqual:r=true}=t??{};return r?`Value must be greater than or equal to ${e}`:`Value must be greater than ${e}`}});var qr=createRule({type:"exactValue",validator:(e,t)=>i(e)&&i(t)?y(t)&&!isNaN(c(e))?c(e)===t:(console.warn(`[exactValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true,message:({$params:[e]})=>`The value must be equal to ${e}`});var Br=createRule({type:"exactLength",validator:(e,t)=>i(e,false)&&i(t)?y(t)?D(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),false):true,message:({$params:[e]})=>`This field should be exactly ${e} characters long`});var pe=/^\d*(\.\d+)?$/,Qr=createRule({type:"numeric",validator(e){return f(e)?true:g(e,pe)},message:"This field must be numeric"});var en=createRule({type:"required",validator(e,t){return t?true:i(e)},message:"This field is required",active({$params:[e]}){return !e}});var an=createRule({type:"sameAs",validator(e,t,r="other"){return f(e)?true:e===t},message({$params:[e,t]}){return `Value must be equal to the ${t} value`}});var de=/^(?:(?:(?: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,un=createRule({type:"url",validator(e){return f(e)?true:g(e,de)},message:"The value is not a valid URL address"});function Te(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function w(e){return e?new Intl.DateTimeFormat(Te(),{dateStyle:"short"}).format(new Date(e)):"?"}var gn=createRule({type:"dateAfter",validator:(e,t)=>i(e)&&i(t)?x(e)&&x(t)?T(e).getTime()>T(t).getTime()?true:{$valid:false,error:"date-not-after"}:{$valid:false,error:"value-or-paramater-not-a-date"}:true,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The inputs must be Dates":`The date must be after ${w(e)}`});var bn=createRule({type:"dateBefore",validator:(e,t)=>i(e)&&i(t)?x(e)&&x(t)?T(e).getTime()<T(t).getTime()?true:{$valid:false,error:"date-not-before"}:{$valid:false,error:"value-or-paramater-not-a-date"}:true,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be Dates":`The date must be before ${w(e)}`});var wn=createRule({type:"dateBetween",validator:(e,t,r)=>x(e)&&x(t)&&x(r)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(r).getTime():true,message:({$params:[e,t]})=>`The date must be between ${w(e)} and ${w(t)}`});function he(e){if(e.length>3||e.length===0||e[0]==="0"&&e!=="0"||!e.match(/^\d+$/))return false;let t=+e|0;return t>=0&&t<=255}var Wn=createRule({type:"ipAddress",validator(e){if(f(e))return true;if(typeof e!="string")return false;let t=e.split(".");return t.length===4&&t.every(he)},message:"The value is not a valid IP address"});var _n=createRule({type:"macAddress",validator(e,t=":"){if(f(e))return true;if(typeof e!="string")return false;let r=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return r!==null&&(r.length===6||r.length===8)&&r.every(we)},message:"The value is not a valid MAC Address"}),we=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var kn=createRule({type:"checked",validator:e=>i(e)?e===true:true,message:"This field must be checked"});var Sn=createRule({type:"contains",validator(e,t){return i(e)&&i(t)?e.includes(t):true},message({$params:[e]}){return `Field must contain ${e}`}});var Kn=createRule({type:"startsWith",validator(e,t){return i(e)&&i(t)?e.startsWith(t):true},message({$params:[e]}){return `Field must end with ${e}`}});var Hn=createRule({type:"endsWith",validator(e,t){return i(e)&&i(t)?e.endsWith(t):true},message({$params:[e]}){return `Field must end with ${e}`}});var jn=createRule({type:"regex",validator(e,t){if(i(e)){let r=Array.isArray(t)?t:[t];return g(e,...r)}return true},message:"This field does not match the required pattern"});function na(e){let t=computed(()=>toValue(e));return h(P((n,s)=>i(n)&&i(s,false)?s.includes(n):true,[t]),({$params:[n]})=>`Value should be one of those options: ${n.join(", ")}.`)}function Ee(e){let t=Object.keys(e).filter(n=>typeof e[e[n]]!="number"),r={};for(let n of t)r[n]=e[n];return Object.values(r)}function sa(e){let t=computed(()=>toValue(e));return h(P((n,s)=>i(n)&&!f(s)?Ee(s).includes(n):true,[t]),({$params:[n]})=>`Value should be one of those options: ${Object.values(n).join(", ")}.`)}function Ra(e){let t=computed(()=>toValue(e));return h(P((n,s)=>s===n,[t]),({$params:[n]})=>`Value should be ${n}.`)}export{or as alpha,mr as alphaNum,q as and,L as applyIf,yr as between,kn as checked,Sn as contains,gn as dateAfter,bn as dateBefore,wn as dateBetween,Tr as decimal,Mr as email,Hn as endsWith,Br as exactLength,qr as exactValue,D as getSize,Vr as integer,Wn as ipAddress,x as isDate,f as isEmpty,i as isFilled,y as isNumber,Ra as literal,_n as macAddress,g as matchRegex,Yt as maxLength,vr as maxValue,Nr as minLength,Or as minValue,sa as nativeEnum,B as not,Qr as numeric,na as oneOf,G as or,jn as regex,Jt as required,rr as requiredIf,en as requiredUnless,an as sameAs,Kn as startsWith,T as toDate,c as toNumber,un as url,E as withAsync,h as withMessage,P as withParams,_ as withTooltip};
|
|
1
|
+
import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref,computed,toValue}from'vue';function M(e,t){let r,n,s,R;typeof e=="function"&&!("_validator"in e)?(r=InternalRuleType.Inline,n=e):{_type:r,validator:n,_active:s,_params:R}=e;let l=createRule({type:r,validator:n,active:s,message:t}),u=[...R??[]];if(l._params=u,l._message_patched=true,typeof l=="function"){let a=l(...u);return a._message_patched=true,a}else return l}function _(e,t){let r,n,s,R,l;typeof e=="function"&&!("_validator"in e)?(r=InternalRuleType.Inline,n=e):{_type:r,validator:n,_active:s,_params:R,_message:l}=e;let u=createRule({type:r,validator:n,active:s,message:l,tooltip:t}),a=[...R??[]];if(u._params=a,u._tooltip_patched=true,typeof u=="function"){let m=u(...a);return u._tooltip_patched=true,m}else return u}function E(e,t){let r,n,s=[],R="";typeof e=="function"?(r=InternalRuleType.Inline,n=async(u,...a)=>e(u,...a),s=[t]):({_type:r,_message:R}=e,s=s=e._params?.concat(t),n=async(...u)=>e.validator(u));let l=createRule({type:InternalRuleType.Async,validator:n,message:R});return l._params=l._params?.concat(s),l(...t??[])}function P(e,t){let r,n,s=[],R="";typeof e=="function"?(r=InternalRuleType.Inline,n=(u,...a)=>e(u,...a),s=[t]):({_type:r,validator:n,_message:R}=e,s=s=e._params?.concat(t));let l=createRule({type:InternalRuleType.Inline,validator:n,message:R});return l._params=l._params?.concat(s),l(...t)}function S(e,t){let r,n,s=[],R="";typeof t=="function"?(r=InternalRuleType.Inline,n=t,s=[e]):({_type:r,validator:n,_message:R}=t,s=t._params?.concat([e]));function l(o,...y){let[b]=unwrapRuleParameters([e]);return b?n(o,...y):true}function u(o){let[y]=unwrapRuleParameters([e]);return y}let a=createRule({type:r,validator:l,active:u,message:R}),m=[...s??[]];return a._params=m,typeof a=="function"?a(...m):a}function f(e,t=true){return e==null?true:e instanceof Date?isNaN(e.getTime()):e.constructor.name=="File"||e.constructor.name=="FileList"?e.size<=0:Array.isArray(e)?t?e.length===0:false:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function x(e){if(f(e))return false;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="string"){let r=new Date(e);if(r.toString()==="Invalid Date")return !1;t=r;}return !!t}catch{return false}}function T(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]"?new Date(e):typeof e=="string"||t==="[object String]"?new Date(e):new Date(NaN)}function i(e,t=true){return !f(typeof e=="string"?e.trim():e,t)}function c(e){return e==null||typeof e!="number"?false:!isNaN(e)}function p(e,...t){if(f(e))return true;let r=typeof e=="number"?e.toString():e;return t.every(n=>(n.lastIndex=0,n.test(r)))}function h(e){let t=unref(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 g(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function q(...e){let t=e.some(a=>typeof a=="function"?a.constructor.name==="AsyncFunction":a._async),r=e.map(a=>{if(typeof a=="function")return null;{let m=a._params;return m?.length?m:[]}}).flat().filter(a=>!!a);function n(a,m,...o){let y=[],b=0;for(let d of a)if(typeof d=="function")y.push(d(m)),b++;else {let D=d._params?.length??0;y.push(d.validator(m,...o.slice(b,D))),D&&(b+=D);}return y}function s(a){return a?.some(o=>typeof o!="boolean")?{$valid:a.every(o=>typeof o=="boolean"?!!o:o.$valid),...a.reduce((o,y)=>{if(typeof y=="boolean")return o;let{$valid:b,...d}=y;return {...o,...d}},{})}:a.every(o=>!!o)}let R;e.length?R=t?async(a,...m)=>{let o=await Promise.all(n(e,a,...m));return s(o)}:(a,...m)=>{let o=n(e,a,...m);return s(o)}:R=a=>false;let l=createRule({type:"and",validator:R,message:"The value does not match all of the provided validators"}),u=[...r??[]];return l._params=u,typeof l=="function"?l(...u):l}function G(...e){let t=e.some(a=>typeof a=="function"?a.constructor.name==="AsyncFunction":a._async),r=e.map(a=>typeof a=="function"?null:a._params).flat().filter(a=>!!a);function n(a,m,...o){let y=[],b=0;for(let d of a)if(typeof d=="function")y.push(d(m)),b++;else {let D=d._params?.length??0;y.push(d.validator(m,...o.slice(b,D))),D&&(b+=D);}return y}function s(a){return a.some(o=>typeof o!="boolean")?{$valid:a.some(o=>typeof o=="boolean"?!!o:o.$valid),...a.reduce((o,y)=>{if(typeof y=="boolean")return o;let{$valid:b,...d}=y;return {...o,...d}},{})}:a.some(o=>!!o)}let l=createRule({type:"or",validator:t?async(a,...m)=>{let o=await Promise.all(n(e,a,...m));return s(o)}:(a,...m)=>{let o=n(e,a,...m);return s(o)},message:"The value does not match any of the provided validators"}),u=[...r??[]];return l._params=u,typeof l=="function"?l(...u):l}function B(e,t){let r,n,s,R,l;typeof e=="function"?(n=e,l=e.constructor.name==="AsyncFunction"):({_type:r,validator:n,_params:R}=e,l=e._async),l?s=async(m,...o)=>i(m)?!await n(m,...o):true:s=(m,...o)=>i(m)?!n(m,...o):true;let u=createRule({type:"not",validator:s,message:t??"Error"}),a=[...R??[]];return u._params=a,typeof u=="function"?u(...a):u}var Qt=createRule({type:"required",validator:e=>i(e),message:"This field is required"});var er=createRule({type:"maxLength",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e,false)&&i(t)?c(t)?n?h(e)<=t:h(e)<t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),false):true},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`});var ar=createRule({type:"required",validator(e,t){return t?i(e):true},message:"This field is required",active({$params:[e]}){return e}});var X=/^[a-zA-Z]*$/,Y=/^[\w.]+$/,lr=createRule({type:"alpha",validator(e,t){return f(e)?true:t?p(e,Y):p(e,X)},message:"The value is not alphabetical"});var ee=/^[a-zA-Z0-9]*$/,te=/^[a-zA-Z0-9_]*$/,Rr=createRule({type:"alphaNum",validator(e,t){return f(e)?true:t?p(e,te):p(e,ee)},message:"The value must be alpha-numeric"});var gr=createRule({type:"between",validator:(e,t,r,n)=>{let{allowEqual:s=true}=n??{};if(i(e)&&i(t)&&i(r)){let R=g(e),l=g(t),u=g(r);return c(R)&&c(l)&&c(u)?s?R>=l&&R<=u:R>l&&R<u:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${r}`),false)}return true},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var ae=/^[-]?\d*(\.\d+)?$/,br=createRule({type:"decimal",validator(e){return f(e)?true:p(e,ae)},message:"The value must be decimal"});var oe=/^(?:[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,Pr=createRule({type:"email",validator(e){return f(e)?true:p(e,oe)},message:"The value must be an valid email address"});var le=/(^[0-9]*$)|(^-[0-9]+$)/,Vr=createRule({type:"integer",validator(e){return f(e)?true:p(e,le)},message:"The value must be an integer"});var Cr=createRule({type:"maxValue",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e)&&i(t)?c(t)&&!isNaN(g(e))?n?g(e)<=t:g(e)<t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true},message:({$params:[e,t]})=>{let{allowEqual:r=true}=t??{};return r?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}});var Ir=createRule({type:"minLength",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e,false)&&i(t)?c(t)?n?h(e)>=t:h(e)>t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),false):true},message:({$value:e,$params:[t]})=>Array.isArray(e)?`The list should have at least ${t} items`:`The value length should be at least ${t}`});var zr=createRule({type:"minValue",validator:(e,t,r)=>{let{allowEqual:n=true}=r??{};return i(e)&&i(t)?c(t)&&!isNaN(g(e))?n?g(e)>=t:g(e)>t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true},message:({$params:[e,t]})=>{let{allowEqual:r=true}=t??{};return r?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});var Gr=createRule({type:"exactValue",validator:(e,t)=>i(e)&&i(t)?c(t)&&!isNaN(g(e))?g(e)===t:(console.warn(`[exactValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),true):true,message:({$params:[e]})=>`The value must be equal to ${e}`});var Jr=createRule({type:"exactLength",validator:(e,t)=>i(e,false)&&i(t)?c(t)?h(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),false):true,message:({$params:[e]})=>`The value should be exactly ${e} characters long`});var ce=/^\d*(\.\d+)?$/,Yr=createRule({type:"numeric",validator(e){return f(e)?true:p(e,ce)},message:"The value must be numeric"});var rn=createRule({type:"required",validator(e,t){return t?true:i(e)},message:"This field is required",active({$params:[e]}){return !e}});var sn=createRule({type:"sameAs",validator(e,t,r="other"){return f(e)?true:e===t},message({$params:[e,t]}){return `The value must be equal to the ${t} value`}});var xe=/^(?:(?:(?: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,fn=createRule({type:"url",validator(e){return f(e)?true:p(e,xe)},message:"The value is not a valid URL address"});function be(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function w(e){return e?new Intl.DateTimeFormat(be(),{dateStyle:"short"}).format(new Date(e)):"?"}var dn=createRule({type:"dateAfter",validator:(e,t)=>i(e)&&i(t)?x(e)&&x(t)?T(e).getTime()>T(t).getTime()?true:{$valid:false,error:"date-not-after"}:{$valid:false,error:"value-or-paramater-not-a-date"}:true,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The values must be dates":`The date must be after ${w(e)}`});var Dn=createRule({type:"dateBefore",validator:(e,t)=>i(e)&&i(t)?x(e)&&x(t)?T(e).getTime()<T(t).getTime()?true:{$valid:false,error:"date-not-before"}:{$valid:false,error:"value-or-paramater-not-a-date"}:true,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be dates":`The date must be before ${w(e)}`});var vn=createRule({type:"dateBetween",validator:(e,t,r)=>x(e)&&x(t)&&x(r)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(r).getTime():true,message:({$params:[e,t]})=>`The date must be between ${w(e)} and ${w(t)}`});function we(e){if(e.length>3||e.length===0||e[0]==="0"&&e!=="0"||!e.match(/^\d+$/))return false;let t=+e|0;return t>=0&&t<=255}var Fn=createRule({type:"ipv4Address",validator(e){if(f(e))return true;if(typeof e!="string")return false;let t=e.split(".");return t.length===4&&t.every(we)},message:"The value is not a valid IPv4 address"});var En=createRule({type:"macAddress",validator(e,t=":"){if(f(e))return true;if(typeof e!="string")return false;let r=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return r!==null&&(r.length===6||r.length===8)&&r.every(ve)},message:"The value is not a valid MAC Address"}),ve=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var Sn=createRule({type:"checked",validator:e=>i(e)?e===true:true,message:"The value must be checked"});var Un=createRule({type:"contains",validator(e,t){return i(e)&&i(t)?e.includes(t):true},message({$params:[e]}){return `The value must contain ${e}`}});var Zn=createRule({type:"startsWith",validator(e,t){return i(e)&&i(t)?e.startsWith(t):true},message({$params:[e]}){return `The value must end with ${e}`}});var Xn=createRule({type:"endsWith",validator(e,t){return i(e)&&i(t)?e.endsWith(t):true},message({$params:[e]}){return `The value must end with ${e}`}});var ta=createRule({type:"regex",validator(e,t){if(i(e)){let r=Array.isArray(t)?t:[t];return p(e,...r)}return true},message:"The value does not match the required pattern"});function ia(e){let t=computed(()=>toValue(e));return M(P((n,s)=>i(n)&&i(s,false)?s.includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${n.join(", ")}.`)}function Oe(e){let t=Object.keys(e).filter(n=>typeof e[e[n]]!="number"),r={};for(let n of t)r[n]=e[n];return Object.values(r)}function ua(e){let t=computed(()=>toValue(e));return M(P((n,s)=>i(n)&&!f(s)?Oe(s).includes(n):true,[t]),({$params:[n]})=>`The value should be one of those options: ${Object.values(n).join(", ")}.`)}function ya(e){let t=computed(()=>toValue(e));return M(P((n,s)=>s===n,[t]),({$params:[n]})=>`Value should be ${n}.`)}export{lr as alpha,Rr as alphaNum,q as and,S as applyIf,gr as between,Sn as checked,Un as contains,dn as dateAfter,Dn as dateBefore,vn as dateBetween,br as decimal,Pr as email,Xn as endsWith,Jr as exactLength,Gr as exactValue,h as getSize,Vr as integer,Fn as ipv4Address,x as isDate,f as isEmpty,i as isFilled,c as isNumber,ya as literal,En as macAddress,p as matchRegex,er as maxLength,Cr as maxValue,Ir as minLength,zr as minValue,ua as nativeEnum,B as not,Yr as numeric,ia as oneOf,G as or,ta as regex,Qt as required,ar as requiredIf,rn as requiredUnless,sn as sameAs,Zn as startsWith,T as toDate,g as toNumber,fn as url,E as withAsync,M as withMessage,P as withParams,_ as withTooltip};
|
package/dist/regle-rules.mjs
CHANGED
|
@@ -497,7 +497,7 @@ var maxLength = createRule({
|
|
|
497
497
|
if (Array.isArray($value)) {
|
|
498
498
|
return `This list should have maximum ${count} items`;
|
|
499
499
|
}
|
|
500
|
-
return `The
|
|
500
|
+
return `The value length should not exceed ${count}`;
|
|
501
501
|
}
|
|
502
502
|
});
|
|
503
503
|
var requiredIf = createRule({
|
|
@@ -514,23 +514,31 @@ var requiredIf = createRule({
|
|
|
514
514
|
}
|
|
515
515
|
});
|
|
516
516
|
var alphaRegex = /^[a-zA-Z]*$/;
|
|
517
|
+
var alphaSymbolRegex = /^[\w.]+$/;
|
|
517
518
|
var alpha = createRule({
|
|
518
519
|
type: "alpha",
|
|
519
|
-
validator(value) {
|
|
520
|
+
validator(value, allowSymbols) {
|
|
520
521
|
if (isEmpty(value)) {
|
|
521
522
|
return true;
|
|
522
523
|
}
|
|
524
|
+
if (allowSymbols) {
|
|
525
|
+
return matchRegex(value, alphaSymbolRegex);
|
|
526
|
+
}
|
|
523
527
|
return matchRegex(value, alphaRegex);
|
|
524
528
|
},
|
|
525
529
|
message: "The value is not alphabetical"
|
|
526
530
|
});
|
|
527
531
|
var alphaNumRegex = /^[a-zA-Z0-9]*$/;
|
|
532
|
+
var alphaNumSymbolRegex = /^[a-zA-Z0-9_]*$/;
|
|
528
533
|
var alphaNum = createRule({
|
|
529
|
-
type: "
|
|
530
|
-
validator(value) {
|
|
534
|
+
type: "alphaNum",
|
|
535
|
+
validator(value, allowSymbols) {
|
|
531
536
|
if (isEmpty(value)) {
|
|
532
537
|
return true;
|
|
533
538
|
}
|
|
539
|
+
if (allowSymbols) {
|
|
540
|
+
return matchRegex(value, alphaNumSymbolRegex);
|
|
541
|
+
}
|
|
534
542
|
return matchRegex(value, alphaNumRegex);
|
|
535
543
|
},
|
|
536
544
|
message: "The value must be alpha-numeric"
|
|
@@ -568,7 +576,7 @@ var decimal = createRule({
|
|
|
568
576
|
}
|
|
569
577
|
return matchRegex(value, decimalRegex);
|
|
570
578
|
},
|
|
571
|
-
message: "
|
|
579
|
+
message: "The value must be decimal"
|
|
572
580
|
});
|
|
573
581
|
var emailRegex = /^(?:[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;
|
|
574
582
|
var email = createRule({
|
|
@@ -579,7 +587,7 @@ var email = createRule({
|
|
|
579
587
|
}
|
|
580
588
|
return matchRegex(value, emailRegex);
|
|
581
589
|
},
|
|
582
|
-
message: "
|
|
590
|
+
message: "The value must be an valid email address"
|
|
583
591
|
});
|
|
584
592
|
var integerRegex = /(^[0-9]*$)|(^-[0-9]+$)/;
|
|
585
593
|
var integer = createRule({
|
|
@@ -590,7 +598,7 @@ var integer = createRule({
|
|
|
590
598
|
}
|
|
591
599
|
return matchRegex(value, integerRegex);
|
|
592
600
|
},
|
|
593
|
-
message: "
|
|
601
|
+
message: "The value must be an integer"
|
|
594
602
|
});
|
|
595
603
|
var maxValue = createRule({
|
|
596
604
|
type: "maxValue",
|
|
@@ -612,9 +620,9 @@ var maxValue = createRule({
|
|
|
612
620
|
message: ({ $params: [count, options] }) => {
|
|
613
621
|
const { allowEqual = true } = options ?? {};
|
|
614
622
|
if (allowEqual) {
|
|
615
|
-
return `
|
|
623
|
+
return `The value must be less than or equal to ${count}`;
|
|
616
624
|
} else {
|
|
617
|
-
return `
|
|
625
|
+
return `The value must be less than ${count}`;
|
|
618
626
|
}
|
|
619
627
|
}
|
|
620
628
|
});
|
|
@@ -637,9 +645,9 @@ var minLength = createRule({
|
|
|
637
645
|
},
|
|
638
646
|
message: ({ $value, $params: [count] }) => {
|
|
639
647
|
if (Array.isArray($value)) {
|
|
640
|
-
return `
|
|
648
|
+
return `The list should have at least ${count} items`;
|
|
641
649
|
}
|
|
642
|
-
return `
|
|
650
|
+
return `The value length should be at least ${count}`;
|
|
643
651
|
}
|
|
644
652
|
});
|
|
645
653
|
var minValue = createRule({
|
|
@@ -662,9 +670,9 @@ var minValue = createRule({
|
|
|
662
670
|
message: ({ $params: [count, options] }) => {
|
|
663
671
|
const { allowEqual = true } = options ?? {};
|
|
664
672
|
if (allowEqual) {
|
|
665
|
-
return `
|
|
673
|
+
return `The value must be greater than or equal to ${count}`;
|
|
666
674
|
} else {
|
|
667
|
-
return `
|
|
675
|
+
return `The value must be greater than ${count}`;
|
|
668
676
|
}
|
|
669
677
|
}
|
|
670
678
|
});
|
|
@@ -697,7 +705,7 @@ var exactLength = createRule({
|
|
|
697
705
|
return true;
|
|
698
706
|
},
|
|
699
707
|
message: ({ $params: [count] }) => {
|
|
700
|
-
return `
|
|
708
|
+
return `The value should be exactly ${count} characters long`;
|
|
701
709
|
}
|
|
702
710
|
});
|
|
703
711
|
var numericRegex = /^\d*(\.\d+)?$/;
|
|
@@ -709,7 +717,7 @@ var numeric = createRule({
|
|
|
709
717
|
}
|
|
710
718
|
return matchRegex(value, numericRegex);
|
|
711
719
|
},
|
|
712
|
-
message: "
|
|
720
|
+
message: "The value must be numeric"
|
|
713
721
|
});
|
|
714
722
|
var requiredUnless = createRule({
|
|
715
723
|
type: "required",
|
|
@@ -733,7 +741,7 @@ var sameAs = createRule({
|
|
|
733
741
|
return value === target;
|
|
734
742
|
},
|
|
735
743
|
message({ $params: [_, otherName] }) {
|
|
736
|
-
return `
|
|
744
|
+
return `The value must be equal to the ${otherName} value`;
|
|
737
745
|
}
|
|
738
746
|
});
|
|
739
747
|
var urlRegex = /^(?:(?:(?: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;
|
|
@@ -778,7 +786,7 @@ var dateAfter = createRule({
|
|
|
778
786
|
},
|
|
779
787
|
message: ({ $params: [after], error }) => {
|
|
780
788
|
if (error === "value-or-paramater-not-a-date") {
|
|
781
|
-
return "The
|
|
789
|
+
return "The values must be dates";
|
|
782
790
|
}
|
|
783
791
|
return `The date must be after ${formatLocaleDate(after)}`;
|
|
784
792
|
}
|
|
@@ -800,7 +808,7 @@ var dateBefore = createRule({
|
|
|
800
808
|
},
|
|
801
809
|
message: ({ $params: [before], error }) => {
|
|
802
810
|
if (error === "value-or-paramater-not-a-date") {
|
|
803
|
-
return "The fields must be
|
|
811
|
+
return "The fields must be dates";
|
|
804
812
|
}
|
|
805
813
|
return `The date must be before ${formatLocaleDate(before)}`;
|
|
806
814
|
}
|
|
@@ -830,8 +838,8 @@ function nibbleValid(nibble) {
|
|
|
830
838
|
const numeric2 = +nibble | 0;
|
|
831
839
|
return numeric2 >= 0 && numeric2 <= 255;
|
|
832
840
|
}
|
|
833
|
-
var
|
|
834
|
-
type: "
|
|
841
|
+
var ipv4Address = createRule({
|
|
842
|
+
type: "ipv4Address",
|
|
835
843
|
validator(value) {
|
|
836
844
|
if (isEmpty(value)) {
|
|
837
845
|
return true;
|
|
@@ -842,7 +850,7 @@ var ipAddress = createRule({
|
|
|
842
850
|
const nibbles = value.split(".");
|
|
843
851
|
return nibbles.length === 4 && nibbles.every(nibbleValid);
|
|
844
852
|
},
|
|
845
|
-
message: "The value is not a valid
|
|
853
|
+
message: "The value is not a valid IPv4 address"
|
|
846
854
|
});
|
|
847
855
|
var macAddress = createRule({
|
|
848
856
|
type: "macAddress",
|
|
@@ -867,7 +875,7 @@ var checked = createRule({
|
|
|
867
875
|
}
|
|
868
876
|
return true;
|
|
869
877
|
},
|
|
870
|
-
message: "
|
|
878
|
+
message: "The value must be checked"
|
|
871
879
|
});
|
|
872
880
|
var contains = createRule({
|
|
873
881
|
type: "contains",
|
|
@@ -878,7 +886,7 @@ var contains = createRule({
|
|
|
878
886
|
return true;
|
|
879
887
|
},
|
|
880
888
|
message({ $params: [part] }) {
|
|
881
|
-
return `
|
|
889
|
+
return `The value must contain ${part}`;
|
|
882
890
|
}
|
|
883
891
|
});
|
|
884
892
|
var startsWith = createRule({
|
|
@@ -890,7 +898,7 @@ var startsWith = createRule({
|
|
|
890
898
|
return true;
|
|
891
899
|
},
|
|
892
900
|
message({ $params: [part] }) {
|
|
893
|
-
return `
|
|
901
|
+
return `The value must end with ${part}`;
|
|
894
902
|
}
|
|
895
903
|
});
|
|
896
904
|
var endsWith = createRule({
|
|
@@ -902,7 +910,7 @@ var endsWith = createRule({
|
|
|
902
910
|
return true;
|
|
903
911
|
},
|
|
904
912
|
message({ $params: [part] }) {
|
|
905
|
-
return `
|
|
913
|
+
return `The value must end with ${part}`;
|
|
906
914
|
}
|
|
907
915
|
});
|
|
908
916
|
var regex = createRule({
|
|
@@ -914,7 +922,7 @@ var regex = createRule({
|
|
|
914
922
|
}
|
|
915
923
|
return true;
|
|
916
924
|
},
|
|
917
|
-
message: "
|
|
925
|
+
message: "The value does not match the required pattern"
|
|
918
926
|
});
|
|
919
927
|
function oneOf(options) {
|
|
920
928
|
const params = computed(() => toValue(options));
|
|
@@ -928,7 +936,7 @@ function oneOf(options) {
|
|
|
928
936
|
},
|
|
929
937
|
[params]
|
|
930
938
|
),
|
|
931
|
-
({ $params: [options2] }) => `
|
|
939
|
+
({ $params: [options2] }) => `The value should be one of those options: ${options2.join(", ")}.`
|
|
932
940
|
);
|
|
933
941
|
return rule;
|
|
934
942
|
}
|
|
@@ -953,7 +961,7 @@ function nativeEnum(enumLike) {
|
|
|
953
961
|
},
|
|
954
962
|
[params]
|
|
955
963
|
),
|
|
956
|
-
({ $params: [enumLike2] }) => `
|
|
964
|
+
({ $params: [enumLike2] }) => `The value should be one of those options: ${Object.values(enumLike2).join(", ")}.`
|
|
957
965
|
);
|
|
958
966
|
return rule;
|
|
959
967
|
}
|
|
@@ -971,4 +979,4 @@ function literal(literal2) {
|
|
|
971
979
|
return rule;
|
|
972
980
|
}
|
|
973
981
|
|
|
974
|
-
export { alpha, alphaNum, and, applyIf, between, checked, contains, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, integer,
|
|
982
|
+
export { alpha, alphaNum, and, applyIf, between, checked, contains, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, nativeEnum, not, numeric, oneOf, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, toDate, toNumber, url, withAsync, withMessage, withParams, withTooltip };
|
package/package.json
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/rules",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.4",
|
|
4
4
|
"description": "Collection of rules and helpers for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@regle/core": "1.1.0-beta.
|
|
6
|
+
"@regle/core": "1.1.0-beta.4"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@typescript-eslint/eslint-plugin": "8.28.0",
|
|
10
10
|
"@typescript-eslint/parser": "8.28.0",
|
|
11
|
+
"@types/node": "22.13.17",
|
|
11
12
|
"@vue/reactivity": "3.5.13",
|
|
12
13
|
"@vue/test-utils": "2.4.6",
|
|
13
|
-
"bumpp": "10.1.0",
|
|
14
|
-
"changelogithub": "13.13.0",
|
|
15
|
-
"cross-env": "7.0.3",
|
|
16
14
|
"eslint": "9.15.0",
|
|
17
15
|
"eslint-config-prettier": "9.1.0",
|
|
18
16
|
"eslint-plugin-vue": "9.31.0",
|
|
19
|
-
"prettier": "3.
|
|
17
|
+
"prettier": "3.5.3",
|
|
20
18
|
"tsup": "8.4.0",
|
|
21
19
|
"type-fest": "4.38.0",
|
|
22
20
|
"typescript": "5.8.2",
|
|
23
|
-
"vitest": "3.
|
|
21
|
+
"vitest": "3.1.1",
|
|
24
22
|
"vue": "3.5.13",
|
|
25
|
-
"vue-eslint-parser": "
|
|
23
|
+
"vue-eslint-parser": "10.1.3",
|
|
26
24
|
"vue-tsc": "2.2.8"
|
|
27
25
|
},
|
|
28
26
|
"type": "module",
|
|
@@ -34,26 +32,18 @@
|
|
|
34
32
|
"production": "./dist/regle-rules.min.mjs",
|
|
35
33
|
"development": "./dist/regle-rules.mjs",
|
|
36
34
|
"default": "./dist/regle-rules.mjs"
|
|
37
|
-
},
|
|
38
|
-
"require": {
|
|
39
|
-
"production": "./dist/regle-rules.min.cjs",
|
|
40
|
-
"development": "./dist/regle-rules.cjs",
|
|
41
|
-
"default": "./index.js"
|
|
42
35
|
}
|
|
43
36
|
},
|
|
44
|
-
"import": "./dist/regle-rules.mjs"
|
|
45
|
-
"require": "./index.js"
|
|
37
|
+
"import": "./dist/regle-rules.mjs"
|
|
46
38
|
},
|
|
47
39
|
"./package.json": "./package.json",
|
|
48
40
|
"./dist/*": "./dist/*"
|
|
49
41
|
},
|
|
50
|
-
"main": "
|
|
42
|
+
"main": "./dist/regle-rules.mjs",
|
|
51
43
|
"module": "./dist/regle-rules.mjs",
|
|
52
44
|
"types": "./dist/regle-rules.d.ts",
|
|
53
45
|
"files": [
|
|
54
46
|
"dist",
|
|
55
|
-
"index.js",
|
|
56
|
-
"index.cjs",
|
|
57
47
|
"LICENSE",
|
|
58
48
|
"README.md"
|
|
59
49
|
],
|
|
@@ -71,7 +61,7 @@
|
|
|
71
61
|
},
|
|
72
62
|
"license": "MIT",
|
|
73
63
|
"scripts": {
|
|
74
|
-
"typecheck": "tsc --noEmit",
|
|
64
|
+
"typecheck": "vue-tsc --noEmit",
|
|
75
65
|
"build": "tsup",
|
|
76
66
|
"build:dev": "tsup --config=tsup.dev.ts",
|
|
77
67
|
"build:sourcemaps": "tsup --config=tsup.sourcemap.ts",
|