@regle/rules 0.5.5 โ†’ 0.5.7

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/README.md CHANGED
@@ -11,7 +11,7 @@ It's heavily inspired by Vuelidate.
11
11
 
12
12
  ## ๐Ÿ“š Documentation
13
13
 
14
- [![Documentation](https://raw.githubusercontent.com/victorgarciaesgi/regle/refs/heads/main/.github/images/redirectDoc.svg)](https://regle.vercel.app/)
14
+ [![Documentation](https://raw.githubusercontent.com/victorgarciaesgi/regle/refs/heads/main/.github/images/redirectDoc.svg)](https://reglejs.dev/)
15
15
 
16
16
  ## ๐ŸŽฎ Play with it
17
17
 
@@ -594,6 +594,22 @@ var minValue = core.createRule({
594
594
  return `The minimum value allowed is ${count}`;
595
595
  }
596
596
  });
597
+ var exactValue = core.createRule({
598
+ type: "exactValue",
599
+ validator: (value, count) => {
600
+ if (isFilled(value) && isFilled(count)) {
601
+ if (isNumber(count) && !isNaN(toNumber(value))) {
602
+ return toNumber(value) === count;
603
+ }
604
+ console.warn(`[exactValue] Value or parameter isn't a number, got value: ${value}, parameter: ${count}`);
605
+ return true;
606
+ }
607
+ return true;
608
+ },
609
+ message: ({ $params: [count] }) => {
610
+ return `The value must be equal to ${count}`;
611
+ }
612
+ });
597
613
  var exactLength = core.createRule({
598
614
  type: "exactLength",
599
615
  validator: (value, count) => {
@@ -840,6 +856,7 @@ exports.decimal = decimal;
840
856
  exports.email = email;
841
857
  exports.endsWith = endsWith;
842
858
  exports.exactLength = exactLength;
859
+ exports.exactValue = exactValue;
843
860
  exports.getSize = getSize;
844
861
  exports.integer = integer;
845
862
  exports.ipAddress = ipAddress;
@@ -1,33 +1,116 @@
1
- import { RegleRuleMetadataDefinition, InlineRuleDeclaration, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, InferRegleRule, RegleRuleWithParamsDefinition, RegleRuleDefinition, UnwrapRegleUniversalParams, ParamDecl, Maybe, FormRuleDeclaration } from '@regle/core';
2
- import { Ref, MaybeRef } from 'vue';
1
+ import { RegleRuleMetadataDefinition, InlineRuleDeclaration, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, InferRegleRule, RegleRuleWithParamsDefinition, RegleRuleDefinition, UnwrapRegleUniversalParams, Maybe, FormRuleDeclaration } from '@regle/core';
2
+ import { Ref, MaybeRefOrGetter, MaybeRef } from 'vue';
3
3
 
4
+ /**
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.
6
+ *
7
+ * ```ts
8
+ * const { r$ } = useRegle({ name: '' }, {
9
+ name: {
10
+ customRule1: withMessage((value) => !!value, "Custom Error"),
11
+ customRule2: withMessage(customRuleInlineWithMetaData, "Custom Error"),
12
+ customRule3: withMessage(
13
+ customRuleInlineWithMetaData,
14
+ ({ $value, foo }) => `Custom Error: ${$value} ${foo}`
15
+ ),
16
+ }
17
+ })
18
+ * ```
19
+ * Docs: {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withmessage}
20
+ */
4
21
  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[]>): InferRegleRule<TValue, TParams, TAsync, TReturn extends Promise<infer M> ? M : TReturn>;
5
22
  declare function withMessage<TValue extends any, TParams extends any[], TMetadata extends RegleRuleMetadataDefinition, TReturn extends TMetadata | Promise<TMetadata>, 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>;
6
23
  declare function withMessage<TValue extends any, TParams extends any[], TMetadata extends RegleRuleMetadataDefinition, TReturn extends TMetadata | Promise<TMetadata>, TAsync extends boolean>(rule: RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
7
24
 
25
+ /**
26
+ * The withTooltip wrapper allows you to display additional messages for your field that arenโ€™t necessarily errors. Tooltips are aggregated and accessible via $field.xxx.$tooltips .
27
+ */
8
28
  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>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TReturn extends Promise<infer M> ? M : TReturn>, string | string[]>): InferRegleRule<TValue, TParams, TAsync, TReturn extends Promise<infer M> ? M : TReturn>;
9
29
  declare function withTooltip<TValue extends any, TParams extends any[], TMetadata extends RegleRuleMetadataDefinition, TReturn extends TMetadata | Promise<TMetadata>, 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>;
10
30
  declare function withTooltip<TValue extends any, TParams extends any[], TMetadata extends RegleRuleMetadataDefinition, TReturn extends TMetadata | Promise<TMetadata>, TAsync extends boolean>(rule: RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
11
31
 
32
+ /**
33
+ * withAsync works like withParams, but is specifically designed for async rules that depend on external values.
34
+ *
35
+ * ```ts
36
+ *import { withAsync } from '@regle/rules';
37
+
38
+ const base = ref('foo');
39
+
40
+ const { r$ } = useRegle({ name: '' }, {
41
+ name: {
42
+ customRule: withAsync(async (value, param) => {
43
+ await someAsyncCall(param)
44
+ }, [base])
45
+ }
46
+ })
47
+ * ```
48
+ * Docs: {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withasync}
49
+ */
12
50
  declare function withAsync<TValue, TParams extends (Ref<unknown> | (() => unknown))[] = [], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = 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>;
13
51
 
52
+ /**
53
+ * The withParams wrapper allows your rule to depend on external parameters, such as a reactive property in your component or store.
54
+ *
55
+ * By default, useRegle observes changes automatically when rules are defined using getter functions or computed properties.
56
+ *
57
+ * ```ts
58
+ * import { withParams } from '@regle/rules';
59
+
60
+ const base = ref('foo');
61
+
62
+ const { r$ } = useRegle({ name: '' }, {
63
+ name: {
64
+ customRule: withParams((value, param) => value === param, [base]),
65
+ // or
66
+ customRule: withParams((value, param) => value === param, [() => base.value]),
67
+ }
68
+ })
69
+ * ```
70
+ * Docs: {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withparams}
71
+ */
14
72
  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>, depsArray: [...TParams]): RegleRuleDefinition<TValue, UnwrapRegleUniversalParams<TParams>, TAsync, TMetadata>;
15
73
 
16
- 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: ParamDecl<boolean>, rule: InlineRuleDeclaration<TValue, TParams, TReturn> | RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>): RegleRuleDefinition<TValue, [...TParams, condition: boolean], TAsync, TMetadata>;
74
+ /**
75
+ * The applyIf operator is similar to requiredIf, but it can be used with any rule. It simplifies conditional rule declarations.
76
+ */
77
+ 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>;
78
+
79
+ /**
80
+ * 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.
17
81
 
82
+ isFilled also acts as a type guard.
83
+ */
18
84
  declare function isFilled<T extends unknown>(value: T): value is NonNullable<T>;
19
85
 
86
+ /**
87
+ * 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".
88
+ */
20
89
  declare function isNumber(value: unknown): value is number;
21
90
 
91
+ /**
92
+ * This utility can take multiple regular expressions as arguments. It checks the input's validity and tests it against the provided regex patterns.
93
+ */
22
94
  declare function matchRegex(_value: string | number | null | undefined, ...expr: RegExp[]): boolean;
23
95
 
96
+ /**
97
+ * This helper will return the length of any data type you pass. It works with strings, arrays, objects and numbers.
98
+ */
24
99
  declare function getSize(value: MaybeRef<string | any[] | Record<string, any> | number>): number;
25
100
 
101
+ /**
102
+ * 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.
103
+ */
26
104
  declare function isDate(value: unknown): value is Date;
27
105
 
106
+ /**
107
+ * This utility will coerce any string, number or Date value into a Date using the Date constructor.
108
+ */
28
109
  declare function toDate(argument: Maybe<Date | number | string>): Date;
29
110
 
30
111
  /**
112
+ * This utility converts any string (or number) into a number using the Number constructor.
113
+ *
31
114
  * @returns โš ๏ธ Warning, returned value can be NaN
32
115
  */
33
116
  declare function toNumber<T extends number | string | undefined>(argument: T): number;
@@ -69,6 +152,11 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
69
152
  */
70
153
  type EmptyObject$1 = {[emptyObjectSymbol$1]?: never};
71
154
 
155
+ /**
156
+ * This is the inverse of isFilled. It will check if the value is in any way empty (including arrays and objects)
157
+
158
+ isEmpty also acts as a type guard.
159
+ */
72
160
  declare function isEmpty(value: unknown): value is null | undefined | [] | EmptyObject$1;
73
161
 
74
162
  declare global {
@@ -127,52 +215,136 @@ type UnwrapTuplesRaw<T extends any[] = [], F = CreateFn<T>> = [T] extends [[]] ?
127
215
  }) => any : never>;
128
216
  type UnwrapTuples<T extends any[]> = FilterTuple<UnwrapTuplesRaw<T>>;
129
217
 
218
+ /**
219
+ * The and operator combines multiple rules and validates successfully only if all provided rules are valid.
220
+ */
130
221
  declare function and<TRules extends FormRuleDeclaration<any, any>[]>(...rules: [...TRules]): RegleRuleDefinition<ExtractValueFromRules<TRules>[number], UnwrapTuples<ExtractParamsFromRules<TRules>>, GuessAsyncFromRules<TRules>, GuessMetadataFromRules<TRules>>;
131
222
 
223
+ /**
224
+ * The or operator validates successfully if at least one of the provided rules is valid.
225
+ */
132
226
  declare function or<TRules extends FormRuleDeclaration<any, any>[]>(...rules: [...TRules]): RegleRuleDefinition<ExtractValueFromRules<TRules>[number], UnwrapTuples<ExtractParamsFromRules<TRules>>, GuessAsyncFromRules<TRules>, GuessMetadataFromRules<TRules>>;
133
227
 
228
+ /**
229
+ * The not operator passes when the provided rule fails and fails when the rule passes. It can be combined with other rules.
230
+ */
134
231
  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>;
135
232
 
233
+ /**
234
+ * Requires non-empty data. Checks for empty arrays and strings containing only whitespaces.
235
+ */
136
236
  declare const required: RegleRuleDefinition<unknown, [], false, boolean, unknown>;
137
237
 
238
+ /**
239
+ * Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.
240
+ *
241
+ * @param max - the maximum length
242
+ */
138
243
  declare const maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
139
244
  count: number
140
245
  ], false, boolean>;
141
246
 
247
+ /**
248
+ * Requires non-empty data, only if provided data property, ref, or a function resolves to true.
249
+ *
250
+ * @param condition - the condition to enable the required rule
251
+ */
142
252
  declare const requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
143
253
 
254
+ /**
255
+ * Allows only alphabetic characters.
256
+ * */
144
257
  declare const alpha: RegleRuleDefinition<string, [], false, boolean, string>;
145
258
 
259
+ /**
260
+ * Allows only alphanumeric characters.
261
+ */
146
262
  declare const alphaNum: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
147
263
 
264
+ /**
265
+ * Checks if a number is in specified bounds. min and max are both inclusive.
266
+ *
267
+ * @param min - the minimum limit
268
+ * @param max - the maximum limit
269
+ */
148
270
  declare const between: RegleRuleWithParamsDefinition<number, [min: number, max: number], false, boolean>;
149
271
 
272
+ /**
273
+ * Allows positive and negative decimal numbers.
274
+ */
150
275
  declare const decimal: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
151
276
 
277
+ /**
278
+ * Validates email addresses. Always verify on the server to ensure the address is real and not already in use.
279
+ */
152
280
  declare const email: RegleRuleDefinition<string, [], false, boolean, string>;
153
281
 
282
+ /**
283
+ * Allows only integers (positive and negative).
284
+ */
154
285
  declare const integer: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
155
286
 
287
+ /**
288
+ * Requires a field to have a specified maximum numeric value.
289
+ *
290
+ * @param max - the maximum value
291
+ */
156
292
  declare const maxValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
157
293
 
294
+ /**
295
+ * Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.
296
+ *
297
+ * @param min - the minimum value
298
+ */
158
299
  declare const minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
159
300
  count: number
160
301
  ], false, boolean>;
161
302
 
303
+ /**
304
+ * Requires a field to have a specified minimum numeric value.
305
+ *
306
+ * @param count - the minimum count
307
+ */
162
308
  declare const minValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
163
309
 
310
+ declare const exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
311
+
312
+ /**
313
+ * Requires the input value to have a strict specified length, inclusive. Works with arrays, objects and strings.
314
+ *
315
+ * @param count - the required length
316
+ */
164
317
  declare const exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
165
318
  count: number
166
319
  ], false, boolean>;
167
320
 
321
+ /**
322
+ * Allows only numeric values (including numeric strings).
323
+ */
168
324
  declare const numeric: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
169
325
 
326
+ /**
327
+ * Requires non-empty data, only if provided data property, ref, or a function resolves to false.
328
+ *
329
+ * @param condition - the condition to disable the required rule
330
+ */
170
331
  declare const requiredUnless: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
171
332
 
333
+ /**
334
+ * Checks if the value matches the specified property or ref.
335
+ */
172
336
  declare const sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
173
337
 
338
+ /**
339
+ * Validates URLs.
340
+ */
174
341
  declare const url: RegleRuleDefinition<string, [], false, boolean, string>;
175
342
 
343
+ /**
344
+ * Checks if the date is after the given parameter.
345
+ *
346
+ * @param after - the date to compare to
347
+ */
176
348
  declare const dateAfter: RegleRuleWithParamsDefinition<string | Date, [
177
349
  after: Maybe<string | Date>
178
350
  ], false, true | {
@@ -183,6 +355,11 @@ declare const dateAfter: RegleRuleWithParamsDefinition<string | Date, [
183
355
  error: 'value-or-paramater-not-a-date';
184
356
  }>;
185
357
 
358
+ /**
359
+ * Checks if the date is before the given parameter.
360
+ *
361
+ * @param before - the date to compare to
362
+ */
186
363
  declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [
187
364
  before: Maybe<string | Date>
188
365
  ], false, true | {
@@ -193,23 +370,58 @@ declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [
193
370
  error: 'value-or-paramater-not-a-date';
194
371
  }>;
195
372
 
373
+ /**
374
+ * Checks if the date falls between the specified bounds.
375
+ *
376
+ * @param before - the minimum limit
377
+ * @param after - the maximum limit
378
+ */
196
379
  declare const dateBetween: RegleRuleWithParamsDefinition<string | Date, [
197
380
  before: Maybe<string | Date>,
198
381
  after: Maybe<string | Date>
199
382
  ], false, boolean>;
200
383
 
384
+ /**
385
+ * Validates IPv4 addresses in dotted decimal notation 127.0.0.1.
386
+ */
201
387
  declare const ipAddress: RegleRuleDefinition<string, [], false, boolean, string>;
202
388
 
389
+ /**
390
+ * Validates MAC addresses. Call as a function to specify a custom separator (e.g., ':' or an empty string for 00ff1122334455).
391
+ *
392
+ * @param separator - the custom separator
393
+ */
203
394
  declare const macAddress: RegleRuleWithParamsDefinition<string, [separator?: string | undefined], false, boolean>;
204
395
 
396
+ /**
397
+ * Requires a boolean value to be true. This is useful for checkbox inputs.
398
+ */
205
399
  declare const checked: RegleRuleDefinition<boolean, [], false, boolean, boolean>;
206
400
 
401
+ /**
402
+ * Checks if the string contains the specified substring.
403
+ *
404
+ * @param part - the part the value needs to contain
405
+ */
207
406
  declare const contains: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
208
407
 
408
+ /**
409
+ * Checks if the string starts with the specified substring.
410
+ *
411
+ * @private part - the vlaue the field must start with
412
+ */
209
413
  declare const startsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
210
414
 
415
+ /**
416
+ * Checks if the string ends with the specified substring.
417
+ *
418
+ * @param part - the value the field must end with
419
+ */
211
420
  declare const endsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
212
421
 
422
+ /**
423
+ * Checks if the value matches one or more regular expressions.
424
+ */
213
425
  declare const regex: RegleRuleWithParamsDefinition<string | number, [...regexp: RegExp[]], false, boolean>;
214
426
 
215
- export { alpha, alphaNum, and, applyIf, between, checked, contains, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, getSize, integer, ipAddress, isDate, isEmpty, isFilled, isNumber, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, not, numeric, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, toDate, toNumber, url, withAsync, withMessage, withParams, withTooltip };
427
+ export { alpha, alphaNum, and, applyIf, between, checked, contains, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, integer, ipAddress, isDate, isEmpty, isFilled, isNumber, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, not, numeric, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, toDate, toNumber, url, withAsync, withMessage, withParams, withTooltip };
@@ -1,33 +1,116 @@
1
- import { RegleRuleMetadataDefinition, InlineRuleDeclaration, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, InferRegleRule, RegleRuleWithParamsDefinition, RegleRuleDefinition, UnwrapRegleUniversalParams, ParamDecl, Maybe, FormRuleDeclaration } from '@regle/core';
2
- import { Ref, MaybeRef } from 'vue';
1
+ import { RegleRuleMetadataDefinition, InlineRuleDeclaration, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, InferRegleRule, RegleRuleWithParamsDefinition, RegleRuleDefinition, UnwrapRegleUniversalParams, Maybe, FormRuleDeclaration } from '@regle/core';
2
+ import { Ref, MaybeRefOrGetter, MaybeRef } from 'vue';
3
3
 
4
+ /**
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.
6
+ *
7
+ * ```ts
8
+ * const { r$ } = useRegle({ name: '' }, {
9
+ name: {
10
+ customRule1: withMessage((value) => !!value, "Custom Error"),
11
+ customRule2: withMessage(customRuleInlineWithMetaData, "Custom Error"),
12
+ customRule3: withMessage(
13
+ customRuleInlineWithMetaData,
14
+ ({ $value, foo }) => `Custom Error: ${$value} ${foo}`
15
+ ),
16
+ }
17
+ })
18
+ * ```
19
+ * Docs: {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withmessage}
20
+ */
4
21
  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[]>): InferRegleRule<TValue, TParams, TAsync, TReturn extends Promise<infer M> ? M : TReturn>;
5
22
  declare function withMessage<TValue extends any, TParams extends any[], TMetadata extends RegleRuleMetadataDefinition, TReturn extends TMetadata | Promise<TMetadata>, 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>;
6
23
  declare function withMessage<TValue extends any, TParams extends any[], TMetadata extends RegleRuleMetadataDefinition, TReturn extends TMetadata | Promise<TMetadata>, TAsync extends boolean>(rule: RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
7
24
 
25
+ /**
26
+ * The withTooltip wrapper allows you to display additional messages for your field that arenโ€™t necessarily errors. Tooltips are aggregated and accessible via $field.xxx.$tooltips .
27
+ */
8
28
  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>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TReturn extends Promise<infer M> ? M : TReturn>, string | string[]>): InferRegleRule<TValue, TParams, TAsync, TReturn extends Promise<infer M> ? M : TReturn>;
9
29
  declare function withTooltip<TValue extends any, TParams extends any[], TMetadata extends RegleRuleMetadataDefinition, TReturn extends TMetadata | Promise<TMetadata>, 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>;
10
30
  declare function withTooltip<TValue extends any, TParams extends any[], TMetadata extends RegleRuleMetadataDefinition, TReturn extends TMetadata | Promise<TMetadata>, TAsync extends boolean>(rule: RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue, RegleRuleMetadataConsumer<TValue, TParams, TMetadata>, string | string[]>): RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>;
11
31
 
32
+ /**
33
+ * withAsync works like withParams, but is specifically designed for async rules that depend on external values.
34
+ *
35
+ * ```ts
36
+ *import { withAsync } from '@regle/rules';
37
+
38
+ const base = ref('foo');
39
+
40
+ const { r$ } = useRegle({ name: '' }, {
41
+ name: {
42
+ customRule: withAsync(async (value, param) => {
43
+ await someAsyncCall(param)
44
+ }, [base])
45
+ }
46
+ })
47
+ * ```
48
+ * Docs: {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withasync}
49
+ */
12
50
  declare function withAsync<TValue, TParams extends (Ref<unknown> | (() => unknown))[] = [], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = 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>;
13
51
 
52
+ /**
53
+ * The withParams wrapper allows your rule to depend on external parameters, such as a reactive property in your component or store.
54
+ *
55
+ * By default, useRegle observes changes automatically when rules are defined using getter functions or computed properties.
56
+ *
57
+ * ```ts
58
+ * import { withParams } from '@regle/rules';
59
+
60
+ const base = ref('foo');
61
+
62
+ const { r$ } = useRegle({ name: '' }, {
63
+ name: {
64
+ customRule: withParams((value, param) => value === param, [base]),
65
+ // or
66
+ customRule: withParams((value, param) => value === param, [() => base.value]),
67
+ }
68
+ })
69
+ * ```
70
+ * Docs: {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withparams}
71
+ */
14
72
  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>, depsArray: [...TParams]): RegleRuleDefinition<TValue, UnwrapRegleUniversalParams<TParams>, TAsync, TMetadata>;
15
73
 
16
- 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: ParamDecl<boolean>, rule: InlineRuleDeclaration<TValue, TParams, TReturn> | RegleRuleDefinition<TValue, TParams, TAsync, TMetadata>): RegleRuleDefinition<TValue, [...TParams, condition: boolean], TAsync, TMetadata>;
74
+ /**
75
+ * The applyIf operator is similar to requiredIf, but it can be used with any rule. It simplifies conditional rule declarations.
76
+ */
77
+ 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>;
78
+
79
+ /**
80
+ * 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.
17
81
 
82
+ isFilled also acts as a type guard.
83
+ */
18
84
  declare function isFilled<T extends unknown>(value: T): value is NonNullable<T>;
19
85
 
86
+ /**
87
+ * 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".
88
+ */
20
89
  declare function isNumber(value: unknown): value is number;
21
90
 
91
+ /**
92
+ * This utility can take multiple regular expressions as arguments. It checks the input's validity and tests it against the provided regex patterns.
93
+ */
22
94
  declare function matchRegex(_value: string | number | null | undefined, ...expr: RegExp[]): boolean;
23
95
 
96
+ /**
97
+ * This helper will return the length of any data type you pass. It works with strings, arrays, objects and numbers.
98
+ */
24
99
  declare function getSize(value: MaybeRef<string | any[] | Record<string, any> | number>): number;
25
100
 
101
+ /**
102
+ * 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.
103
+ */
26
104
  declare function isDate(value: unknown): value is Date;
27
105
 
106
+ /**
107
+ * This utility will coerce any string, number or Date value into a Date using the Date constructor.
108
+ */
28
109
  declare function toDate(argument: Maybe<Date | number | string>): Date;
29
110
 
30
111
  /**
112
+ * This utility converts any string (or number) into a number using the Number constructor.
113
+ *
31
114
  * @returns โš ๏ธ Warning, returned value can be NaN
32
115
  */
33
116
  declare function toNumber<T extends number | string | undefined>(argument: T): number;
@@ -69,6 +152,11 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
69
152
  */
70
153
  type EmptyObject$1 = {[emptyObjectSymbol$1]?: never};
71
154
 
155
+ /**
156
+ * This is the inverse of isFilled. It will check if the value is in any way empty (including arrays and objects)
157
+
158
+ isEmpty also acts as a type guard.
159
+ */
72
160
  declare function isEmpty(value: unknown): value is null | undefined | [] | EmptyObject$1;
73
161
 
74
162
  declare global {
@@ -127,52 +215,136 @@ type UnwrapTuplesRaw<T extends any[] = [], F = CreateFn<T>> = [T] extends [[]] ?
127
215
  }) => any : never>;
128
216
  type UnwrapTuples<T extends any[]> = FilterTuple<UnwrapTuplesRaw<T>>;
129
217
 
218
+ /**
219
+ * The and operator combines multiple rules and validates successfully only if all provided rules are valid.
220
+ */
130
221
  declare function and<TRules extends FormRuleDeclaration<any, any>[]>(...rules: [...TRules]): RegleRuleDefinition<ExtractValueFromRules<TRules>[number], UnwrapTuples<ExtractParamsFromRules<TRules>>, GuessAsyncFromRules<TRules>, GuessMetadataFromRules<TRules>>;
131
222
 
223
+ /**
224
+ * The or operator validates successfully if at least one of the provided rules is valid.
225
+ */
132
226
  declare function or<TRules extends FormRuleDeclaration<any, any>[]>(...rules: [...TRules]): RegleRuleDefinition<ExtractValueFromRules<TRules>[number], UnwrapTuples<ExtractParamsFromRules<TRules>>, GuessAsyncFromRules<TRules>, GuessMetadataFromRules<TRules>>;
133
227
 
228
+ /**
229
+ * The not operator passes when the provided rule fails and fails when the rule passes. It can be combined with other rules.
230
+ */
134
231
  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>;
135
232
 
233
+ /**
234
+ * Requires non-empty data. Checks for empty arrays and strings containing only whitespaces.
235
+ */
136
236
  declare const required: RegleRuleDefinition<unknown, [], false, boolean, unknown>;
137
237
 
238
+ /**
239
+ * Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.
240
+ *
241
+ * @param max - the maximum length
242
+ */
138
243
  declare const maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
139
244
  count: number
140
245
  ], false, boolean>;
141
246
 
247
+ /**
248
+ * Requires non-empty data, only if provided data property, ref, or a function resolves to true.
249
+ *
250
+ * @param condition - the condition to enable the required rule
251
+ */
142
252
  declare const requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
143
253
 
254
+ /**
255
+ * Allows only alphabetic characters.
256
+ * */
144
257
  declare const alpha: RegleRuleDefinition<string, [], false, boolean, string>;
145
258
 
259
+ /**
260
+ * Allows only alphanumeric characters.
261
+ */
146
262
  declare const alphaNum: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
147
263
 
264
+ /**
265
+ * Checks if a number is in specified bounds. min and max are both inclusive.
266
+ *
267
+ * @param min - the minimum limit
268
+ * @param max - the maximum limit
269
+ */
148
270
  declare const between: RegleRuleWithParamsDefinition<number, [min: number, max: number], false, boolean>;
149
271
 
272
+ /**
273
+ * Allows positive and negative decimal numbers.
274
+ */
150
275
  declare const decimal: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
151
276
 
277
+ /**
278
+ * Validates email addresses. Always verify on the server to ensure the address is real and not already in use.
279
+ */
152
280
  declare const email: RegleRuleDefinition<string, [], false, boolean, string>;
153
281
 
282
+ /**
283
+ * Allows only integers (positive and negative).
284
+ */
154
285
  declare const integer: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
155
286
 
287
+ /**
288
+ * Requires a field to have a specified maximum numeric value.
289
+ *
290
+ * @param max - the maximum value
291
+ */
156
292
  declare const maxValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
157
293
 
294
+ /**
295
+ * Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.
296
+ *
297
+ * @param min - the minimum value
298
+ */
158
299
  declare const minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
159
300
  count: number
160
301
  ], false, boolean>;
161
302
 
303
+ /**
304
+ * Requires a field to have a specified minimum numeric value.
305
+ *
306
+ * @param count - the minimum count
307
+ */
162
308
  declare const minValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
163
309
 
310
+ declare const exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean>;
311
+
312
+ /**
313
+ * Requires the input value to have a strict specified length, inclusive. Works with arrays, objects and strings.
314
+ *
315
+ * @param count - the required length
316
+ */
164
317
  declare const exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [
165
318
  count: number
166
319
  ], false, boolean>;
167
320
 
321
+ /**
322
+ * Allows only numeric values (including numeric strings).
323
+ */
168
324
  declare const numeric: RegleRuleDefinition<string | number, [], false, boolean, string | number>;
169
325
 
326
+ /**
327
+ * Requires non-empty data, only if provided data property, ref, or a function resolves to false.
328
+ *
329
+ * @param condition - the condition to disable the required rule
330
+ */
170
331
  declare const requiredUnless: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
171
332
 
333
+ /**
334
+ * Checks if the value matches the specified property or ref.
335
+ */
172
336
  declare const sameAs: RegleRuleWithParamsDefinition<unknown, [target: unknown, otherName?: string], false, boolean>;
173
337
 
338
+ /**
339
+ * Validates URLs.
340
+ */
174
341
  declare const url: RegleRuleDefinition<string, [], false, boolean, string>;
175
342
 
343
+ /**
344
+ * Checks if the date is after the given parameter.
345
+ *
346
+ * @param after - the date to compare to
347
+ */
176
348
  declare const dateAfter: RegleRuleWithParamsDefinition<string | Date, [
177
349
  after: Maybe<string | Date>
178
350
  ], false, true | {
@@ -183,6 +355,11 @@ declare const dateAfter: RegleRuleWithParamsDefinition<string | Date, [
183
355
  error: 'value-or-paramater-not-a-date';
184
356
  }>;
185
357
 
358
+ /**
359
+ * Checks if the date is before the given parameter.
360
+ *
361
+ * @param before - the date to compare to
362
+ */
186
363
  declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [
187
364
  before: Maybe<string | Date>
188
365
  ], false, true | {
@@ -193,23 +370,58 @@ declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [
193
370
  error: 'value-or-paramater-not-a-date';
194
371
  }>;
195
372
 
373
+ /**
374
+ * Checks if the date falls between the specified bounds.
375
+ *
376
+ * @param before - the minimum limit
377
+ * @param after - the maximum limit
378
+ */
196
379
  declare const dateBetween: RegleRuleWithParamsDefinition<string | Date, [
197
380
  before: Maybe<string | Date>,
198
381
  after: Maybe<string | Date>
199
382
  ], false, boolean>;
200
383
 
384
+ /**
385
+ * Validates IPv4 addresses in dotted decimal notation 127.0.0.1.
386
+ */
201
387
  declare const ipAddress: RegleRuleDefinition<string, [], false, boolean, string>;
202
388
 
389
+ /**
390
+ * Validates MAC addresses. Call as a function to specify a custom separator (e.g., ':' or an empty string for 00ff1122334455).
391
+ *
392
+ * @param separator - the custom separator
393
+ */
203
394
  declare const macAddress: RegleRuleWithParamsDefinition<string, [separator?: string | undefined], false, boolean>;
204
395
 
396
+ /**
397
+ * Requires a boolean value to be true. This is useful for checkbox inputs.
398
+ */
205
399
  declare const checked: RegleRuleDefinition<boolean, [], false, boolean, boolean>;
206
400
 
401
+ /**
402
+ * Checks if the string contains the specified substring.
403
+ *
404
+ * @param part - the part the value needs to contain
405
+ */
207
406
  declare const contains: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
208
407
 
408
+ /**
409
+ * Checks if the string starts with the specified substring.
410
+ *
411
+ * @private part - the vlaue the field must start with
412
+ */
209
413
  declare const startsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
210
414
 
415
+ /**
416
+ * Checks if the string ends with the specified substring.
417
+ *
418
+ * @param part - the value the field must end with
419
+ */
211
420
  declare const endsWith: RegleRuleWithParamsDefinition<string, [part: Maybe<string>], false, boolean>;
212
421
 
422
+ /**
423
+ * Checks if the value matches one or more regular expressions.
424
+ */
213
425
  declare const regex: RegleRuleWithParamsDefinition<string | number, [...regexp: RegExp[]], false, boolean>;
214
426
 
215
- export { alpha, alphaNum, and, applyIf, between, checked, contains, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, getSize, integer, ipAddress, isDate, isEmpty, isFilled, isNumber, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, not, numeric, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, toDate, toNumber, url, withAsync, withMessage, withParams, withTooltip };
427
+ export { alpha, alphaNum, and, applyIf, between, checked, contains, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, integer, ipAddress, isDate, isEmpty, isFilled, isNumber, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, not, numeric, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, toDate, toNumber, url, withAsync, withMessage, withParams, withTooltip };
@@ -1 +1 @@
1
- 'use strict';var core=require('@regle/core'),vue=require('vue');function $(e,t){let i,o,u,m;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m}=e;let f=core.createRule({type:i,validator:o,active:u,message:t}),r=[...m??[]];if(f._params=r,f._message_patched=!0,typeof f=="function"){let s=f(...r);return s._message_patched=!0,s}else return f}function W(e,t){let i,o,u,m,f;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m,_message:f}=e;let r=core.createRule({type:i,validator:o,active:u,message:f,tooltip:t}),s=[...m??[]];if(r._params=s,r._tooltip_patched=!0,typeof r=="function"){let n=r(...s);return r._tooltip_patched=!0,n}else return r}function N(e,t){let i=async(u,...m)=>e(u,...m),o=core.createRule({type:core.InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function E(e,t){let i=(u,...m)=>e(u,...m),o=core.createRule({type:core.InternalRuleType.Inline,validator:i,message:""});return o._params=o._params?.concat(t),o(...t)}function S(e,t){let i,o,u=[],m="";typeof t=="function"?(i=core.InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:m}=t,u=t._params?.concat([e]));function f(R,...d){let[g]=core.unwrapRuleParameters([e]);return g?o(R,...d):!0}function r(R){let[d]=core.unwrapRuleParameters([e]);return d}let s=core.createRule({type:i,validator:f,active:r,message:m}),n=[...u??[]];if(s._params=n,typeof s=="function"){let R=s(...n);return R._message_patched=!0,R}else return s}function l(e){return e==null?!0:e instanceof Date?isNaN(e.getTime()):Array.isArray(e)?!1:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function a(e){return !l(typeof e=="string"?e.trim():e)}function y(e){return e==null||typeof e!="number"?!1:!isNaN(e)}function p(e,...t){if(l(e))return !0;let i=typeof e=="number"?e.toString():e;return t.every(o=>(o.lastIndex=0,o.test(i)))}function b(e){let t=vue.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 T(e){if(l(e))return !1;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="number"&&!isNaN(e))t=new Date(e);else if(typeof e=="string"){let i=new Date(e);if(i.toString()==="Invalid Date")return !1;t=i;}return !!t}catch{return !1}}function c(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 x(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function U(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>{if(typeof r=="function")return null;{let s=r._params;return s?.length?s:[null]}}).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let g of r)if(typeof g=="function")R.push(g(s)),d++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...g}=R;return {...n,...g}},{})}:r.every(n=>!!n)}let m;e.length?m=t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)}:m=r=>!1;let f=core.createRule({type:"and",validator:m,message:"The value does not match all of the provided validators"});return f._params=i,f}function G(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>typeof r=="function"?null:r._params).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let g of r)if(typeof g=="function")R.push(g(s)),d++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...g}=R;return {...n,...g}},{})}:r.some(n=>!!n)}let f=core.createRule({type:"or",validator:t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)},message:"The value does not match any of the provided validators"});return f._params=i,f}function O(e,t){let i,o,u,m,f;typeof e=="function"?(o=e,f=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:m}=e,f=e._async),f?u=async(s,...n)=>a(s)?!await o(s,...n):!0:u=(s,...n)=>a(s)?!o(s,...n):!0;let r=core.createRule({type:"not",validator:u,message:t??"Error"});return r._params=m,r}var Et=core.createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Ct=core.createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(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 maximum length allowed is ${t}`});var Gt=core.createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var J=/^[a-zA-Z]*$/,Bt=core.createRule({type:"alpha",validator(e){return l(e)?!0:p(e,J)},message:"The value is not alphabetical"});var X=/^[a-zA-Z0-9]*$/,Qt=core.createRule({type:"alpha",validator(e){return l(e)?!0:p(e,X)},message:"The value must be alpha-numeric"});var tr=core.createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=x(e),u=x(t),m=x(i);return y(o)&&y(u)&&y(m)?o>=u&&o<=m:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${i}`),!1)}return !0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var te=/^[-]?\d*(\.\d+)?$/,ir=core.createRule({type:"decimal",validator(e){return l(e)?!0:p(e,te)},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,ur=core.createRule({type:"email",validator(e){return l(e)?!0:p(e,ae)},message:"Value must be an valid email address"});var ie=/(^[0-9]*$)|(^-[0-9]+$)/,pr=core.createRule({type:"integer",validator(e){return l(e)?!0:p(e,ie)},message:"Value must be an integer"});var cr=core.createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(x(e))?x(e)<=t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The maximum value allowed is ${e}`});var Dr=core.createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(e)>=t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,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 wr=core.createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(x(e))?x(e)>=t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The minimum value allowed is ${e}`});var Wr=core.createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$params:[e]})=>`This field should be exactly ${e} characters long`});var fe=/^\d*(\.\d+)?$/,_r=core.createRule({type:"numeric",validator(e){return l(e)?!0:p(e,fe)},message:"This field must be numeric"});var zr=core.createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Ur=core.createRule({type:"sameAs",validator(e,t,i="other"){return l(e)?!0:e===t},message({$params:[e,t]}){return `Value must be equal to the ${t} value`}});var ge=/^(?:(?:(?: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,Or=core.createRule({type:"url",validator(e){return l(e)?!0:p(e,ge)},message:"The value is not a valid URL address"});function de(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function M(e){return e?new Intl.DateTimeFormat(de(),{dateStyle:"short"}).format(new Date(e)):"?"}var Qr=core.createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()>c(t).getTime()?!0:{$valid:!1,error:"date-not-after"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The inputs must be Dates":`The date must be after ${M(e)}`});var ra=core.createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()<c(t).getTime()?!0:{$valid:!1,error:"date-not-before"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be Dates":`The date must be before ${M(e)}`});var sa=core.createRule({type:"dateBetween",validator:(e,t,i)=>T(e)&&T(t)&&T(i)?c(e).getTime()>c(t).getTime()&&c(e).getTime()<c(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${M(e)} and ${M(t)}`});function De(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}var fa=core.createRule({type:"ipAddress",validator(e){if(l(e))return !0;if(typeof e!="string")return !1;let t=e.split(".");return t.length===4&&t.every(De)},message:"The value is not a valid IP address"});var ga=core.createRule({type:"macAddress",validator(e,t=":"){if(l(e))return !0;if(typeof e!="string")return !1;let i=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return i!==null&&(i.length===6||i.length===8)&&i.every(he)},message:"The value is not a valid MAC Address"}),he=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var xa=core.createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var ha=core.createRule({type:"contains",validator(e,t){return a(e)&&a(t)?e.includes(t):!0},message({$params:[e]}){return `Field must contain ${e}`}});var Va=core.createRule({type:"startsWith",validator(e,t){return a(e)&&a(t)?e.startsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var Fa=core.createRule({type:"endsWith",validator(e,t){return a(e)&&a(t)?e.endsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var Ea=core.createRule({type:"regex",validator(e,...t){return a(e)?p(e,...t):!0},message:"This field does not match the required pattern"});exports.alpha=Bt;exports.alphaNum=Qt;exports.and=U;exports.applyIf=S;exports.between=tr;exports.checked=xa;exports.contains=ha;exports.dateAfter=Qr;exports.dateBefore=ra;exports.dateBetween=sa;exports.decimal=ir;exports.email=ur;exports.endsWith=Fa;exports.exactLength=Wr;exports.getSize=b;exports.integer=pr;exports.ipAddress=fa;exports.isDate=T;exports.isEmpty=l;exports.isFilled=a;exports.isNumber=y;exports.macAddress=ga;exports.matchRegex=p;exports.maxLength=Ct;exports.maxValue=cr;exports.minLength=Dr;exports.minValue=wr;exports.not=O;exports.numeric=_r;exports.or=G;exports.regex=Ea;exports.required=Et;exports.requiredIf=Gt;exports.requiredUnless=zr;exports.sameAs=Ur;exports.startsWith=Va;exports.toDate=c;exports.toNumber=x;exports.url=Or;exports.withAsync=N;exports.withMessage=$;exports.withParams=E;exports.withTooltip=W;
1
+ 'use strict';var core=require('@regle/core'),vue=require('vue');function $(e,t){let i,o,u,m;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m}=e;let f=core.createRule({type:i,validator:o,active:u,message:t}),r=[...m??[]];if(f._params=r,f._message_patched=!0,typeof f=="function"){let s=f(...r);return s._message_patched=!0,s}else return f}function W(e,t){let i,o,u,m,f;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m,_message:f}=e;let r=core.createRule({type:i,validator:o,active:u,message:f,tooltip:t}),s=[...m??[]];if(r._params=s,r._tooltip_patched=!0,typeof r=="function"){let n=r(...s);return r._tooltip_patched=!0,n}else return r}function N(e,t){let i=async(u,...m)=>e(u,...m),o=core.createRule({type:core.InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function E(e,t){let i=(u,...m)=>e(u,...m),o=core.createRule({type:core.InternalRuleType.Inline,validator:i,message:""});return o._params=o._params?.concat(t),o(...t)}function S(e,t){let i,o,u=[],m="";typeof t=="function"?(i=core.InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:m}=t,u=t._params?.concat([e]));function f(R,...c){let[g]=core.unwrapRuleParameters([e]);return g?o(R,...c):!0}function r(R){let[c]=core.unwrapRuleParameters([e]);return c}let s=core.createRule({type:i,validator:f,active:r,message:m}),n=[...u??[]];if(s._params=n,typeof s=="function"){let R=s(...n);return R._message_patched=!0,R}else return s}function l(e){return e==null?!0:e instanceof Date?isNaN(e.getTime()):Array.isArray(e)?!1:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function a(e){return !l(typeof e=="string"?e.trim():e)}function p(e){return e==null||typeof e!="number"?!1:!isNaN(e)}function y(e,...t){if(l(e))return !0;let i=typeof e=="number"?e.toString():e;return t.every(o=>(o.lastIndex=0,o.test(i)))}function b(e){let t=vue.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 x(e){if(l(e))return !1;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="number"&&!isNaN(e))t=new Date(e);else if(typeof e=="string"){let i=new Date(e);if(i.toString()==="Invalid Date")return !1;t=i;}return !!t}catch{return !1}}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 d(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function U(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>{if(typeof r=="function")return null;{let s=r._params;return s?.length?s:[null]}}).flat().filter(r=>!!r);function o(r,s,...n){let R=[],c=0;for(let g of r)if(typeof g=="function")R.push(g(s)),c++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(c,D))),D&&(c+=D);}return R}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:c,...g}=R;return {...n,...g}},{})}:r.every(n=>!!n)}let m;e.length?m=t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)}:m=r=>!1;let f=core.createRule({type:"and",validator:m,message:"The value does not match all of the provided validators"});return f._params=i,f}function G(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>typeof r=="function"?null:r._params).flat().filter(r=>!!r);function o(r,s,...n){let R=[],c=0;for(let g of r)if(typeof g=="function")R.push(g(s)),c++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(c,D))),D&&(c+=D);}return R}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:c,...g}=R;return {...n,...g}},{})}:r.some(n=>!!n)}let f=core.createRule({type:"or",validator:t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)},message:"The value does not match any of the provided validators"});return f._params=i,f}function K(e,t){let i,o,u,m,f;typeof e=="function"?(o=e,f=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:m}=e,f=e._async),f?u=async(s,...n)=>a(s)?!await o(s,...n):!0:u=(s,...n)=>a(s)?!o(s,...n):!0;let r=core.createRule({type:"not",validator:u,message:t??"Error"});return r._params=m,r}var kt=core.createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Lt=core.createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?p(t)?b(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 maximum length allowed is ${t}`});var Ot=core.createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var J=/^[a-zA-Z]*$/,Zt=core.createRule({type:"alpha",validator(e){return l(e)?!0:y(e,J)},message:"The value is not alphabetical"});var X=/^[a-zA-Z0-9]*$/,Xt=core.createRule({type:"alpha",validator(e){return l(e)?!0:y(e,X)},message:"The value must be alpha-numeric"});var rr=core.createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=d(e),u=d(t),m=d(i);return p(o)&&p(u)&&p(m)?o>=u&&o<=m:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${i}`),!1)}return !0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var te=/^[-]?\d*(\.\d+)?$/,or=core.createRule({type:"decimal",validator(e){return l(e)?!0:y(e,te)},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=core.createRule({type:"email",validator(e){return l(e)?!0:y(e,ae)},message:"Value must be an valid email address"});var ie=/(^[0-9]*$)|(^-[0-9]+$)/,yr=core.createRule({type:"integer",validator(e){return l(e)?!0:y(e,ie)},message:"Value must be an integer"});var Tr=core.createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?p(t)&&!isNaN(d(e))?d(e)<=t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The maximum value allowed is ${e}`});var Mr=core.createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?p(t)?b(e)>=t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,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 $r=core.createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?p(t)&&!isNaN(d(e))?d(e)>=t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The minimum value allowed is ${e}`});var vr=core.createRule({type:"exactValue",validator:(e,t)=>a(e)&&a(t)?p(t)&&!isNaN(d(e))?d(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}`});var Ir=core.createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?p(t)?b(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$params:[e]})=>`This field should be exactly ${e} characters long`});var Re=/^\d*(\.\d+)?$/,Sr=core.createRule({type:"numeric",validator(e){return l(e)?!0:y(e,Re)},message:"This field must be numeric"});var qr=core.createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var jr=core.createRule({type:"sameAs",validator(e,t,i="other"){return l(e)?!0: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,Jr=core.createRule({type:"url",validator(e){return l(e)?!0:y(e,de)},message:"The value is not a valid URL address"});function ce(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function M(e){return e?new Intl.DateTimeFormat(ce(),{dateStyle:"short"}).format(new Date(e)):"?"}var ra=core.createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()>T(t).getTime()?!0:{$valid:!1,error:"date-not-after"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The inputs must be Dates":`The date must be after ${M(e)}`});var sa=core.createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()<T(t).getTime()?!0:{$valid:!1,error:"date-not-before"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be Dates":`The date must be before ${M(e)}`});var Ra=core.createRule({type:"dateBetween",validator:(e,t,i)=>x(e)&&x(t)&&x(i)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${M(e)} and ${M(t)}`});function Me(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}var da=core.createRule({type:"ipAddress",validator(e){if(l(e))return !0;if(typeof e!="string")return !1;let t=e.split(".");return t.length===4&&t.every(Me)},message:"The value is not a valid IP address"});var ba=core.createRule({type:"macAddress",validator(e,t=":"){if(l(e))return !0;if(typeof e!="string")return !1;let i=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return i!==null&&(i.length===6||i.length===8)&&i.every(Pe)},message:"The value is not a valid MAC Address"}),Pe=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var Pa=core.createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var Aa=core.createRule({type:"contains",validator(e,t){return a(e)&&a(t)?e.includes(t):!0},message({$params:[e]}){return `Field must contain ${e}`}});var Na=core.createRule({type:"startsWith",validator(e,t){return a(e)&&a(t)?e.startsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var ka=core.createRule({type:"endsWith",validator(e,t){return a(e)&&a(t)?e.endsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var La=core.createRule({type:"regex",validator(e,...t){return a(e)?y(e,...t):!0},message:"This field does not match the required pattern"});exports.alpha=Zt;exports.alphaNum=Xt;exports.and=U;exports.applyIf=S;exports.between=rr;exports.checked=Pa;exports.contains=Aa;exports.dateAfter=ra;exports.dateBefore=sa;exports.dateBetween=Ra;exports.decimal=or;exports.email=mr;exports.endsWith=ka;exports.exactLength=Ir;exports.exactValue=vr;exports.getSize=b;exports.integer=yr;exports.ipAddress=da;exports.isDate=x;exports.isEmpty=l;exports.isFilled=a;exports.isNumber=p;exports.macAddress=ba;exports.matchRegex=y;exports.maxLength=Lt;exports.maxValue=Tr;exports.minLength=Mr;exports.minValue=$r;exports.not=K;exports.numeric=Sr;exports.or=G;exports.regex=La;exports.required=kt;exports.requiredIf=Ot;exports.requiredUnless=qr;exports.sameAs=jr;exports.startsWith=Na;exports.toDate=T;exports.toNumber=d;exports.url=Jr;exports.withAsync=N;exports.withMessage=$;exports.withParams=E;exports.withTooltip=W;
@@ -1 +1 @@
1
- import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref}from'vue';function $(e,t){let i,o,u,m;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m}=e;let f=createRule({type:i,validator:o,active:u,message:t}),r=[...m??[]];if(f._params=r,f._message_patched=!0,typeof f=="function"){let s=f(...r);return s._message_patched=!0,s}else return f}function W(e,t){let i,o,u,m,f;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m,_message:f}=e;let r=createRule({type:i,validator:o,active:u,message:f,tooltip:t}),s=[...m??[]];if(r._params=s,r._tooltip_patched=!0,typeof r=="function"){let n=r(...s);return r._tooltip_patched=!0,n}else return r}function N(e,t){let i=async(u,...m)=>e(u,...m),o=createRule({type:InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function E(e,t){let i=(u,...m)=>e(u,...m),o=createRule({type:InternalRuleType.Inline,validator:i,message:""});return o._params=o._params?.concat(t),o(...t)}function S(e,t){let i,o,u=[],m="";typeof t=="function"?(i=InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:m}=t,u=t._params?.concat([e]));function f(R,...d){let[g]=unwrapRuleParameters([e]);return g?o(R,...d):!0}function r(R){let[d]=unwrapRuleParameters([e]);return d}let s=createRule({type:i,validator:f,active:r,message:m}),n=[...u??[]];if(s._params=n,typeof s=="function"){let R=s(...n);return R._message_patched=!0,R}else return s}function l(e){return e==null?!0:e instanceof Date?isNaN(e.getTime()):Array.isArray(e)?!1:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function a(e){return !l(typeof e=="string"?e.trim():e)}function y(e){return e==null||typeof e!="number"?!1:!isNaN(e)}function p(e,...t){if(l(e))return !0;let i=typeof e=="number"?e.toString():e;return t.every(o=>(o.lastIndex=0,o.test(i)))}function b(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 T(e){if(l(e))return !1;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="number"&&!isNaN(e))t=new Date(e);else if(typeof e=="string"){let i=new Date(e);if(i.toString()==="Invalid Date")return !1;t=i;}return !!t}catch{return !1}}function c(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 x(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function U(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>{if(typeof r=="function")return null;{let s=r._params;return s?.length?s:[null]}}).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let g of r)if(typeof g=="function")R.push(g(s)),d++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...g}=R;return {...n,...g}},{})}:r.every(n=>!!n)}let m;e.length?m=t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)}:m=r=>!1;let f=createRule({type:"and",validator:m,message:"The value does not match all of the provided validators"});return f._params=i,f}function G(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>typeof r=="function"?null:r._params).flat().filter(r=>!!r);function o(r,s,...n){let R=[],d=0;for(let g of r)if(typeof g=="function")R.push(g(s)),d++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(d,D))),D&&(d+=D);}return R}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:d,...g}=R;return {...n,...g}},{})}:r.some(n=>!!n)}let f=createRule({type:"or",validator:t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)},message:"The value does not match any of the provided validators"});return f._params=i,f}function O(e,t){let i,o,u,m,f;typeof e=="function"?(o=e,f=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:m}=e,f=e._async),f?u=async(s,...n)=>a(s)?!await o(s,...n):!0:u=(s,...n)=>a(s)?!o(s,...n):!0;let r=createRule({type:"not",validator:u,message:t??"Error"});return r._params=m,r}var Et=createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Ct=createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(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 maximum length allowed is ${t}`});var Gt=createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var J=/^[a-zA-Z]*$/,Bt=createRule({type:"alpha",validator(e){return l(e)?!0:p(e,J)},message:"The value is not alphabetical"});var X=/^[a-zA-Z0-9]*$/,Qt=createRule({type:"alpha",validator(e){return l(e)?!0:p(e,X)},message:"The value must be alpha-numeric"});var tr=createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=x(e),u=x(t),m=x(i);return y(o)&&y(u)&&y(m)?o>=u&&o<=m:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${i}`),!1)}return !0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var te=/^[-]?\d*(\.\d+)?$/,ir=createRule({type:"decimal",validator(e){return l(e)?!0:p(e,te)},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,ur=createRule({type:"email",validator(e){return l(e)?!0:p(e,ae)},message:"Value must be an valid email address"});var ie=/(^[0-9]*$)|(^-[0-9]+$)/,pr=createRule({type:"integer",validator(e){return l(e)?!0:p(e,ie)},message:"Value must be an integer"});var cr=createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(x(e))?x(e)<=t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The maximum value allowed is ${e}`});var Dr=createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(e)>=t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,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 wr=createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?y(t)&&!isNaN(x(e))?x(e)>=t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The minimum value allowed is ${e}`});var Wr=createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?y(t)?b(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$params:[e]})=>`This field should be exactly ${e} characters long`});var fe=/^\d*(\.\d+)?$/,_r=createRule({type:"numeric",validator(e){return l(e)?!0:p(e,fe)},message:"This field must be numeric"});var zr=createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Ur=createRule({type:"sameAs",validator(e,t,i="other"){return l(e)?!0:e===t},message({$params:[e,t]}){return `Value must be equal to the ${t} value`}});var ge=/^(?:(?:(?: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,Or=createRule({type:"url",validator(e){return l(e)?!0:p(e,ge)},message:"The value is not a valid URL address"});function de(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function M(e){return e?new Intl.DateTimeFormat(de(),{dateStyle:"short"}).format(new Date(e)):"?"}var Qr=createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()>c(t).getTime()?!0:{$valid:!1,error:"date-not-after"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The inputs must be Dates":`The date must be after ${M(e)}`});var ra=createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?T(e)&&T(t)?c(e).getTime()<c(t).getTime()?!0:{$valid:!1,error:"date-not-before"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be Dates":`The date must be before ${M(e)}`});var sa=createRule({type:"dateBetween",validator:(e,t,i)=>T(e)&&T(t)&&T(i)?c(e).getTime()>c(t).getTime()&&c(e).getTime()<c(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${M(e)} and ${M(t)}`});function De(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}var fa=createRule({type:"ipAddress",validator(e){if(l(e))return !0;if(typeof e!="string")return !1;let t=e.split(".");return t.length===4&&t.every(De)},message:"The value is not a valid IP address"});var ga=createRule({type:"macAddress",validator(e,t=":"){if(l(e))return !0;if(typeof e!="string")return !1;let i=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return i!==null&&(i.length===6||i.length===8)&&i.every(he)},message:"The value is not a valid MAC Address"}),he=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var xa=createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var ha=createRule({type:"contains",validator(e,t){return a(e)&&a(t)?e.includes(t):!0},message({$params:[e]}){return `Field must contain ${e}`}});var Va=createRule({type:"startsWith",validator(e,t){return a(e)&&a(t)?e.startsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var Fa=createRule({type:"endsWith",validator(e,t){return a(e)&&a(t)?e.endsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var Ea=createRule({type:"regex",validator(e,...t){return a(e)?p(e,...t):!0},message:"This field does not match the required pattern"});export{Bt as alpha,Qt as alphaNum,U as and,S as applyIf,tr as between,xa as checked,ha as contains,Qr as dateAfter,ra as dateBefore,sa as dateBetween,ir as decimal,ur as email,Fa as endsWith,Wr as exactLength,b as getSize,pr as integer,fa as ipAddress,T as isDate,l as isEmpty,a as isFilled,y as isNumber,ga as macAddress,p as matchRegex,Ct as maxLength,cr as maxValue,Dr as minLength,wr as minValue,O as not,_r as numeric,G as or,Ea as regex,Et as required,Gt as requiredIf,zr as requiredUnless,Ur as sameAs,Va as startsWith,c as toDate,x as toNumber,Or as url,N as withAsync,$ as withMessage,E as withParams,W as withTooltip};
1
+ import {createRule,InternalRuleType,unwrapRuleParameters}from'@regle/core';import {unref}from'vue';function $(e,t){let i,o,u,m;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m}=e;let f=createRule({type:i,validator:o,active:u,message:t}),r=[...m??[]];if(f._params=r,f._message_patched=!0,typeof f=="function"){let s=f(...r);return s._message_patched=!0,s}else return f}function W(e,t){let i,o,u,m,f;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:m,_message:f}=e;let r=createRule({type:i,validator:o,active:u,message:f,tooltip:t}),s=[...m??[]];if(r._params=s,r._tooltip_patched=!0,typeof r=="function"){let n=r(...s);return r._tooltip_patched=!0,n}else return r}function N(e,t){let i=async(u,...m)=>e(u,...m),o=createRule({type:InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function E(e,t){let i=(u,...m)=>e(u,...m),o=createRule({type:InternalRuleType.Inline,validator:i,message:""});return o._params=o._params?.concat(t),o(...t)}function S(e,t){let i,o,u=[],m="";typeof t=="function"?(i=InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:m}=t,u=t._params?.concat([e]));function f(R,...c){let[g]=unwrapRuleParameters([e]);return g?o(R,...c):!0}function r(R){let[c]=unwrapRuleParameters([e]);return c}let s=createRule({type:i,validator:f,active:r,message:m}),n=[...u??[]];if(s._params=n,typeof s=="function"){let R=s(...n);return R._message_patched=!0,R}else return s}function l(e){return e==null?!0:e instanceof Date?isNaN(e.getTime()):Array.isArray(e)?!1:typeof e=="object"&&e!=null?Object.keys(e).length===0:!String(e).length}function a(e){return !l(typeof e=="string"?e.trim():e)}function p(e){return e==null||typeof e!="number"?!1:!isNaN(e)}function y(e,...t){if(l(e))return !0;let i=typeof e=="number"?e.toString():e;return t.every(o=>(o.lastIndex=0,o.test(i)))}function b(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 x(e){if(l(e))return !1;try{let t=null;if(e instanceof Date)t=e;else if(typeof e=="number"&&!isNaN(e))t=new Date(e);else if(typeof e=="string"){let i=new Date(e);if(i.toString()==="Invalid Date")return !1;t=i;}return !!t}catch{return !1}}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 d(e){return typeof e=="number"?e:e!=null?typeof e=="string"?e.trim()!==e?NaN:+e:NaN:NaN}function U(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>{if(typeof r=="function")return null;{let s=r._params;return s?.length?s:[null]}}).flat().filter(r=>!!r);function o(r,s,...n){let R=[],c=0;for(let g of r)if(typeof g=="function")R.push(g(s)),c++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(c,D))),D&&(c+=D);}return R}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:c,...g}=R;return {...n,...g}},{})}:r.every(n=>!!n)}let m;e.length?m=t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)}:m=r=>!1;let f=createRule({type:"and",validator:m,message:"The value does not match all of the provided validators"});return f._params=i,f}function G(...e){let t=e.some(r=>typeof r=="function"?r.constructor.name==="AsyncFunction":r._async),i=e.map(r=>typeof r=="function"?null:r._params).flat().filter(r=>!!r);function o(r,s,...n){let R=[],c=0;for(let g of r)if(typeof g=="function")R.push(g(s)),c++;else {let D=g._params?.length??0;R.push(g.validator(s,...n.slice(c,D))),D&&(c+=D);}return R}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,R)=>{if(typeof R=="boolean")return n;let{$valid:c,...g}=R;return {...n,...g}},{})}:r.some(n=>!!n)}let f=createRule({type:"or",validator:t?async(r,...s)=>{let n=await Promise.all(o(e,r,...s));return u(n)}:(r,...s)=>{let n=o(e,r,...s);return u(n)},message:"The value does not match any of the provided validators"});return f._params=i,f}function K(e,t){let i,o,u,m,f;typeof e=="function"?(o=e,f=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:m}=e,f=e._async),f?u=async(s,...n)=>a(s)?!await o(s,...n):!0:u=(s,...n)=>a(s)?!o(s,...n):!0;let r=createRule({type:"not",validator:u,message:t??"Error"});return r._params=m,r}var kt=createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Lt=createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?p(t)?b(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 maximum length allowed is ${t}`});var Ot=createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var J=/^[a-zA-Z]*$/,Zt=createRule({type:"alpha",validator(e){return l(e)?!0:y(e,J)},message:"The value is not alphabetical"});var X=/^[a-zA-Z0-9]*$/,Xt=createRule({type:"alpha",validator(e){return l(e)?!0:y(e,X)},message:"The value must be alpha-numeric"});var rr=createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=d(e),u=d(t),m=d(i);return p(o)&&p(u)&&p(m)?o>=u&&o<=m:(console.warn(`[between] Value or parameters aren't numbers, got value: ${e}, min: ${t}, max: ${i}`),!1)}return !0},message:({$params:[e,t]})=>`The value must be between ${e} and ${t}`});var te=/^[-]?\d*(\.\d+)?$/,or=createRule({type:"decimal",validator(e){return l(e)?!0:y(e,te)},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 l(e)?!0:y(e,ae)},message:"Value must be an valid email address"});var ie=/(^[0-9]*$)|(^-[0-9]+$)/,yr=createRule({type:"integer",validator(e){return l(e)?!0:y(e,ie)},message:"Value must be an integer"});var Tr=createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?p(t)&&!isNaN(d(e))?d(e)<=t:(console.warn(`[maxValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The maximum value allowed is ${e}`});var Mr=createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?p(t)?b(e)>=t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,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 $r=createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?p(t)&&!isNaN(d(e))?d(e)>=t:(console.warn(`[minValue] Value or parameter isn't a number, got value: ${e}, parameter: ${t}`),!0):!0,message:({$params:[e]})=>`The minimum value allowed is ${e}`});var vr=createRule({type:"exactValue",validator:(e,t)=>a(e)&&a(t)?p(t)&&!isNaN(d(e))?d(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}`});var Ir=createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?p(t)?b(e)===t:(console.warn(`[minLength] Parameter isn't a number, got parameter: ${t}`),!1):!0,message:({$params:[e]})=>`This field should be exactly ${e} characters long`});var Re=/^\d*(\.\d+)?$/,Sr=createRule({type:"numeric",validator(e){return l(e)?!0:y(e,Re)},message:"This field must be numeric"});var qr=createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var jr=createRule({type:"sameAs",validator(e,t,i="other"){return l(e)?!0: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,Jr=createRule({type:"url",validator(e){return l(e)?!0:y(e,de)},message:"The value is not a valid URL address"});function ce(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function M(e){return e?new Intl.DateTimeFormat(ce(),{dateStyle:"short"}).format(new Date(e)):"?"}var ra=createRule({type:"dateAfter",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()>T(t).getTime()?!0:{$valid:!1,error:"date-not-after"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The inputs must be Dates":`The date must be after ${M(e)}`});var sa=createRule({type:"dateBefore",validator:(e,t)=>a(e)&&a(t)?x(e)&&x(t)?T(e).getTime()<T(t).getTime()?!0:{$valid:!1,error:"date-not-before"}:{$valid:!1,error:"value-or-paramater-not-a-date"}:!0,message:({$params:[e],error:t})=>t==="value-or-paramater-not-a-date"?"The fields must be Dates":`The date must be before ${M(e)}`});var Ra=createRule({type:"dateBetween",validator:(e,t,i)=>x(e)&&x(t)&&x(i)?T(e).getTime()>T(t).getTime()&&T(e).getTime()<T(i).getTime():!0,message:({$params:[e,t]})=>`The date must be between ${M(e)} and ${M(t)}`});function Me(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}var da=createRule({type:"ipAddress",validator(e){if(l(e))return !0;if(typeof e!="string")return !1;let t=e.split(".");return t.length===4&&t.every(Me)},message:"The value is not a valid IP address"});var ba=createRule({type:"macAddress",validator(e,t=":"){if(l(e))return !0;if(typeof e!="string")return !1;let i=typeof t=="string"&&t!==""?e.split(t):e.length===12||e.length===16?e.match(/.{2}/g):null;return i!==null&&(i.length===6||i.length===8)&&i.every(Pe)},message:"The value is not a valid MAC Address"}),Pe=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var Pa=createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var Aa=createRule({type:"contains",validator(e,t){return a(e)&&a(t)?e.includes(t):!0},message({$params:[e]}){return `Field must contain ${e}`}});var Na=createRule({type:"startsWith",validator(e,t){return a(e)&&a(t)?e.startsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var ka=createRule({type:"endsWith",validator(e,t){return a(e)&&a(t)?e.endsWith(t):!0},message({$params:[e]}){return `Field must end with ${e}`}});var La=createRule({type:"regex",validator(e,...t){return a(e)?y(e,...t):!0},message:"This field does not match the required pattern"});export{Zt as alpha,Xt as alphaNum,U as and,S as applyIf,rr as between,Pa as checked,Aa as contains,ra as dateAfter,sa as dateBefore,Ra as dateBetween,or as decimal,mr as email,ka as endsWith,Ir as exactLength,vr as exactValue,b as getSize,yr as integer,da as ipAddress,x as isDate,l as isEmpty,a as isFilled,p as isNumber,ba as macAddress,y as matchRegex,Lt as maxLength,Tr as maxValue,Mr as minLength,$r as minValue,K as not,Sr as numeric,G as or,La as regex,kt as required,Ot as requiredIf,qr as requiredUnless,jr as sameAs,Na as startsWith,T as toDate,d as toNumber,Jr as url,N as withAsync,$ as withMessage,E as withParams,W as withTooltip};
@@ -592,6 +592,22 @@ var minValue = createRule({
592
592
  return `The minimum value allowed is ${count}`;
593
593
  }
594
594
  });
595
+ var exactValue = createRule({
596
+ type: "exactValue",
597
+ validator: (value, count) => {
598
+ if (isFilled(value) && isFilled(count)) {
599
+ if (isNumber(count) && !isNaN(toNumber(value))) {
600
+ return toNumber(value) === count;
601
+ }
602
+ console.warn(`[exactValue] Value or parameter isn't a number, got value: ${value}, parameter: ${count}`);
603
+ return true;
604
+ }
605
+ return true;
606
+ },
607
+ message: ({ $params: [count] }) => {
608
+ return `The value must be equal to ${count}`;
609
+ }
610
+ });
595
611
  var exactLength = createRule({
596
612
  type: "exactLength",
597
613
  validator: (value, count) => {
@@ -824,4 +840,4 @@ var regex = createRule({
824
840
  message: "This field does not match the required pattern"
825
841
  });
826
842
 
827
- export { alpha, alphaNum, and, applyIf, between, checked, contains, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, getSize, integer, ipAddress, isDate, isEmpty, isFilled, isNumber, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, not, numeric, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, toDate, toNumber, url, withAsync, withMessage, withParams, withTooltip };
843
+ export { alpha, alphaNum, and, applyIf, between, checked, contains, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, integer, ipAddress, isDate, isEmpty, isFilled, isNumber, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, not, numeric, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, toDate, toNumber, url, withAsync, withMessage, withParams, withTooltip };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@regle/rules",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "description": "Collection of rules and helpers for Regle",
5
5
  "dependencies": {
6
- "@regle/core": "0.5.5"
6
+ "@regle/core": "0.5.7"
7
7
  },
8
8
  "devDependencies": {
9
9
  "@typescript-eslint/eslint-plugin": "8.18.1",
@@ -64,7 +64,7 @@
64
64
  "name": "Victor Garcia",
65
65
  "url": "https://github.com/victorgarciaesgi"
66
66
  },
67
- "homepage": "https://regle.vercel.app/",
67
+ "homepage": "https://reglejs.dev/",
68
68
  "repository": {
69
69
  "type": "git",
70
70
  "url": "git+https://github.com/victorgarciaesgi/regle.git"