@regle/rules 1.11.0-beta.1 → 1.11.0-beta.3
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 +1 -145
- package/dist/regle-rules.js +3 -119
- package/dist/regle-rules.min.js +1 -1
- package/package.json +11 -16
package/dist/regle-rules.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { AllRulesDeclarations, CommonAlphaOptions, CommonComparisonOptions, FormRuleDeclaration, InlineRuleDeclaration, Maybe, MaybeInput, MaybeReadonly, NonEmptyTuple, RegleRuleDecl, RegleRuleDefinition, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, RegleRuleMetadataDefinition, RegleRuleWithParamsDefinition, UnwrapRegleUniversalParams } from "@regle/core";
|
|
2
2
|
import { ComputedRef, MaybeRef, MaybeRefOrGetter, Ref } from "vue";
|
|
3
|
-
|
|
4
|
-
//#region src/helpers/withMessage.d.ts
|
|
5
|
-
|
|
3
|
+
import { EmptyObject } from "type-fest";
|
|
6
4
|
/**
|
|
7
5
|
* The withMessage wrapper lets you associate an error message with a rule. Pass your rule as the first argument and the error message as the second.
|
|
8
6
|
*
|
|
@@ -24,16 +22,12 @@ declare function withMessage<TValue extends any, TParams extends any[], TReturn
|
|
|
24
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>;
|
|
25
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>;
|
|
26
24
|
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: (...args: any[]) => RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetadata>;
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/helpers/withTooltip.d.ts
|
|
29
25
|
/**
|
|
30
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 .
|
|
31
27
|
*/
|
|
32
28
|
declare function withTooltip<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>, newTooltip: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetadata>;
|
|
33
29
|
declare function withTooltip<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: RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>, newTooltip: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
|
|
34
30
|
declare function withTooltip<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>, newTooltip: 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>;
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/helpers/withAsync.d.ts
|
|
37
31
|
/**
|
|
38
32
|
* withAsync works like withParams, but is specifically designed for async rules that depend on external values.
|
|
39
33
|
*
|
|
@@ -54,8 +48,6 @@ declare function withTooltip<TValue extends any, TParams extends any[], TReturn
|
|
|
54
48
|
*/
|
|
55
49
|
declare function withAsync<TValue, TParams extends (Ref<unknown> | (() => unknown))[] = [], TReturn extends Promise<RegleRuleMetadataDefinition> = Promise<RegleRuleMetadataDefinition>, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise<infer M> ? M : TReturn)>(rule: InlineRuleDeclaration<TValue, TParams, TReturn>, depsArray?: [...TParams]): RegleRuleDefinition<TValue, UnwrapRegleUniversalParams<TParams>, true, TMetadata>;
|
|
56
50
|
declare function withAsync<TValue extends any, TParams extends any[], TMetadata extends RegleRuleMetadataDefinition>(rule: RegleRuleWithParamsDefinition<TValue, TParams, true, TMetadata>, depsArray?: [...TParams]): RegleRuleWithParamsDefinition<TValue, TParams, true, TMetadata>;
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/helpers/withParams.d.ts
|
|
59
51
|
/**
|
|
60
52
|
* The withParams wrapper allows your rule to depend on external parameters, such as a reactive property in your component or store.
|
|
61
53
|
*
|
|
@@ -78,8 +70,6 @@ declare function withAsync<TValue extends any, TParams extends any[], TMetadata
|
|
|
78
70
|
*/
|
|
79
71
|
declare function withParams<TValue, TParams extends (Ref<unknown> | (() => unknown))[] = [], TReturn extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise<infer M> ? M : TReturn), TAsync extends boolean = (TReturn extends Promise<any> ? true : false)>(rule: InlineRuleDeclaration<TValue, TParams, TReturn> | RegleRuleDefinition<TValue, any[], TAsync, TMetadata>, depsArray: [...TParams]): RegleRuleDefinition<TValue, UnwrapRegleUniversalParams<TParams>, TAsync, TMetadata>;
|
|
80
72
|
declare function withParams<TValue extends any, TParams extends any[], TReturn extends RegleRuleMetadataDefinition = 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>, depsArray: [...TParams]): RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetadata>;
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/helpers/applyIf.d.ts
|
|
83
73
|
/**
|
|
84
74
|
* The applyIf operator is similar to requiredIf, but it can be used with any rule.
|
|
85
75
|
* It simplifies conditional rule declarations.
|
|
@@ -96,8 +86,6 @@ declare function withParams<TValue extends any, TParams extends any[], TReturn e
|
|
|
96
86
|
* ```
|
|
97
87
|
*/
|
|
98
88
|
declare function applyIf<TValue extends any, 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)>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rule: InlineRuleDeclaration<TValue, TParams, TReturn> | RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>): RegleRuleDefinition<TValue, [...TParams, condition: boolean], TAsync, TMetadata>;
|
|
99
|
-
//#endregion
|
|
100
|
-
//#region src/helpers/ruleHelpers/isFilled.d.ts
|
|
101
89
|
/**
|
|
102
90
|
* This is almost a must have for optional fields. It checks if any value you provided is defined (including arrays and objects). You can base your validator result on this.
|
|
103
91
|
*
|
|
@@ -107,67 +95,24 @@ declare function applyIf<TValue extends any, TParams extends any[], TReturn exte
|
|
|
107
95
|
* @param [considerEmptyArrayInvalid=true] - will return true if set to `false`. (default: `true`)
|
|
108
96
|
*/
|
|
109
97
|
declare function isFilled<T extends unknown>(value: T, considerEmptyArrayInvalid?: boolean): value is NonNullable<T>;
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region src/helpers/ruleHelpers/isNumber.d.ts
|
|
112
98
|
/**
|
|
113
99
|
* This is a type guard that will check if the passed value is a real Number. This also returns false for NaN, so this is better than typeof value === "number".
|
|
114
100
|
*/
|
|
115
101
|
declare function isNumber(value: unknown): value is number;
|
|
116
|
-
//#endregion
|
|
117
|
-
//#region src/helpers/ruleHelpers/matchRegex.d.ts
|
|
118
102
|
/**
|
|
119
103
|
* This utility can take multiple regular expressions as arguments. It checks the input's validity and tests it against the provided regex patterns.
|
|
120
104
|
*/
|
|
121
105
|
declare function matchRegex(_value: string | number | null | undefined, ...expr: RegExp[]): boolean;
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region src/helpers/ruleHelpers/getSize.d.ts
|
|
124
106
|
/**
|
|
125
107
|
* This helper will return the length of any data type you pass. It works with strings, arrays, objects and numbers.
|
|
126
108
|
*/
|
|
127
109
|
declare function getSize(value: MaybeRef<string | any[] | Record<string, any> | number>): number;
|
|
128
|
-
//#endregion
|
|
129
|
-
//#region src/helpers/ruleHelpers/toNumber.d.ts
|
|
130
110
|
/**
|
|
131
111
|
* This utility converts any string (or number) into a number using the Number constructor.
|
|
132
112
|
*
|
|
133
113
|
* @returns ⚠️ Warning, returned value can be NaN
|
|
134
114
|
*/
|
|
135
115
|
declare function toNumber<T extends number | string | undefined>(argument: T): number;
|
|
136
|
-
//#endregion
|
|
137
|
-
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/empty-object.d.ts
|
|
138
|
-
declare const emptyObjectSymbol: unique symbol;
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
Represents a strictly empty plain object, the `{}` value.
|
|
142
|
-
|
|
143
|
-
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)).
|
|
144
|
-
|
|
145
|
-
@example
|
|
146
|
-
```
|
|
147
|
-
import type {EmptyObject} from 'type-fest';
|
|
148
|
-
|
|
149
|
-
// The following illustrates the problem with `{}`.
|
|
150
|
-
const foo1: {} = {}; // Pass
|
|
151
|
-
const foo2: {} = []; // Pass
|
|
152
|
-
const foo3: {} = 42; // Pass
|
|
153
|
-
const foo4: {} = {a: 1}; // Pass
|
|
154
|
-
|
|
155
|
-
// With `EmptyObject` only the first case is valid.
|
|
156
|
-
const bar1: EmptyObject = {}; // Pass
|
|
157
|
-
const bar2: EmptyObject = 42; // Fail
|
|
158
|
-
const bar3: EmptyObject = []; // Fail
|
|
159
|
-
const bar4: EmptyObject = {a: 1}; // Fail
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
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}.
|
|
163
|
-
|
|
164
|
-
@category Object
|
|
165
|
-
*/
|
|
166
|
-
type EmptyObject = {
|
|
167
|
-
[emptyObjectSymbol]?: never;
|
|
168
|
-
};
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region ../shared/utils/isEmpty.d.ts
|
|
171
116
|
/**
|
|
172
117
|
* This is the inverse of isFilled. It will check if the value is in any way empty (including arrays and objects)
|
|
173
118
|
*
|
|
@@ -177,20 +122,14 @@ type EmptyObject = {
|
|
|
177
122
|
* @param [considerEmptyArrayInvalid=true] - will return false if set to `false`. (default: `true`)
|
|
178
123
|
*/
|
|
179
124
|
declare function isEmpty(value: unknown, considerEmptyArrayInvalid?: boolean): value is null | undefined | [] | EmptyObject;
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region ../shared/utils/isDate.d.ts
|
|
182
125
|
/**
|
|
183
126
|
* 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.
|
|
184
127
|
*/
|
|
185
128
|
declare function isDate(value: unknown): value is Date | string;
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region ../shared/utils/toDate.d.ts
|
|
188
129
|
/**
|
|
189
130
|
* This utility will coerce any string, number or Date value into a Date using the Date constructor.
|
|
190
131
|
*/
|
|
191
132
|
declare function toDate(argument: Maybe<Date | number | string>): Date;
|
|
192
|
-
//#endregion
|
|
193
|
-
//#region src/types/utils/params.utils.d.ts
|
|
194
133
|
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>] : [];
|
|
195
134
|
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>] : [];
|
|
196
135
|
type ExtractAsync<T extends [...any[]]> = T extends [infer F, ...infer R] ? F extends true ? true : F extends false ? ExtractAsync<R> : false : false;
|
|
@@ -205,26 +144,18 @@ type ExtractMetadata<T extends [...any[]]> = T extends [infer F, ...infer R] ? F
|
|
|
205
144
|
type GuessMetadataFromRules<T extends any[], TMeta = ExtractMetadata<ExtractMetaDataFromRules<T>>> = TMeta extends EmptyObject ? boolean : TMeta;
|
|
206
145
|
type FilterTuple<T extends any[]> = T extends [infer F, ...infer R] ? [F] extends [[]] ? [...FilterTuple<R>] : [F, ...FilterTuple<R>] : [];
|
|
207
146
|
type UnwrapTuples<T extends any[]> = FilterTuple<T> extends [infer U extends any[]] ? U : FilterTuple<T>;
|
|
208
|
-
//#endregion
|
|
209
|
-
//#region src/helpers/and.d.ts
|
|
210
147
|
/**
|
|
211
148
|
* The and operator combines multiple rules and validates successfully only if all provided rules are valid.
|
|
212
149
|
*/
|
|
213
150
|
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>>;
|
|
214
|
-
//#endregion
|
|
215
|
-
//#region src/helpers/or.d.ts
|
|
216
151
|
/**
|
|
217
152
|
* The or operator validates successfully if at least one of the provided rules is valid.
|
|
218
153
|
*/
|
|
219
154
|
declare function or<TRules extends [FormRuleDeclaration<any, any>, ...FormRuleDeclaration<any, any>[]]>(...rules: [...TRules]): RegleRuleDefinition<ExtractValueFromRules<TRules>[number], UnwrapTuples<ExtractParamsFromRules<TRules>>, GuessAsyncFromRules<TRules>, GuessMetadataFromRules<TRules>>;
|
|
220
|
-
//#endregion
|
|
221
|
-
//#region src/helpers/not.d.ts
|
|
222
155
|
/**
|
|
223
156
|
* The not operator passes when the provided rule fails and fails when the rule passes. It can be combined with other rules.
|
|
224
157
|
*/
|
|
225
158
|
declare function not<TValue, 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<TValue, TParams, TAsync, TMetadata> | InlineRuleDeclaration<TValue, TParams, TReturn>, message?: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
|
|
226
|
-
//#endregion
|
|
227
|
-
//#region src/helpers/assignIf.d.ts
|
|
228
159
|
/**
|
|
229
160
|
* The assignIf is a shorthand for conditional destructuring assignment.
|
|
230
161
|
* It allows to apply multiple rules to a field conditionally.
|
|
@@ -240,24 +171,18 @@ declare function not<TValue, TParams extends any[] = [], TReturn extends RegleRu
|
|
|
240
171
|
* ```
|
|
241
172
|
*/
|
|
242
173
|
declare function assignIf<TValue extends unknown = any, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>, TRulesDelc extends RegleRuleDecl<TValue, TCustomRules> = RegleRuleDecl<TValue, TCustomRules>>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rules: TRulesDelc): ComputedRef<TRulesDelc>;
|
|
243
|
-
//#endregion
|
|
244
|
-
//#region src/rules/alpha.d.ts
|
|
245
174
|
/**
|
|
246
175
|
* Allows only alphabetic characters.
|
|
247
176
|
*
|
|
248
177
|
* @param [options] - Alpha rules options
|
|
249
178
|
* */
|
|
250
179
|
declare const alpha: RegleRuleWithParamsDefinition<string, [options?: CommonAlphaOptions | undefined], false, boolean, MaybeInput<string>, string>;
|
|
251
|
-
//#endregion
|
|
252
|
-
//#region src/rules/alphaNum.d.ts
|
|
253
180
|
/**
|
|
254
181
|
* Allows only alphanumeric characters.
|
|
255
182
|
*
|
|
256
183
|
* @param [options] - Alpha rules options
|
|
257
184
|
*/
|
|
258
185
|
declare const alphaNum: RegleRuleWithParamsDefinition<string | number, [options?: CommonAlphaOptions | undefined], false, boolean, MaybeInput<string>>;
|
|
259
|
-
//#endregion
|
|
260
|
-
//#region src/rules/between.d.ts
|
|
261
186
|
/**
|
|
262
187
|
* Checks if a number is in specified bounds. min and max are both inclusive.
|
|
263
188
|
*
|
|
@@ -265,38 +190,28 @@ declare const alphaNum: RegleRuleWithParamsDefinition<string | number, [options?
|
|
|
265
190
|
* @param max - the maximum limit
|
|
266
191
|
*/
|
|
267
192
|
declare const between: RegleRuleWithParamsDefinition<number, [min: number, max: number, options?: CommonComparisonOptions], false, boolean, MaybeInput<number>>;
|
|
268
|
-
//#endregion
|
|
269
|
-
//#region src/rules/boolean.d.ts
|
|
270
193
|
/**
|
|
271
194
|
* Requires a value to be a native boolean type
|
|
272
195
|
*
|
|
273
196
|
* Mainly used for typing
|
|
274
197
|
*/
|
|
275
198
|
declare const boolean: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<boolean>, unknown>;
|
|
276
|
-
//#endregion
|
|
277
|
-
//#region src/rules/checked.d.ts
|
|
278
199
|
/**
|
|
279
200
|
* Requires a boolean value to be true. This is useful for checkbox inputs.
|
|
280
201
|
*/
|
|
281
202
|
declare const checked: RegleRuleDefinition<boolean, [], false, boolean, MaybeInput<boolean>>;
|
|
282
|
-
//#endregion
|
|
283
|
-
//#region src/rules/contains.d.ts
|
|
284
203
|
/**
|
|
285
204
|
* Checks if the string contains the specified substring.
|
|
286
205
|
*
|
|
287
206
|
* @param part - the part the value needs to contain
|
|
288
207
|
*/
|
|
289
208
|
declare const contains: RegleRuleWithParamsDefinition<string, [part: MaybeInput<string>], false, boolean, MaybeInput<string>>;
|
|
290
|
-
//#endregion
|
|
291
|
-
//#region src/rules/date.d.ts
|
|
292
209
|
/**
|
|
293
210
|
* Requires a value to be a native Date constructor
|
|
294
211
|
*
|
|
295
212
|
* Mainly used for typing
|
|
296
213
|
*/
|
|
297
214
|
declare const date: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<Date>, unknown>;
|
|
298
|
-
//#endregion
|
|
299
|
-
//#region src/rules/dateAfter.d.ts
|
|
300
215
|
/**
|
|
301
216
|
* Checks if the date is after the given parameter.
|
|
302
217
|
*
|
|
@@ -310,8 +225,6 @@ declare const dateAfter: RegleRuleWithParamsDefinition<string | Date, [after: Ma
|
|
|
310
225
|
$valid: false;
|
|
311
226
|
error: 'value-or-parameter-not-a-date';
|
|
312
227
|
}, MaybeInput<string | Date>>;
|
|
313
|
-
//#endregion
|
|
314
|
-
//#region src/rules/dateBefore.d.ts
|
|
315
228
|
/**
|
|
316
229
|
* Checks if the date is before the given parameter.
|
|
317
230
|
*
|
|
@@ -325,8 +238,6 @@ declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [before:
|
|
|
325
238
|
$valid: false;
|
|
326
239
|
error: 'value-or-parameter-not-a-date';
|
|
327
240
|
}, MaybeInput<string | Date>>;
|
|
328
|
-
//#endregion
|
|
329
|
-
//#region src/rules/dateBetween.d.ts
|
|
330
241
|
/**
|
|
331
242
|
* Checks if the date falls between the specified bounds.
|
|
332
243
|
*
|
|
@@ -335,74 +246,52 @@ declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [before:
|
|
|
335
246
|
* @param options - comparison options
|
|
336
247
|
*/
|
|
337
248
|
declare const dateBetween: RegleRuleWithParamsDefinition<string | Date, [before: MaybeInput<string | Date>, after: MaybeInput<string | Date>, options?: CommonComparisonOptions], false, boolean, MaybeInput<string | Date>>;
|
|
338
|
-
//#endregion
|
|
339
|
-
//#region src/rules/decimal.d.ts
|
|
340
249
|
/**
|
|
341
250
|
* Allows positive and negative decimal numbers.
|
|
342
251
|
*/
|
|
343
252
|
declare const decimal: RegleRuleDefinition<string | number, [], false, boolean, MaybeInput<number | undefined>>;
|
|
344
|
-
//#endregion
|
|
345
|
-
//#region src/rules/email.d.ts
|
|
346
253
|
/**
|
|
347
254
|
* Validates email addresses. Always verify on the server to ensure the address is real and not already in use.
|
|
348
255
|
*/
|
|
349
256
|
declare const email: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
|
|
350
|
-
//#endregion
|
|
351
|
-
//#region src/rules/endsWith.d.ts
|
|
352
257
|
/**
|
|
353
258
|
* Checks if the string ends with the specified substring.
|
|
354
259
|
*
|
|
355
260
|
* @param part - the value the field must end with
|
|
356
261
|
*/
|
|
357
262
|
declare const endsWith: RegleRuleWithParamsDefinition<string, [part: MaybeInput<string>], false, boolean, MaybeInput<string>>;
|
|
358
|
-
//#endregion
|
|
359
|
-
//#region src/rules/exactLength.d.ts
|
|
360
263
|
/**
|
|
361
264
|
* Requires the input value to have a strict specified length, inclusive. Works with arrays, objects and strings.
|
|
362
265
|
*
|
|
363
266
|
* @param count - the required length
|
|
364
267
|
*/
|
|
365
268
|
declare const exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number], false, boolean>;
|
|
366
|
-
//#endregion
|
|
367
|
-
//#region src/rules/exactValue.d.ts
|
|
368
269
|
/**
|
|
369
270
|
* Requires a field to have a strict numeric value.
|
|
370
271
|
*/
|
|
371
272
|
declare const exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean, MaybeInput<number>>;
|
|
372
|
-
//#endregion
|
|
373
|
-
//#region src/rules/hexadecimal.d.ts
|
|
374
273
|
/**
|
|
375
274
|
* Allows only hexadecimal values.
|
|
376
275
|
*/
|
|
377
276
|
declare const hexadecimal: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
|
|
378
|
-
//#endregion
|
|
379
|
-
//#region src/rules/integer.d.ts
|
|
380
277
|
/**
|
|
381
278
|
* Allows only integers (positive and negative).
|
|
382
279
|
*/
|
|
383
280
|
declare const integer: RegleRuleDefinition<string | number, [], false, boolean, MaybeInput<number>>;
|
|
384
|
-
//#endregion
|
|
385
|
-
//#region src/rules/ipv4Address.d.ts
|
|
386
281
|
/**
|
|
387
282
|
* Validates IPv4 addresses in dotted decimal notation 127.0.0.1.
|
|
388
283
|
*/
|
|
389
284
|
declare const ipv4Address: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
|
|
390
|
-
//#endregion
|
|
391
|
-
//#region src/rules/literal.d.ts
|
|
392
285
|
/**
|
|
393
286
|
* Allow only one possible literal value
|
|
394
287
|
*/
|
|
395
288
|
declare function literal<const TValue extends string | number>(literal: MaybeRefOrGetter<TValue>): RegleRuleDefinition<TValue, [literal: TValue], false, boolean, MaybeInput<TValue>, string | number>;
|
|
396
|
-
//#endregion
|
|
397
|
-
//#region src/rules/macAddress.d.ts
|
|
398
289
|
/**
|
|
399
290
|
* Validates MAC addresses. Call as a function to specify a custom separator (e.g., ':' or an empty string for 00ff1122334455).
|
|
400
291
|
*
|
|
401
292
|
* @param separator - the custom separator
|
|
402
293
|
*/
|
|
403
294
|
declare const macAddress: RegleRuleWithParamsDefinition<string, [separator?: string | undefined], false, boolean, MaybeInput<string>>;
|
|
404
|
-
//#endregion
|
|
405
|
-
//#region src/rules/maxLength.d.ts
|
|
406
295
|
/**
|
|
407
296
|
* Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.
|
|
408
297
|
*
|
|
@@ -410,8 +299,6 @@ declare const macAddress: RegleRuleWithParamsDefinition<string, [separator?: str
|
|
|
410
299
|
* @param options - comparison options
|
|
411
300
|
*/
|
|
412
301
|
declare const maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
413
|
-
//#endregion
|
|
414
|
-
//#region src/rules/maxValue.d.ts
|
|
415
302
|
/**
|
|
416
303
|
* Requires a field to have a specified maximum numeric value.
|
|
417
304
|
*
|
|
@@ -419,8 +306,6 @@ declare const maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<P
|
|
|
419
306
|
* @param options - comparison options
|
|
420
307
|
*/
|
|
421
308
|
declare const maxValue: RegleRuleWithParamsDefinition<number | string, [count: number | string, options?: CommonComparisonOptions], false, boolean, MaybeInput<number | string>>;
|
|
422
|
-
//#endregion
|
|
423
|
-
//#region src/rules/minLength.d.ts
|
|
424
309
|
/**
|
|
425
310
|
* Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.
|
|
426
311
|
*
|
|
@@ -428,8 +313,6 @@ declare const maxValue: RegleRuleWithParamsDefinition<number | string, [count: n
|
|
|
428
313
|
* @param options - comparison options
|
|
429
314
|
*/
|
|
430
315
|
declare const minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
|
|
431
|
-
//#endregion
|
|
432
|
-
//#region src/rules/minValue.d.ts
|
|
433
316
|
/**
|
|
434
317
|
* Requires a field to have a specified minimum numeric value.
|
|
435
318
|
*
|
|
@@ -437,8 +320,6 @@ declare const minLength: RegleRuleWithParamsDefinition<string | any[] | Record<P
|
|
|
437
320
|
* @param options - comparison options
|
|
438
321
|
*/
|
|
439
322
|
declare const minValue: RegleRuleWithParamsDefinition<number | string, [count: number | string, options?: CommonComparisonOptions], false, boolean, MaybeInput<number | string>>;
|
|
440
|
-
//#endregion
|
|
441
|
-
//#region src/rules/nativeEnum.d.ts
|
|
442
323
|
type EnumLike = {
|
|
443
324
|
[k: string]: string | number;
|
|
444
325
|
[nu: number]: string;
|
|
@@ -447,22 +328,16 @@ type EnumLike = {
|
|
|
447
328
|
* Validate against a native Typescript enum value.
|
|
448
329
|
*/
|
|
449
330
|
declare function nativeEnum<T extends EnumLike>(enumLike: T): RegleRuleDefinition<MaybeInput<T[keyof T]>, [enumLike: T], false, boolean, MaybeInput<T[keyof T]>, string | number>;
|
|
450
|
-
//#endregion
|
|
451
|
-
//#region src/rules/number.d.ts
|
|
452
331
|
/**
|
|
453
332
|
* Requires a value to be a native number type
|
|
454
333
|
*
|
|
455
334
|
* Mainly used for typing
|
|
456
335
|
*/
|
|
457
336
|
declare const number: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<number>, unknown>;
|
|
458
|
-
//#endregion
|
|
459
|
-
//#region src/rules/numeric.d.ts
|
|
460
337
|
/**
|
|
461
338
|
* Allows only numeric values (including numeric strings).
|
|
462
339
|
*/
|
|
463
340
|
declare const numeric: RegleRuleDefinition<string | number, [], false, boolean, MaybeInput<string | number>>;
|
|
464
|
-
//#endregion
|
|
465
|
-
//#region src/rules/oneOf.d.ts
|
|
466
341
|
interface OneOfFn {
|
|
467
342
|
<const TValues extends NonEmptyTuple<string | number> | NonEmptyTuple<string> | NonEmptyTuple<number>>(options: MaybeReadonly<MaybeRefOrGetter<[...TValues]>>): RegleRuleDefinition<TValues[number], [options: TValues], false, boolean, MaybeInput<TValues[number]>, string | number>;
|
|
468
343
|
/** Keep this definition without generics for inference */
|
|
@@ -472,36 +347,26 @@ interface OneOfFn {
|
|
|
472
347
|
* Allow only one of the values from a fixed Array of possible entries.
|
|
473
348
|
*/
|
|
474
349
|
declare const oneOf: OneOfFn;
|
|
475
|
-
//#endregion
|
|
476
|
-
//#region src/rules/regex.d.ts
|
|
477
350
|
/**
|
|
478
351
|
* Checks if the value matches one or more regular expressions.
|
|
479
352
|
*/
|
|
480
353
|
declare const regex: RegleRuleWithParamsDefinition<string | number, [regexp: RegExp | RegExp[]], false, boolean, MaybeInput<string | number>>;
|
|
481
|
-
//#endregion
|
|
482
|
-
//#region src/rules/required.d.ts
|
|
483
354
|
/**
|
|
484
355
|
* Requires non-empty data. Checks for empty arrays and strings containing only whitespaces.
|
|
485
356
|
*/
|
|
486
357
|
declare const required: RegleRuleDefinition<unknown, [], false, boolean, unknown>;
|
|
487
|
-
//#endregion
|
|
488
|
-
//#region src/rules/requiredIf.d.ts
|
|
489
358
|
/**
|
|
490
359
|
* Requires non-empty data, only if provided data property, ref, or a function resolves to true.
|
|
491
360
|
*
|
|
492
361
|
* @param condition - the condition to enable the required rule
|
|
493
362
|
*/
|
|
494
363
|
declare const requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
|
|
495
|
-
//#endregion
|
|
496
|
-
//#region src/rules/requiredUnless.d.ts
|
|
497
364
|
/**
|
|
498
365
|
* Requires non-empty data, only if provided data property, ref, or a function resolves to false.
|
|
499
366
|
*
|
|
500
367
|
* @param condition - the condition to disable the required rule
|
|
501
368
|
*/
|
|
502
369
|
declare const requiredUnless: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
|
|
503
|
-
//#endregion
|
|
504
|
-
//#region src/rules/sameAs.d.ts
|
|
505
370
|
interface SameAsFn {
|
|
506
371
|
<TTarget extends unknown = unknown>(target: MaybeRefOrGetter<TTarget>, otherName?: MaybeRefOrGetter<string>): RegleRuleDefinition<TTarget, [target: TTarget, otherName?: string], false, boolean, TTarget extends MaybeInput<infer M> ? M : MaybeInput<TTarget>>;
|
|
507
372
|
/** Keep this definition without generics for inference */
|
|
@@ -511,35 +376,26 @@ interface SameAsFn {
|
|
|
511
376
|
* Checks if the value matches the specified property or ref.
|
|
512
377
|
*/
|
|
513
378
|
declare const sameAs: SameAsFn;
|
|
514
|
-
//#endregion
|
|
515
|
-
//#region src/rules/startsWith.d.ts
|
|
516
379
|
/**
|
|
517
380
|
* Checks if the string starts with the specified substring.
|
|
518
381
|
*
|
|
519
382
|
* @private part - the value the field must start with
|
|
520
383
|
*/
|
|
521
384
|
declare const startsWith: RegleRuleWithParamsDefinition<string, [part: MaybeInput<string>], false, boolean, MaybeInput<string>>;
|
|
522
|
-
//#endregion
|
|
523
|
-
//#region src/rules/string.d.ts
|
|
524
385
|
/**
|
|
525
386
|
* Requires a value to be a native string type
|
|
526
387
|
*
|
|
527
388
|
* Mainly used for typing
|
|
528
389
|
*/
|
|
529
390
|
declare const string: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<string>, unknown>;
|
|
530
|
-
//#endregion
|
|
531
|
-
//#region src/rules/type.d.ts
|
|
532
391
|
/**
|
|
533
392
|
* Define the input type of a rule. No runtime validation.
|
|
534
393
|
*
|
|
535
394
|
* Override any input type set by other rules.
|
|
536
395
|
*/
|
|
537
396
|
declare function type<T>(): RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<T>>;
|
|
538
|
-
//#endregion
|
|
539
|
-
//#region src/rules/url.d.ts
|
|
540
397
|
/**
|
|
541
398
|
* Validates URLs.
|
|
542
399
|
*/
|
|
543
400
|
declare const url: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
|
|
544
|
-
//#endregion
|
|
545
401
|
export { EnumLike, alpha, alphaNum, and, applyIf, assignIf, between, boolean, checked, contains, date, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, hexadecimal, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, url, withAsync, withMessage, withParams, withTooltip };
|
package/dist/regle-rules.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { InternalRuleType, createRule, unwrapRuleParameters } from "@regle/core";
|
|
2
2
|
import { computed, toValue, unref } from "vue";
|
|
3
3
|
|
|
4
|
-
//#region src/helpers/withMessage.ts
|
|
5
4
|
function withMessage(rule, newMessage) {
|
|
6
5
|
let _type;
|
|
7
6
|
let validator;
|
|
@@ -30,8 +29,6 @@ function withMessage(rule, newMessage) {
|
|
|
30
29
|
} else return newRule;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/helpers/withTooltip.ts
|
|
35
32
|
function withTooltip(rule, newTooltip) {
|
|
36
33
|
let _type;
|
|
37
34
|
let validator;
|
|
@@ -59,8 +56,6 @@ function withTooltip(rule, newTooltip) {
|
|
|
59
56
|
} else return newRule;
|
|
60
57
|
}
|
|
61
58
|
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/helpers/withAsync.ts
|
|
64
59
|
function withAsync(rule, depsArray) {
|
|
65
60
|
let _type;
|
|
66
61
|
let validator;
|
|
@@ -86,8 +81,6 @@ function withAsync(rule, depsArray) {
|
|
|
86
81
|
return newRule(...depsArray ?? []);
|
|
87
82
|
}
|
|
88
83
|
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/helpers/withParams.ts
|
|
91
84
|
function withParams(rule, depsArray) {
|
|
92
85
|
let _type;
|
|
93
86
|
let validator;
|
|
@@ -112,8 +105,6 @@ function withParams(rule, depsArray) {
|
|
|
112
105
|
return newRule(...depsArray);
|
|
113
106
|
}
|
|
114
107
|
|
|
115
|
-
//#endregion
|
|
116
|
-
//#region src/helpers/applyIf.ts
|
|
117
108
|
/**
|
|
118
109
|
* The applyIf operator is similar to requiredIf, but it can be used with any rule.
|
|
119
110
|
* It simplifies conditional rule declarations.
|
|
@@ -163,8 +154,6 @@ function applyIf(_condition, rule) {
|
|
|
163
154
|
else return newRule;
|
|
164
155
|
}
|
|
165
156
|
|
|
166
|
-
//#endregion
|
|
167
|
-
//#region ../shared/utils/isFile.ts
|
|
168
157
|
/**
|
|
169
158
|
* Server side friendly way of checking for a File
|
|
170
159
|
*/
|
|
@@ -172,8 +161,6 @@ function isFile(value) {
|
|
|
172
161
|
return value?.constructor?.name == "File" || value?.constructor?.name == "FileList";
|
|
173
162
|
}
|
|
174
163
|
|
|
175
|
-
//#endregion
|
|
176
|
-
//#region ../shared/utils/isEmpty.ts
|
|
177
164
|
/**
|
|
178
165
|
* This is the inverse of isFilled. It will check if the value is in any way empty (including arrays and objects)
|
|
179
166
|
*
|
|
@@ -193,12 +180,6 @@ function isEmpty(value, considerEmptyArrayInvalid = true) {
|
|
|
193
180
|
return !String(value).length;
|
|
194
181
|
}
|
|
195
182
|
|
|
196
|
-
//#endregion
|
|
197
|
-
//#region ../shared/utils/symbol.ts
|
|
198
|
-
const RegleRuleSymbol = Symbol("regle-rule");
|
|
199
|
-
|
|
200
|
-
//#endregion
|
|
201
|
-
//#region ../shared/utils/isDate.ts
|
|
202
183
|
/**
|
|
203
184
|
* 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.
|
|
204
185
|
*/
|
|
@@ -218,8 +199,6 @@ function isDate(value) {
|
|
|
218
199
|
}
|
|
219
200
|
}
|
|
220
201
|
|
|
221
|
-
//#endregion
|
|
222
|
-
//#region ../shared/utils/toDate.ts
|
|
223
202
|
/**
|
|
224
203
|
* This utility will coerce any string, number or Date value into a Date using the Date constructor.
|
|
225
204
|
*/
|
|
@@ -232,8 +211,6 @@ function toDate(argument) {
|
|
|
232
211
|
else return /* @__PURE__ */ new Date(NaN);
|
|
233
212
|
}
|
|
234
213
|
|
|
235
|
-
//#endregion
|
|
236
|
-
//#region src/helpers/ruleHelpers/isFilled.ts
|
|
237
214
|
/**
|
|
238
215
|
* This is almost a must have for optional fields. It checks if any value you provided is defined (including arrays and objects). You can base your validator result on this.
|
|
239
216
|
*
|
|
@@ -246,8 +223,6 @@ function isFilled(value, considerEmptyArrayInvalid = true) {
|
|
|
246
223
|
return !isEmpty(typeof value === "string" ? value.trim() : value, considerEmptyArrayInvalid);
|
|
247
224
|
}
|
|
248
225
|
|
|
249
|
-
//#endregion
|
|
250
|
-
//#region src/helpers/ruleHelpers/isNumber.ts
|
|
251
226
|
/**
|
|
252
227
|
* This is a type guard that will check if the passed value is a real Number. This also returns false for NaN, so this is better than typeof value === "number".
|
|
253
228
|
*/
|
|
@@ -258,8 +233,6 @@ function isNumber(value) {
|
|
|
258
233
|
else return true;
|
|
259
234
|
}
|
|
260
235
|
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/helpers/ruleHelpers/matchRegex.ts
|
|
263
236
|
/**
|
|
264
237
|
* This utility can take multiple regular expressions as arguments. It checks the input's validity and tests it against the provided regex patterns.
|
|
265
238
|
*/
|
|
@@ -272,8 +245,6 @@ function matchRegex(_value, ...expr) {
|
|
|
272
245
|
});
|
|
273
246
|
}
|
|
274
247
|
|
|
275
|
-
//#endregion
|
|
276
|
-
//#region src/helpers/ruleHelpers/getSize.ts
|
|
277
248
|
/**
|
|
278
249
|
* This helper will return the length of any data type you pass. It works with strings, arrays, objects and numbers.
|
|
279
250
|
*/
|
|
@@ -288,8 +259,6 @@ function getSize(value) {
|
|
|
288
259
|
return String(_value).length;
|
|
289
260
|
}
|
|
290
261
|
|
|
291
|
-
//#endregion
|
|
292
|
-
//#region src/helpers/ruleHelpers/toNumber.ts
|
|
293
262
|
/**
|
|
294
263
|
* This utility converts any string (or number) into a number using the Number constructor.
|
|
295
264
|
*
|
|
@@ -307,8 +276,6 @@ function toNumber(argument) {
|
|
|
307
276
|
return NaN;
|
|
308
277
|
}
|
|
309
278
|
|
|
310
|
-
//#endregion
|
|
311
|
-
//#region src/helpers/and.ts
|
|
312
279
|
/**
|
|
313
280
|
* The and operator combines multiple rules and validates successfully only if all provided rules are valid.
|
|
314
281
|
*/
|
|
@@ -346,7 +313,7 @@ function and(...rules) {
|
|
|
346
313
|
}),
|
|
347
314
|
...results.reduce((acc, result) => {
|
|
348
315
|
if (typeof result === "boolean") return acc;
|
|
349
|
-
const { $valid: _$valid
|
|
316
|
+
const { $valid: _$valid, ...rest } = result;
|
|
350
317
|
return {
|
|
351
318
|
...acc,
|
|
352
319
|
...rest
|
|
@@ -375,8 +342,6 @@ function and(...rules) {
|
|
|
375
342
|
else return newRule;
|
|
376
343
|
}
|
|
377
344
|
|
|
378
|
-
//#endregion
|
|
379
|
-
//#region src/helpers/or.ts
|
|
380
345
|
/**
|
|
381
346
|
* The or operator validates successfully if at least one of the provided rules is valid.
|
|
382
347
|
*/
|
|
@@ -410,7 +375,7 @@ function or(...rules) {
|
|
|
410
375
|
}),
|
|
411
376
|
...results.reduce((acc, result) => {
|
|
412
377
|
if (typeof result === "boolean") return acc;
|
|
413
|
-
const { $valid: _
|
|
378
|
+
const { $valid: _, ...rest } = result;
|
|
414
379
|
return {
|
|
415
380
|
...acc,
|
|
416
381
|
...rest
|
|
@@ -434,8 +399,6 @@ function or(...rules) {
|
|
|
434
399
|
else return newRule;
|
|
435
400
|
}
|
|
436
401
|
|
|
437
|
-
//#endregion
|
|
438
|
-
//#region src/helpers/not.ts
|
|
439
402
|
/**
|
|
440
403
|
* The not operator passes when the provided rule fails and fails when the rule passes. It can be combined with other rules.
|
|
441
404
|
*/
|
|
@@ -471,8 +434,6 @@ function not(rule, message) {
|
|
|
471
434
|
else return newRule;
|
|
472
435
|
}
|
|
473
436
|
|
|
474
|
-
//#endregion
|
|
475
|
-
//#region src/helpers/assignIf.ts
|
|
476
437
|
/**
|
|
477
438
|
* The assignIf is a shorthand for conditional destructuring assignment.
|
|
478
439
|
* It allows to apply multiple rules to a field conditionally.
|
|
@@ -494,8 +455,6 @@ function assignIf(_condition, rules) {
|
|
|
494
455
|
});
|
|
495
456
|
}
|
|
496
457
|
|
|
497
|
-
//#endregion
|
|
498
|
-
//#region src/rules/alpha.ts
|
|
499
458
|
const alphaRegex = /^[a-zA-Z]*$/;
|
|
500
459
|
const alphaSymbolRegex = /^[\w.]+$/;
|
|
501
460
|
/**
|
|
@@ -513,8 +472,6 @@ const alpha = createRule({
|
|
|
513
472
|
message: "The value is not alphabetical"
|
|
514
473
|
});
|
|
515
474
|
|
|
516
|
-
//#endregion
|
|
517
|
-
//#region src/rules/alphaNum.ts
|
|
518
475
|
const alphaNumRegex = /^[a-zA-Z0-9]*$/;
|
|
519
476
|
const alphaNumSymbolRegex = /^[a-zA-Z0-9_]*$/;
|
|
520
477
|
/**
|
|
@@ -532,8 +489,6 @@ const alphaNum = createRule({
|
|
|
532
489
|
message: "The value must be alpha-numeric"
|
|
533
490
|
});
|
|
534
491
|
|
|
535
|
-
//#endregion
|
|
536
|
-
//#region src/rules/between.ts
|
|
537
492
|
/**
|
|
538
493
|
* Checks if a number is in specified bounds. min and max are both inclusive.
|
|
539
494
|
*
|
|
@@ -560,8 +515,6 @@ const between = createRule({
|
|
|
560
515
|
}
|
|
561
516
|
});
|
|
562
517
|
|
|
563
|
-
//#endregion
|
|
564
|
-
//#region src/rules/boolean.ts
|
|
565
518
|
/**
|
|
566
519
|
* Requires a value to be a native boolean type
|
|
567
520
|
*
|
|
@@ -576,8 +529,6 @@ const boolean = createRule({
|
|
|
576
529
|
message: "The value must be a native boolean"
|
|
577
530
|
});
|
|
578
531
|
|
|
579
|
-
//#endregion
|
|
580
|
-
//#region src/rules/checked.ts
|
|
581
532
|
/**
|
|
582
533
|
* Requires a boolean value to be true. This is useful for checkbox inputs.
|
|
583
534
|
*/
|
|
@@ -590,8 +541,6 @@ const checked = createRule({
|
|
|
590
541
|
message: "The field must be checked"
|
|
591
542
|
});
|
|
592
543
|
|
|
593
|
-
//#endregion
|
|
594
|
-
//#region src/rules/contains.ts
|
|
595
544
|
/**
|
|
596
545
|
* Checks if the string contains the specified substring.
|
|
597
546
|
*
|
|
@@ -608,8 +557,6 @@ const contains = createRule({
|
|
|
608
557
|
}
|
|
609
558
|
});
|
|
610
559
|
|
|
611
|
-
//#endregion
|
|
612
|
-
//#region src/rules/date.ts
|
|
613
560
|
/**
|
|
614
561
|
* Requires a value to be a native Date constructor
|
|
615
562
|
*
|
|
@@ -624,8 +571,6 @@ const date = createRule({
|
|
|
624
571
|
message: "The value must be a native Date constructor"
|
|
625
572
|
});
|
|
626
573
|
|
|
627
|
-
//#endregion
|
|
628
|
-
//#region src/utils/getLocale.util.ts
|
|
629
574
|
function getUserLocale() {
|
|
630
575
|
if (navigator.languages != void 0) return navigator.languages[0];
|
|
631
576
|
return navigator.language;
|
|
@@ -635,8 +580,6 @@ function formatLocaleDate(date$1) {
|
|
|
635
580
|
return "?";
|
|
636
581
|
}
|
|
637
582
|
|
|
638
|
-
//#endregion
|
|
639
|
-
//#region src/rules/dateAfter.ts
|
|
640
583
|
/**
|
|
641
584
|
* Checks if the date is after the given parameter.
|
|
642
585
|
*
|
|
@@ -668,8 +611,6 @@ const dateAfter = createRule({
|
|
|
668
611
|
}
|
|
669
612
|
});
|
|
670
613
|
|
|
671
|
-
//#endregion
|
|
672
|
-
//#region src/rules/dateBefore.ts
|
|
673
614
|
/**
|
|
674
615
|
* Checks if the date is before the given parameter.
|
|
675
616
|
*
|
|
@@ -701,8 +642,6 @@ const dateBefore = createRule({
|
|
|
701
642
|
}
|
|
702
643
|
});
|
|
703
644
|
|
|
704
|
-
//#endregion
|
|
705
|
-
//#region src/rules/dateBetween.ts
|
|
706
645
|
/**
|
|
707
646
|
* Checks if the date falls between the specified bounds.
|
|
708
647
|
*
|
|
@@ -723,8 +662,6 @@ const dateBetween = createRule({
|
|
|
723
662
|
}
|
|
724
663
|
});
|
|
725
664
|
|
|
726
|
-
//#endregion
|
|
727
|
-
//#region src/rules/decimal.ts
|
|
728
665
|
const decimalRegex = /^[-]?\d*(\.\d+)?$/;
|
|
729
666
|
/**
|
|
730
667
|
* Allows positive and negative decimal numbers.
|
|
@@ -738,8 +675,6 @@ const decimal = createRule({
|
|
|
738
675
|
message: "The value must be decimal"
|
|
739
676
|
});
|
|
740
677
|
|
|
741
|
-
//#endregion
|
|
742
|
-
//#region src/rules/email.ts
|
|
743
678
|
const 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;
|
|
744
679
|
/**
|
|
745
680
|
* Validates email addresses. Always verify on the server to ensure the address is real and not already in use.
|
|
@@ -753,8 +688,6 @@ const email = createRule({
|
|
|
753
688
|
message: "The value must be an valid email address"
|
|
754
689
|
});
|
|
755
690
|
|
|
756
|
-
//#endregion
|
|
757
|
-
//#region src/rules/endsWith.ts
|
|
758
691
|
/**
|
|
759
692
|
* Checks if the string ends with the specified substring.
|
|
760
693
|
*
|
|
@@ -771,8 +704,6 @@ const endsWith = createRule({
|
|
|
771
704
|
}
|
|
772
705
|
});
|
|
773
706
|
|
|
774
|
-
//#endregion
|
|
775
|
-
//#region src/rules/exactLength.ts
|
|
776
707
|
/**
|
|
777
708
|
* Requires the input value to have a strict specified length, inclusive. Works with arrays, objects and strings.
|
|
778
709
|
*
|
|
@@ -793,8 +724,6 @@ const exactLength = createRule({
|
|
|
793
724
|
}
|
|
794
725
|
});
|
|
795
726
|
|
|
796
|
-
//#endregion
|
|
797
|
-
//#region src/rules/exactValue.ts
|
|
798
727
|
/**
|
|
799
728
|
* Requires a field to have a strict numeric value.
|
|
800
729
|
*/
|
|
@@ -813,8 +742,6 @@ const exactValue = createRule({
|
|
|
813
742
|
}
|
|
814
743
|
});
|
|
815
744
|
|
|
816
|
-
//#endregion
|
|
817
|
-
//#region src/rules/hexadecimal.ts
|
|
818
745
|
const hexadecimalRegex = /^[a-fA-F0-9]*$/;
|
|
819
746
|
/**
|
|
820
747
|
* Allows only hexadecimal values.
|
|
@@ -828,8 +755,6 @@ const hexadecimal = createRule({
|
|
|
828
755
|
message: "The value must be hexadecimal"
|
|
829
756
|
});
|
|
830
757
|
|
|
831
|
-
//#endregion
|
|
832
|
-
//#region src/rules/integer.ts
|
|
833
758
|
const integerRegex = /(^[0-9]*$)|(^-[0-9]+$)/;
|
|
834
759
|
/**
|
|
835
760
|
* Allows only integers (positive and negative).
|
|
@@ -843,8 +768,6 @@ const integer = createRule({
|
|
|
843
768
|
message: "The value must be an integer"
|
|
844
769
|
});
|
|
845
770
|
|
|
846
|
-
//#endregion
|
|
847
|
-
//#region src/rules/ipv4Address.ts
|
|
848
771
|
function nibbleValid(nibble) {
|
|
849
772
|
if (nibble.length > 3 || nibble.length === 0) return false;
|
|
850
773
|
if (nibble[0] === "0" && nibble !== "0") return false;
|
|
@@ -866,8 +789,6 @@ const ipv4Address = createRule({
|
|
|
866
789
|
message: "The value is not a valid IPv4 address"
|
|
867
790
|
});
|
|
868
791
|
|
|
869
|
-
//#endregion
|
|
870
|
-
//#region src/rules/literal.ts
|
|
871
792
|
/**
|
|
872
793
|
* Allow only one possible literal value
|
|
873
794
|
*/
|
|
@@ -878,8 +799,6 @@ function literal(literal$1) {
|
|
|
878
799
|
}, [computed(() => toValue(literal$1))]), ({ $params: [literal$2] }) => `Value should be ${literal$2}.`);
|
|
879
800
|
}
|
|
880
801
|
|
|
881
|
-
//#endregion
|
|
882
|
-
//#region src/rules/macAddress.ts
|
|
883
802
|
/**
|
|
884
803
|
* Validates MAC addresses. Call as a function to specify a custom separator (e.g., ':' or an empty string for 00ff1122334455).
|
|
885
804
|
*
|
|
@@ -897,8 +816,6 @@ const macAddress = createRule({
|
|
|
897
816
|
});
|
|
898
817
|
const hexValid = (hex) => hex.toLowerCase().match(/^[0-9a-f]{2}$/);
|
|
899
818
|
|
|
900
|
-
//#endregion
|
|
901
|
-
//#region src/rules/maxLength.ts
|
|
902
819
|
/**
|
|
903
820
|
* Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.
|
|
904
821
|
*
|
|
@@ -923,8 +840,6 @@ const maxLength = createRule({
|
|
|
923
840
|
}
|
|
924
841
|
});
|
|
925
842
|
|
|
926
|
-
//#endregion
|
|
927
|
-
//#region src/rules/maxValue.ts
|
|
928
843
|
/**
|
|
929
844
|
* Requires a field to have a specified maximum numeric value.
|
|
930
845
|
*
|
|
@@ -950,8 +865,6 @@ const maxValue = createRule({
|
|
|
950
865
|
}
|
|
951
866
|
});
|
|
952
867
|
|
|
953
|
-
//#endregion
|
|
954
|
-
//#region src/rules/minLength.ts
|
|
955
868
|
/**
|
|
956
869
|
* Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.
|
|
957
870
|
*
|
|
@@ -976,8 +889,6 @@ const minLength = createRule({
|
|
|
976
889
|
}
|
|
977
890
|
});
|
|
978
891
|
|
|
979
|
-
//#endregion
|
|
980
|
-
//#region src/rules/minValue.ts
|
|
981
892
|
/**
|
|
982
893
|
* Requires a field to have a specified minimum numeric value.
|
|
983
894
|
*
|
|
@@ -1003,8 +914,6 @@ const minValue = createRule({
|
|
|
1003
914
|
}
|
|
1004
915
|
});
|
|
1005
916
|
|
|
1006
|
-
//#endregion
|
|
1007
|
-
//#region src/rules/nativeEnum.ts
|
|
1008
917
|
function getValidEnumValues(obj) {
|
|
1009
918
|
const validKeys = Object.keys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
1010
919
|
const filtered = {};
|
|
@@ -1021,8 +930,6 @@ function nativeEnum(enumLike) {
|
|
|
1021
930
|
}, [computed(() => toValue(enumLike))]), ({ $params: [enumLike$1] }) => `The value should be one of those options: ${Object.values(enumLike$1).join(", ")}.`);
|
|
1022
931
|
}
|
|
1023
932
|
|
|
1024
|
-
//#endregion
|
|
1025
|
-
//#region src/rules/number.ts
|
|
1026
933
|
/**
|
|
1027
934
|
* Requires a value to be a native number type
|
|
1028
935
|
*
|
|
@@ -1037,8 +944,6 @@ const number = createRule({
|
|
|
1037
944
|
message: "The value must be a native number"
|
|
1038
945
|
});
|
|
1039
946
|
|
|
1040
|
-
//#endregion
|
|
1041
|
-
//#region src/rules/numeric.ts
|
|
1042
947
|
const numericRegex = /^\d*(\.\d+)?$/;
|
|
1043
948
|
/**
|
|
1044
949
|
* Allows only numeric values (including numeric strings).
|
|
@@ -1052,8 +957,6 @@ const numeric = createRule({
|
|
|
1052
957
|
message: "The value must be numeric"
|
|
1053
958
|
});
|
|
1054
959
|
|
|
1055
|
-
//#endregion
|
|
1056
|
-
//#region src/rules/oneOf.ts
|
|
1057
960
|
/**
|
|
1058
961
|
* Allow only one of the values from a fixed Array of possible entries.
|
|
1059
962
|
*/
|
|
@@ -1066,8 +969,6 @@ const oneOf = createRule({
|
|
|
1066
969
|
message: ({ $params: [options] }) => `The value should be one of those options: ${options.join(", ")}.`
|
|
1067
970
|
});
|
|
1068
971
|
|
|
1069
|
-
//#endregion
|
|
1070
|
-
//#region src/rules/regex.ts
|
|
1071
972
|
/**
|
|
1072
973
|
* Checks if the value matches one or more regular expressions.
|
|
1073
974
|
*/
|
|
@@ -1080,8 +981,6 @@ const regex = createRule({
|
|
|
1080
981
|
message: "The value does not match the required pattern"
|
|
1081
982
|
});
|
|
1082
983
|
|
|
1083
|
-
//#endregion
|
|
1084
|
-
//#region src/rules/required.ts
|
|
1085
984
|
/**
|
|
1086
985
|
* Requires non-empty data. Checks for empty arrays and strings containing only whitespaces.
|
|
1087
986
|
*/
|
|
@@ -1093,8 +992,6 @@ const required = createRule({
|
|
|
1093
992
|
message: "This field is required"
|
|
1094
993
|
});
|
|
1095
994
|
|
|
1096
|
-
//#endregion
|
|
1097
|
-
//#region src/rules/requiredIf.ts
|
|
1098
995
|
/**
|
|
1099
996
|
* Requires non-empty data, only if provided data property, ref, or a function resolves to true.
|
|
1100
997
|
*
|
|
@@ -1112,8 +1009,6 @@ const requiredIf = createRule({
|
|
|
1112
1009
|
}
|
|
1113
1010
|
});
|
|
1114
1011
|
|
|
1115
|
-
//#endregion
|
|
1116
|
-
//#region src/rules/requiredUnless.ts
|
|
1117
1012
|
/**
|
|
1118
1013
|
* Requires non-empty data, only if provided data property, ref, or a function resolves to false.
|
|
1119
1014
|
*
|
|
@@ -1131,8 +1026,6 @@ const requiredUnless = createRule({
|
|
|
1131
1026
|
}
|
|
1132
1027
|
});
|
|
1133
1028
|
|
|
1134
|
-
//#endregion
|
|
1135
|
-
//#region src/rules/sameAs.ts
|
|
1136
1029
|
/**
|
|
1137
1030
|
* Checks if the value matches the specified property or ref.
|
|
1138
1031
|
*/
|
|
@@ -1147,8 +1040,6 @@ const sameAs = createRule({
|
|
|
1147
1040
|
}
|
|
1148
1041
|
});
|
|
1149
1042
|
|
|
1150
|
-
//#endregion
|
|
1151
|
-
//#region src/rules/startsWith.ts
|
|
1152
1043
|
/**
|
|
1153
1044
|
* Checks if the string starts with the specified substring.
|
|
1154
1045
|
*
|
|
@@ -1161,12 +1052,10 @@ const startsWith = createRule({
|
|
|
1161
1052
|
return true;
|
|
1162
1053
|
},
|
|
1163
1054
|
message({ $params: [part] }) {
|
|
1164
|
-
return `The value must
|
|
1055
|
+
return `The value must start with ${part}`;
|
|
1165
1056
|
}
|
|
1166
1057
|
});
|
|
1167
1058
|
|
|
1168
|
-
//#endregion
|
|
1169
|
-
//#region src/rules/string.ts
|
|
1170
1059
|
/**
|
|
1171
1060
|
* Requires a value to be a native string type
|
|
1172
1061
|
*
|
|
@@ -1181,8 +1070,6 @@ const string = createRule({
|
|
|
1181
1070
|
message: "The value must be a string"
|
|
1182
1071
|
});
|
|
1183
1072
|
|
|
1184
|
-
//#endregion
|
|
1185
|
-
//#region src/rules/type.ts
|
|
1186
1073
|
/**
|
|
1187
1074
|
* Define the input type of a rule. No runtime validation.
|
|
1188
1075
|
*
|
|
@@ -1192,8 +1079,6 @@ function type() {
|
|
|
1192
1079
|
return (() => true);
|
|
1193
1080
|
}
|
|
1194
1081
|
|
|
1195
|
-
//#endregion
|
|
1196
|
-
//#region src/rules/url.ts
|
|
1197
1082
|
/**
|
|
1198
1083
|
* Regex taken from {@link https://gist.github.com/dperini/729294}
|
|
1199
1084
|
*/
|
|
@@ -1210,5 +1095,4 @@ const url = createRule({
|
|
|
1210
1095
|
message: "The value is not a valid URL address"
|
|
1211
1096
|
});
|
|
1212
1097
|
|
|
1213
|
-
//#endregion
|
|
1214
1098
|
export { alpha, alphaNum, and, applyIf, assignIf, between, boolean, checked, contains, date, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, hexadecimal, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, url, withAsync, withMessage, withParams, withTooltip };
|
package/dist/regle-rules.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{InternalRuleType as e,createRule as t,unwrapRuleParameters as n}from"@regle/core";import{computed as r,toValue as i,unref as a}from"vue";function o(n,r){let i,a,o,s;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s}=n;let c=t({type:i,validator:a,active:o,message:r}),l=[...s??[]];if(c._params=l,c._message_patched=!0,typeof c==`function`){if(s!=null){let e=c(...l);return e._message_patched=!0,e}return c}else return c}function s(n,r){let i,a,o,s,c;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_message:c}=n;let l=t({type:i,validator:a,active:o,message:c,tooltip:r}),u=[...s??[]];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 c(n,r){let i,a,o=[],s=``;typeof n==`function`?(a=async(e,...t)=>n(e,...t),o=[r]):({_type:i,_message:s}=n,o=o=n._params?.concat(r),a=async(...e)=>n.validator(e));let c=t({type:i??e.Async,validator:a,message:s,async:!0});return c._params=c._params?.concat(o),c(...r??[])}function l(n,r){let i,a,o=[],s=``;typeof n==`function`?(e.Inline,a=(e,...t)=>n(e,...t),o=[r]):({_type:i,validator:a,_message:s}=n,o=o=n._params?.concat(r));let c=t({type:e.Inline,validator:a,message:s});return c._params=c._params?.concat(o),c(...r)}function u(r,i){let a,o,s=[],c=``;typeof i==`function`?(a=e.Inline,o=i,s=[r]):({_type:a,validator:o,_message:c}=i,s=i._params?.concat([r]));function l(e,...t){let[i]=n([r]);return i?o(e,...t):!0}function u(){let[e]=n([r]);return e}let d=t({type:a,validator:l,active:u,message:c}),f=[...s??[]];return d._params=f,typeof d==`function`?d(...f):d}function d(e){return e?.constructor?.name==`File`||e?.constructor?.name==`FileList`}function f(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):d(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function p(e){if(f(e))return!1;try{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}catch{return!1}}function m(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 h(e,t=!0){return!f(typeof e==`string`?e.trim():e,t)}function g(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function _(e,...t){if(f(e))return!0;let n=typeof e==`number`?e.toString():e;return t.every(e=>(e.lastIndex=0,e.test(n)))}function v(e){let t=a(e);return Array.isArray(t)?t.length:typeof t==`object`?Object.keys(t).length:typeof t==`number`?isNaN(t)?0:t:String(t).length}function y(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function b(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e?.some(e=>typeof e!=`boolean`)?{$valid:e.every(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.every(e=>!!e)}let o;o=e.length?n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)):e=>!1;let s=t({type:`and`,validator:o,message:`The value does not match all of the provided validators`}),c=[...r??[]];return s._params=c,typeof s==`function`?s(...c):s}function ee(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>typeof e==`function`?null:e._params).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e.some(e=>typeof e!=`boolean`)?{$valid:e.some(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.some(e=>!!e)}let o=t({type:`or`,validator:n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)),message:`The value does not match any of the provided validators`}),s=[...r??[]];return o._params=s,typeof o==`function`?o(...s):o}function x(e,n){let r,i,a,o,s;typeof e==`function`?(i=e,s=e.constructor.name===`AsyncFunction`):({_type:r,validator:i,_params:o}=e,s=e._async),a=s?async(e,...t)=>h(e)?!await i(e,...t):!0:(e,...t)=>h(e)?!i(e,...t):!0;let c=t({type:`not`,validator:a,message:n??`Error`}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function S(e,t){return r(()=>i(e)?t:{})}const C=/^[a-zA-Z]*$/,w=/^[\w.]+$/,T=t({type:`alpha`,validator(e,t){return f(e)?!0:t?.allowSymbols?_(e,w):_(e,C)},message:`The value is not alphabetical`}),E=/^[a-zA-Z0-9]*$/,D=/^[a-zA-Z0-9_]*$/,O=t({type:`alphaNum`,validator(e,t){return f(e)?!0:t?.allowSymbols?_(e,D):_(e,E)},message:`The value must be alpha-numeric`}),k=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(h(e)&&h(t)&&h(n)){let r=y(e),a=y(t),o=y(n);return g(r)&&g(a)&&g(o)?i?r>=a&&r<=o:r>a&&r<o:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${n}`),!1)}return!0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`}),A=t({type:`boolean`,validator:e=>h(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),j=t({type:`checked`,validator:e=>h(e)?e===!0:!0,message:`The field must be checked`}),M=t({type:`contains`,validator(e,t){return h(e)&&h(t)?e.includes(t):!0},message({$params:[e]}){return`The value must contain ${e}`}}),N=t({type:`date`,validator:e=>h(e)?e instanceof Date:!0,message:`The value must be a native Date constructor`});function P(){return navigator.languages==null?navigator.language:navigator.languages[0]}function F(e){return e?new Intl.DateTimeFormat(P(),{dateStyle:`short`}).format(new Date(e)):`?`}const I=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e)&&h(t)?p(e)&&p(t)?(r?m(e).getTime()>=m(t).getTime():m(e).getTime()>m(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 ${F(e)}`}),L=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e)&&h(t)?p(e)&&p(t)?(r?m(e).getTime()<=m(t).getTime():m(e).getTime()<m(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 ${F(e)}`}),R=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return p(e)&&p(t)&&p(n)?i?m(e).getTime()>=m(t).getTime()&&m(e).getTime()<=m(n).getTime():m(e).getTime()>m(t).getTime()&&m(e).getTime()<m(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${F(e)} and ${F(t)}`}),z=/^[-]?\d*(\.\d+)?$/,B=t({type:`decimal`,validator(e){return f(e)?!0:_(e,z)},message:`The value must be decimal`}),V=/^(?:[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,H=t({type:`email`,validator(e){return f(e)?!0:_(e,V)},message:`The value must be an valid email address`}),U=t({type:`endsWith`,validator(e,t){return h(e)&&h(t)?e.endsWith(t):!0},message({$params:[e]}){return`The value must end with ${e}`}}),W=t({type:`exactLength`,validator:(e,t)=>h(e,!1)&&h(t)?g(t)?v(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$params:[e]})=>`The value should be exactly ${e} characters long`}),te=t({type:`exactValue`,validator:(e,t)=>h(e)&&h(t)?g(t)&&!isNaN(y(e))?y(e)===t:(console.warn(`[exactValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),G=/^[a-fA-F0-9]*$/,K=t({type:`hexadecimal`,validator(e){return f(e)?!0:_(e,G)},message:`The value must be hexadecimal`}),q=/(^[0-9]*$)|(^-[0-9]+$)/,J=t({type:`integer`,validator(e){return f(e)?!0:_(e,q)},message:`The value must be an integer`});function Y(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 X=t({type:`ipv4Address`,validator(e){if(f(e))return!0;if(typeof e!=`string`)return!1;let t=e.split(`.`);return t.length===4&&t.every(Y)},message:`The value is not a valid IPv4 address`});function Z(e){return o(l((e,t)=>h(e)&&h(t)?t===e:!0,[r(()=>i(e))]),({$params:[e]})=>`Value should be ${e}.`)}const Q=t({type:`macAddress`,validator(e,t=`:`){if(f(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(ne)},message:`The value is not a valid MAC Address`}),ne=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),re=t({type:`maxLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e,!1)&&h(t)?g(t)?r?v(e)<=t:v(e)<t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!1):!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`}),ie=t({type:`maxValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e)&&h(t)?!isNaN(y(e))&&!isNaN(y(t))?r?y(e)<=y(t):y(e)<y(t):(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!1):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}}),ae=t({type:`minLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e,!1)&&h(t)?g(t)?r?v(e)>=t:v(e)>t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`The list should have at least ${t} items`:`The value length should be at least ${t}`}),oe=t({type:`minValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e)&&h(t)?!isNaN(y(e))&&!isNaN(y(t))?r?y(e)>=y(t):y(e)>y(t):(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!1):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});function se(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 ce(e){return o(l((e,t)=>h(e)&&!f(t)?se(t).includes(e):!0,[r(()=>i(e))]),({$params:[e]})=>`The value should be one of those options: ${Object.values(e).join(`, `)}.`)}const le=t({type:`number`,validator:e=>h(e)?g(e):!0,message:`The value must be a native number`}),ue=/^\d*(\.\d+)?$/,de=t({type:`numeric`,validator(e){return f(e)?!0:_(e,ue)},message:`The value must be numeric`}),fe=t({type:`oneOf`,validator(e,t){return h(e)&&h(t,!1)?t.includes(e):!0},message:({$params:[e]})=>`The value should be one of those options: ${e.join(`, `)}.`}),pe=t({type:`regex`,validator(e,t){return h(e)?_(e,...Array.isArray(t)?t:[t]):!0},message:`The value does not match the required pattern`}),$=t({type:`required`,validator:e=>h(e),message:`This field is required`}),me=t({type:`required`,validator(e,t){return t?h(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),he=t({type:`required`,validator(e,t){return t?!0:h(e)},message:`This field is required`,active({$params:[e]}){return!e}}),ge=t({type:`sameAs`,validator(e,t,n){return f(e)?!0:e===t},message({$params:[e,t=`other`]}){return`The value must be equal to the ${t} value`}}),_e=t({type:`startsWith`,validator(e,t){return h(e)&&h(t)?e.startsWith(t):!0},message({$params:[e]}){return`The value must end with ${e}`}}),ve=t({type:`string`,validator:e=>h(e)?typeof e==`string`:!0,message:`The value must be a string`});function ye(){return(()=>!0)}const be=/^(?:(?:(?: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,xe=t({type:`url`,validator(e){return f(e)?!0:_(e,be)},message:`The value is not a valid URL address`});export{T as alpha,O as alphaNum,b as and,u as applyIf,S as assignIf,k as between,A as boolean,j as checked,M as contains,N as date,I as dateAfter,L as dateBefore,R as dateBetween,B as decimal,H as email,U as endsWith,W as exactLength,te as exactValue,v as getSize,K as hexadecimal,J as integer,X as ipv4Address,p as isDate,f as isEmpty,h as isFilled,g as isNumber,Z as literal,Q as macAddress,_ as matchRegex,re as maxLength,ie as maxValue,ae as minLength,oe as minValue,ce as nativeEnum,x as not,le as number,de as numeric,fe as oneOf,ee as or,pe as regex,$ as required,me as requiredIf,he as requiredUnless,ge as sameAs,_e as startsWith,ve as string,m as toDate,y as toNumber,ye as type,xe as url,c as withAsync,o as withMessage,l as withParams,s as withTooltip};
|
|
1
|
+
import{InternalRuleType as e,createRule as t,unwrapRuleParameters as n}from"@regle/core";import{computed as r,toValue as i,unref as a}from"vue";function o(n,r){let i,a,o,s;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s}=n;let c=t({type:i,validator:a,active:o,message:r}),l=[...s??[]];if(c._params=l,c._message_patched=!0,typeof c==`function`){if(s!=null){let e=c(...l);return e._message_patched=!0,e}return c}else return c}function s(n,r){let i,a,o,s,c;typeof n==`function`&&!(`_validator`in n)?(i=e.Inline,a=n):{_type:i,validator:a,_active:o,_params:s,_message:c}=n;let l=t({type:i,validator:a,active:o,message:c,tooltip:r}),u=[...s??[]];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 c(n,r){let i,a,o=[],s=``;typeof n==`function`?(a=async(e,...t)=>n(e,...t),o=[r]):({_type:i,_message:s}=n,o=o=n._params?.concat(r),a=async(...e)=>n.validator(e));let c=t({type:i??e.Async,validator:a,message:s,async:!0});return c._params=c._params?.concat(o),c(...r??[])}function l(n,r){let i,a,o=[],s=``;typeof n==`function`?(e.Inline,a=(e,...t)=>n(e,...t),o=[r]):({_type:i,validator:a,_message:s}=n,o=o=n._params?.concat(r));let c=t({type:e.Inline,validator:a,message:s});return c._params=c._params?.concat(o),c(...r)}function u(r,i){let a,o,s=[],c=``;typeof i==`function`?(a=e.Inline,o=i,s=[r]):({_type:a,validator:o,_message:c}=i,s=i._params?.concat([r]));function l(e,...t){let[i]=n([r]);return i?o(e,...t):!0}function u(){let[e]=n([r]);return e}let d=t({type:a,validator:l,active:u,message:c}),f=[...s??[]];return d._params=f,typeof d==`function`?d(...f):d}function d(e){return e?.constructor?.name==`File`||e?.constructor?.name==`FileList`}function f(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):d(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}function p(e){if(f(e))return!1;try{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}catch{return!1}}function m(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 h(e,t=!0){return!f(typeof e==`string`?e.trim():e,t)}function g(e){return e==null?!1:typeof e==`number`?!isNaN(e):!1}function _(e,...t){if(f(e))return!0;let n=typeof e==`number`?e.toString():e;return t.every(e=>(e.lastIndex=0,e.test(n)))}function v(e){let t=a(e);return Array.isArray(t)?t.length:typeof t==`object`?Object.keys(t).length:typeof t==`number`?isNaN(t)?0:t:String(t).length}function y(e){return typeof e==`number`?e:e==null?NaN:typeof e==`string`&&e.trim()===e?+e:NaN}function b(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>{if(typeof e==`function`)return null;{let t=e._params;return t?.length?t:[]}}).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e?.some(e=>typeof e!=`boolean`)?{$valid:e.every(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.every(e=>!!e)}let o;o=e.length?n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)):e=>!1;let s=t({type:`and`,validator:o,message:`The value does not match all of the provided validators`}),c=[...r??[]];return s._params=c,typeof s==`function`?s(...c):s}function ee(...e){let n=e.some(e=>typeof e==`function`?e.constructor.name===`AsyncFunction`:e._async),r=e.map(e=>typeof e==`function`?null:e._params).flat().filter(e=>!!e);function i(e,t,...n){let r=[],i=0;for(let a of e)if(typeof a==`function`)r.push(a(t)),i++;else{let e=a._params?.length??0;r.push(a.validator(t,...n.slice(i,e))),e&&(i+=e)}return r}function a(e){return e.some(e=>typeof e!=`boolean`)?{$valid:e.some(e=>typeof e==`boolean`?!!e:e.$valid),...e.reduce((e,t)=>{if(typeof t==`boolean`)return e;let{$valid:n,...r}=t;return{...e,...r}},{})}:e.some(e=>!!e)}let o=t({type:`or`,validator:n?async(t,...n)=>a(await Promise.all(i(e,t,...n))):(t,...n)=>a(i(e,t,...n)),message:`The value does not match any of the provided validators`}),s=[...r??[]];return o._params=s,typeof o==`function`?o(...s):o}function x(e,n){let r,i,a,o,s;typeof e==`function`?(i=e,s=e.constructor.name===`AsyncFunction`):({_type:r,validator:i,_params:o}=e,s=e._async),a=s?async(e,...t)=>h(e)?!await i(e,...t):!0:(e,...t)=>h(e)?!i(e,...t):!0;let c=t({type:`not`,validator:a,message:n??`Error`}),l=[...o??[]];return c._params=l,typeof c==`function`?c(...l):c}function S(e,t){return r(()=>i(e)?t:{})}const C=/^[a-zA-Z]*$/,w=/^[\w.]+$/,T=t({type:`alpha`,validator(e,t){return f(e)?!0:t?.allowSymbols?_(e,w):_(e,C)},message:`The value is not alphabetical`}),E=/^[a-zA-Z0-9]*$/,D=/^[a-zA-Z0-9_]*$/,O=t({type:`alphaNum`,validator(e,t){return f(e)?!0:t?.allowSymbols?_(e,D):_(e,E)},message:`The value must be alpha-numeric`}),k=t({type:`between`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};if(h(e)&&h(t)&&h(n)){let r=y(e),a=y(t),o=y(n);return g(r)&&g(a)&&g(o)?i?r>=a&&r<=o:r>a&&r<o:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${n}`),!1)}return!0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`}),A=t({type:`boolean`,validator:e=>h(e)?typeof e==`boolean`:!0,message:`The value must be a native boolean`}),j=t({type:`checked`,validator:e=>h(e)?e===!0:!0,message:`The field must be checked`}),M=t({type:`contains`,validator(e,t){return h(e)&&h(t)?e.includes(t):!0},message({$params:[e]}){return`The value must contain ${e}`}}),N=t({type:`date`,validator:e=>h(e)?e instanceof Date:!0,message:`The value must be a native Date constructor`});function P(){return navigator.languages==null?navigator.language:navigator.languages[0]}function F(e){return e?new Intl.DateTimeFormat(P(),{dateStyle:`short`}).format(new Date(e)):`?`}const I=t({type:`dateAfter`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e)&&h(t)?p(e)&&p(t)?(r?m(e).getTime()>=m(t).getTime():m(e).getTime()>m(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 ${F(e)}`}),L=t({type:`dateBefore`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e)&&h(t)?p(e)&&p(t)?(r?m(e).getTime()<=m(t).getTime():m(e).getTime()<m(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 ${F(e)}`}),R=t({type:`dateBetween`,validator:(e,t,n,r)=>{let{allowEqual:i=!0}=r??{};return p(e)&&p(t)&&p(n)?i?m(e).getTime()>=m(t).getTime()&&m(e).getTime()<=m(n).getTime():m(e).getTime()>m(t).getTime()&&m(e).getTime()<m(n).getTime():!0},message:({$params:[e,t]})=>`The date must be between ${F(e)} and ${F(t)}`}),z=/^[-]?\d*(\.\d+)?$/,B=t({type:`decimal`,validator(e){return f(e)?!0:_(e,z)},message:`The value must be decimal`}),V=/^(?:[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,H=t({type:`email`,validator(e){return f(e)?!0:_(e,V)},message:`The value must be an valid email address`}),U=t({type:`endsWith`,validator(e,t){return h(e)&&h(t)?e.endsWith(t):!0},message({$params:[e]}){return`The value must end with ${e}`}}),W=t({type:`exactLength`,validator:(e,t)=>h(e,!1)&&h(t)?g(t)?v(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$params:[e]})=>`The value should be exactly ${e} characters long`}),te=t({type:`exactValue`,validator:(e,t)=>h(e)&&h(t)?g(t)&&!isNaN(y(e))?y(e)===t:(console.warn(`[exactValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The value must be equal to ${e}`}),G=/^[a-fA-F0-9]*$/,K=t({type:`hexadecimal`,validator(e){return f(e)?!0:_(e,G)},message:`The value must be hexadecimal`}),q=/(^[0-9]*$)|(^-[0-9]+$)/,J=t({type:`integer`,validator(e){return f(e)?!0:_(e,q)},message:`The value must be an integer`});function Y(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 X=t({type:`ipv4Address`,validator(e){if(f(e))return!0;if(typeof e!=`string`)return!1;let t=e.split(`.`);return t.length===4&&t.every(Y)},message:`The value is not a valid IPv4 address`});function Z(e){return o(l((e,t)=>h(e)&&h(t)?t===e:!0,[r(()=>i(e))]),({$params:[e]})=>`Value should be ${e}.`)}const Q=t({type:`macAddress`,validator(e,t=`:`){if(f(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(ne)},message:`The value is not a valid MAC Address`}),ne=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/),re=t({type:`maxLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e,!1)&&h(t)?g(t)?r?v(e)<=t:v(e)<t:(console.warn(`[maxLength] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!1):!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`This list should have maximum ${t} items`:`The value length should not exceed ${t}`}),ie=t({type:`maxValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e)&&h(t)?!isNaN(y(e))&&!isNaN(y(t))?r?y(e)<=y(t):y(e)<y(t):(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!1):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be less than or equal to ${e}`:`The value must be less than ${e}`}}),ae=t({type:`minLength`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e,!1)&&h(t)?g(t)?r?v(e)>=t:v(e)>t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0},message:({$value:e,$params:[t]})=>Array.isArray(e)?`The list should have at least ${t} items`:`The value length should be at least ${t}`}),oe=t({type:`minValue`,validator:(e,t,n)=>{let{allowEqual:r=!0}=n??{};return h(e)&&h(t)?!isNaN(y(e))&&!isNaN(y(t))?r?y(e)>=y(t):y(e)>y(t):(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!1):!0},message:({$params:[e,t]})=>{let{allowEqual:n=!0}=t??{};return n?`The value must be greater than or equal to ${e}`:`The value must be greater than ${e}`}});function se(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 ce(e){return o(l((e,t)=>h(e)&&!f(t)?se(t).includes(e):!0,[r(()=>i(e))]),({$params:[e]})=>`The value should be one of those options: ${Object.values(e).join(`, `)}.`)}const le=t({type:`number`,validator:e=>h(e)?g(e):!0,message:`The value must be a native number`}),ue=/^\d*(\.\d+)?$/,de=t({type:`numeric`,validator(e){return f(e)?!0:_(e,ue)},message:`The value must be numeric`}),fe=t({type:`oneOf`,validator(e,t){return h(e)&&h(t,!1)?t.includes(e):!0},message:({$params:[e]})=>`The value should be one of those options: ${e.join(`, `)}.`}),pe=t({type:`regex`,validator(e,t){return h(e)?_(e,...Array.isArray(t)?t:[t]):!0},message:`The value does not match the required pattern`}),$=t({type:`required`,validator:e=>h(e),message:`This field is required`}),me=t({type:`required`,validator(e,t){return t?h(e):!0},message:`This field is required`,active({$params:[e]}){return e}}),he=t({type:`required`,validator(e,t){return t?!0:h(e)},message:`This field is required`,active({$params:[e]}){return!e}}),ge=t({type:`sameAs`,validator(e,t,n){return f(e)?!0:e===t},message({$params:[e,t=`other`]}){return`The value must be equal to the ${t} value`}}),_e=t({type:`startsWith`,validator(e,t){return h(e)&&h(t)?e.startsWith(t):!0},message({$params:[e]}){return`The value must start with ${e}`}}),ve=t({type:`string`,validator:e=>h(e)?typeof e==`string`:!0,message:`The value must be a string`});function ye(){return(()=>!0)}const be=/^(?:(?:(?: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,xe=t({type:`url`,validator(e){return f(e)?!0:_(e,be)},message:`The value is not a valid URL address`});export{T as alpha,O as alphaNum,b as and,u as applyIf,S as assignIf,k as between,A as boolean,j as checked,M as contains,N as date,I as dateAfter,L as dateBefore,R as dateBetween,B as decimal,H as email,U as endsWith,W as exactLength,te as exactValue,v as getSize,K as hexadecimal,J as integer,X as ipv4Address,p as isDate,f as isEmpty,h as isFilled,g as isNumber,Z as literal,Q as macAddress,_ as matchRegex,re as maxLength,ie as maxValue,ae as minLength,oe as minValue,ce as nativeEnum,x as not,le as number,de as numeric,fe as oneOf,ee as or,pe as regex,$ as required,me as requiredIf,he as requiredUnless,ge as sameAs,_e as startsWith,ve as string,m as toDate,y as toNumber,ye as type,xe as url,c as withAsync,o as withMessage,l as withParams,s as withTooltip};
|
package/package.json
CHANGED
|
@@ -1,34 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/rules",
|
|
3
|
-
"version": "1.11.0-beta.
|
|
3
|
+
"version": "1.11.0-beta.3",
|
|
4
4
|
"description": "Collection of rules and helpers for Regle",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@regle/core": "1.11.0-beta.
|
|
6
|
+
"@regle/core": "1.11.0-beta.3"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"@types/node": "22.19.
|
|
10
|
-
"@vue/reactivity": "3.5.
|
|
9
|
+
"@types/node": "22.19.1",
|
|
10
|
+
"@vue/reactivity": "3.5.24",
|
|
11
11
|
"@vue/test-utils": "2.4.6",
|
|
12
12
|
"prettier": "3.6.2",
|
|
13
|
-
"tsdown": "0.16.
|
|
13
|
+
"tsdown": "0.16.6",
|
|
14
14
|
"type-fest": "5.2.0",
|
|
15
15
|
"typescript": "5.9.3",
|
|
16
|
-
"vitest": "4.0.
|
|
17
|
-
"vue": "3.5.
|
|
18
|
-
"vue-tsc": "3.1.
|
|
16
|
+
"vitest": "4.0.13",
|
|
17
|
+
"vue": "3.5.24",
|
|
18
|
+
"vue-tsc": "3.1.5"
|
|
19
19
|
},
|
|
20
20
|
"type": "module",
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
23
|
"types": "./dist/regle-rules.d.ts",
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"development": "./dist/regle-rules.js",
|
|
28
|
-
"default": "./dist/regle-rules.js"
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
"import": "./dist/regle-rules.js"
|
|
24
|
+
"production": "./dist/regle-rules.min.js",
|
|
25
|
+
"development": "./dist/regle-rules.js",
|
|
26
|
+
"default": "./dist/regle-rules.js"
|
|
32
27
|
},
|
|
33
28
|
"./package.json": "./package.json",
|
|
34
29
|
"./dist/*": "./dist/*"
|