@regle/rules 0.5.6 → 0.5.8

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
 
@@ -257,7 +257,7 @@ function and(...rules) {
257
257
  } else {
258
258
  const $params = rule._params;
259
259
  if (!$params?.length) {
260
- return [null];
260
+ return [];
261
261
  } else {
262
262
  return $params;
263
263
  }
@@ -321,8 +321,15 @@ function and(...rules) {
321
321
  validator,
322
322
  message: "The value does not match all of the provided validators"
323
323
  });
324
- newRule._params = _params;
325
- return newRule;
324
+ const newParams = [..._params ?? []];
325
+ newRule._params = newParams;
326
+ if (typeof newRule === "function") {
327
+ const executedRule = newRule(...newParams);
328
+ executedRule._message_patched = true;
329
+ return executedRule;
330
+ } else {
331
+ return newRule;
332
+ }
326
333
  }
327
334
  function or(...rules) {
328
335
  const isAnyRuleAsync = rules.some((rule) => {
@@ -332,14 +339,14 @@ function or(...rules) {
332
339
  return rule._async;
333
340
  }
334
341
  });
335
- const params = rules.map((rule) => {
342
+ const _params = rules.map((rule) => {
336
343
  if (typeof rule === "function") {
337
344
  return null;
338
345
  } else {
339
346
  return rule._params;
340
347
  }
341
348
  }).flat().filter((param) => !!param);
342
- function computeRules(rules2, value, ...params2) {
349
+ function computeRules(rules2, value, ...params) {
343
350
  const $rules = [];
344
351
  let paramIndex = 0;
345
352
  for (let rule of rules2) {
@@ -348,7 +355,7 @@ function or(...rules) {
348
355
  paramIndex++;
349
356
  } else {
350
357
  const paramsLength = rule._params?.length ?? 0;
351
- $rules.push(rule.validator(value, ...params2.slice(paramIndex, paramsLength)));
358
+ $rules.push(rule.validator(value, ...params.slice(paramIndex, paramsLength)));
352
359
  if (paramsLength) {
353
360
  paramIndex += paramsLength;
354
361
  }
@@ -378,11 +385,11 @@ function or(...rules) {
378
385
  return results.some((result) => !!result);
379
386
  }
380
387
  }
381
- const validator = isAnyRuleAsync ? async (value, ...params2) => {
382
- const results = await Promise.all(computeRules(rules, value, ...params2));
388
+ const validator = isAnyRuleAsync ? async (value, ...params) => {
389
+ const results = await Promise.all(computeRules(rules, value, ...params));
383
390
  return computeMetadata(results);
384
- } : (value, ...params2) => {
385
- const $rules = computeRules(rules, value, ...params2);
391
+ } : (value, ...params) => {
392
+ const $rules = computeRules(rules, value, ...params);
386
393
  return computeMetadata($rules);
387
394
  };
388
395
  const newRule = core.createRule({
@@ -390,8 +397,15 @@ function or(...rules) {
390
397
  validator,
391
398
  message: "The value does not match any of the provided validators"
392
399
  });
393
- newRule._params = params;
394
- return newRule;
400
+ const newParams = [..._params ?? []];
401
+ newRule._params = newParams;
402
+ if (typeof newRule === "function") {
403
+ const executedRule = newRule(...newParams);
404
+ executedRule._message_patched = true;
405
+ return executedRule;
406
+ } else {
407
+ return newRule;
408
+ }
395
409
  }
396
410
  function not(rule, message) {
397
411
  let _type;
@@ -427,8 +441,15 @@ function not(rule, message) {
427
441
  validator: newValidator,
428
442
  message: message ?? "Error"
429
443
  });
430
- newRule._params = _params;
431
- return newRule;
444
+ const newParams = [..._params ?? []];
445
+ newRule._params = newParams;
446
+ if (typeof newRule === "function") {
447
+ const executedRule = newRule(...newParams);
448
+ executedRule._message_patched = true;
449
+ return executedRule;
450
+ } else {
451
+ return newRule;
452
+ }
432
453
  }
433
454
  var required = core.createRule({
434
455
  type: "required",
@@ -594,6 +615,22 @@ var minValue = core.createRule({
594
615
  return `The minimum value allowed is ${count}`;
595
616
  }
596
617
  });
618
+ var exactValue = core.createRule({
619
+ type: "exactValue",
620
+ validator: (value, count) => {
621
+ if (isFilled(value) && isFilled(count)) {
622
+ if (isNumber(count) && !isNaN(toNumber(value))) {
623
+ return toNumber(value) === count;
624
+ }
625
+ console.warn(`[exactValue] Value or parameter isn't a number, got value: ${value}, parameter: ${count}`);
626
+ return true;
627
+ }
628
+ return true;
629
+ },
630
+ message: ({ $params: [count] }) => {
631
+ return `The value must be equal to ${count}`;
632
+ }
633
+ });
597
634
  var exactLength = core.createRule({
598
635
  type: "exactLength",
599
636
  validator: (value, count) => {
@@ -840,6 +877,7 @@ exports.decimal = decimal;
840
877
  exports.email = email;
841
878
  exports.endsWith = endsWith;
842
879
  exports.exactLength = exactLength;
880
+ exports.exactValue = exactValue;
843
881
  exports.getSize = getSize;
844
882
  exports.integer = integer;
845
883
  exports.ipAddress = ipAddress;
@@ -1,33 +1,116 @@
1
1
  import { RegleRuleMetadataDefinition, InlineRuleDeclaration, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, InferRegleRule, RegleRuleWithParamsDefinition, RegleRuleDefinition, UnwrapRegleUniversalParams, Maybe, FormRuleDeclaration } from '@regle/core';
2
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
 
74
+ /**
75
+ * The applyIf operator is similar to requiredIf, but it can be used with any rule. It simplifies conditional rule declarations.
76
+ */
16
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>;
17
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.
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
1
  import { RegleRuleMetadataDefinition, InlineRuleDeclaration, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, InferRegleRule, RegleRuleWithParamsDefinition, RegleRuleDefinition, UnwrapRegleUniversalParams, Maybe, FormRuleDeclaration } from '@regle/core';
2
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
 
74
+ /**
75
+ * The applyIf operator is similar to requiredIf, but it can be used with any rule. It simplifies conditional rule declarations.
76
+ */
16
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>;
17
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.
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 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 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,Kr=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=K;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=Kr;exports.withAsync=N;exports.withMessage=$;exports.withParams=E;exports.withTooltip=W;
1
+ 'use strict';var core=require('@regle/core'),vue=require('vue');function V(e,t){let i,o,u,f;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f}=e;let m=core.createRule({type:i,validator:o,active:u,message:t}),R=[...f??[]];if(m._params=R,m._message_patched=!0,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function v(e,t){let i,o,u,f,m;typeof e=="function"&&!("_validator"in e)?(i=core.InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f,_message:m}=e;let R=core.createRule({type:i,validator:o,active:u,message:m,tooltip:t}),r=[...f??[]];if(R._params=r,R._tooltip_patched=!0,typeof R=="function"){let s=R(...r);return R._tooltip_patched=!0,s}else return R}function N(e,t){let i=async(u,...f)=>e(u,...f),o=core.createRule({type:core.InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function k(e,t){let i=(u,...f)=>e(u,...f),o=core.createRule({type:core.InternalRuleType.Inline,validator:i,message:""});return o._params=o._params?.concat(t),o(...t)}function C(e,t){let i,o,u=[],f="";typeof t=="function"?(i=core.InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:f}=t,u=t._params?.concat([e]));function m(n,...p){let[b]=core.unwrapRuleParameters([e]);return b?o(n,...p):!0}function R(n){let[p]=core.unwrapRuleParameters([e]);return p}let r=core.createRule({type:i,validator:m,active:R,message:f}),s=[...u??[]];if(r._params=s,typeof r=="function"){let n=r(...s);return n._message_patched=!0,n}else return r}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 g(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 D(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 q(...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:[]}}).flat().filter(r=>!!r);function o(r,s,...n){let p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.every(n=>!!n)}let f;e.length?f=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)}:f=r=>!1;let m=core.createRule({type:"and",validator:f,message:"The value does not match all of the provided validators"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function O(...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 p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.some(n=>!!n)}let m=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"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function j(e,t){let i,o,u,f,m;typeof e=="function"?(o=e,m=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:f}=e,m=e._async),m?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"}),r=[...f??[]];if(R._params=r,typeof R=="function"){let s=R(...r);return s._message_patched=!0,s}else return R}var zt=core.createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Ut=core.createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 Kt=core.createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var Q=/^[a-zA-Z]*$/,Ht=core.createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Q)},message:"The value is not alphabetical"});var Y=/^[a-zA-Z0-9]*$/,Yt=core.createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Y)},message:"The value must be alpha-numeric"});var ar=core.createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=d(e),u=d(t),f=d(i);return y(o)&&y(u)&&y(f)?o>=u&&o<=f:(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 re=/^[-]?\d*(\.\d+)?$/,sr=core.createRule({type:"decimal",validator(e){return l(e)?!0:g(e,re)},message:"Value must be decimal"});var ne=/^(?:[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,fr=core.createRule({type:"email",validator(e){return l(e)?!0:g(e,ne)},message:"Value must be an valid email address"});var oe=/(^[0-9]*$)|(^-[0-9]+$)/,gr=core.createRule({type:"integer",validator(e){return l(e)?!0:g(e,oe)},message:"Value must be an integer"});var xr=core.createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?y(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 hr=core.createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 Vr=core.createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?y(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 _r=core.createRule({type:"exactValue",validator:(e,t)=>a(e)&&a(t)?y(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 Er=core.createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 pe=/^\d*(\.\d+)?$/,Cr=core.createRule({type:"numeric",validator(e){return l(e)?!0:g(e,pe)},message:"This field must be numeric"});var Gr=core.createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Br=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 ce=/^(?:(?:(?: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,Qr=core.createRule({type:"url",validator(e){return l(e)?!0:g(e,ce)},message:"The value is not a valid URL address"});function Te(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function h(e){return e?new Intl.DateTimeFormat(Te(),{dateStyle:"short"}).format(new Date(e)):"?"}var aa=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 ${h(e)}`});var la=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 ${h(e)}`});var pa=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 ${h(e)} and ${h(t)}`});function he(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 ca=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(he)},message:"The value is not a valid IP address"});var Da=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(we)},message:"The value is not a valid MAC Address"}),we=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var wa=core.createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var Wa=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 za=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 Ua=core.createRule({type:"regex",validator(e,...t){return a(e)?g(e,...t):!0},message:"This field does not match the required pattern"});exports.alpha=Ht;exports.alphaNum=Yt;exports.and=q;exports.applyIf=C;exports.between=ar;exports.checked=wa;exports.contains=Wa;exports.dateAfter=aa;exports.dateBefore=la;exports.dateBetween=pa;exports.decimal=sr;exports.email=fr;exports.endsWith=za;exports.exactLength=Er;exports.exactValue=_r;exports.getSize=D;exports.integer=gr;exports.ipAddress=ca;exports.isDate=x;exports.isEmpty=l;exports.isFilled=a;exports.isNumber=y;exports.macAddress=Da;exports.matchRegex=g;exports.maxLength=Ut;exports.maxValue=xr;exports.minLength=hr;exports.minValue=Vr;exports.not=j;exports.numeric=Cr;exports.or=O;exports.regex=Ua;exports.required=zt;exports.requiredIf=Kt;exports.requiredUnless=Gr;exports.sameAs=Br;exports.startsWith=Na;exports.toDate=T;exports.toNumber=d;exports.url=Qr;exports.withAsync=N;exports.withMessage=V;exports.withParams=k;exports.withTooltip=v;
@@ -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 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 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,Kr=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,K 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,Kr 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 V(e,t){let i,o,u,f;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f}=e;let m=createRule({type:i,validator:o,active:u,message:t}),R=[...f??[]];if(m._params=R,m._message_patched=!0,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function v(e,t){let i,o,u,f,m;typeof e=="function"&&!("_validator"in e)?(i=InternalRuleType.Inline,o=e):{_type:i,validator:o,_active:u,_params:f,_message:m}=e;let R=createRule({type:i,validator:o,active:u,message:m,tooltip:t}),r=[...f??[]];if(R._params=r,R._tooltip_patched=!0,typeof R=="function"){let s=R(...r);return R._tooltip_patched=!0,s}else return R}function N(e,t){let i=async(u,...f)=>e(u,...f),o=createRule({type:InternalRuleType.Async,validator:i,message:""});return o._params=o._params?.concat(t),o(...t??[])}function k(e,t){let i=(u,...f)=>e(u,...f),o=createRule({type:InternalRuleType.Inline,validator:i,message:""});return o._params=o._params?.concat(t),o(...t)}function C(e,t){let i,o,u=[],f="";typeof t=="function"?(i=InternalRuleType.Inline,o=t,u=[e]):({_type:i,validator:o,_message:f}=t,u=t._params?.concat([e]));function m(n,...p){let[b]=unwrapRuleParameters([e]);return b?o(n,...p):!0}function R(n){let[p]=unwrapRuleParameters([e]);return p}let r=createRule({type:i,validator:m,active:R,message:f}),s=[...u??[]];if(r._params=s,typeof r=="function"){let n=r(...s);return n._message_patched=!0,n}else return r}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 g(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 D(e){let t=unref(e);return Array.isArray(t)?t.length:typeof t=="object"?Object.keys(t).length:typeof t=="number"?isNaN(t)?0:t:String(t).length}function 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 q(...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:[]}}).flat().filter(r=>!!r);function o(r,s,...n){let p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r?.some(n=>typeof n!="boolean")?{$valid:r.every(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.every(n=>!!n)}let f;e.length?f=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)}:f=r=>!1;let m=createRule({type:"and",validator:f,message:"The value does not match all of the provided validators"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function O(...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 p=[],b=0;for(let c of r)if(typeof c=="function")p.push(c(s)),b++;else {let M=c._params?.length??0;p.push(c.validator(s,...n.slice(b,M))),M&&(b+=M);}return p}function u(r){return r.some(n=>typeof n!="boolean")?{$valid:r.some(n=>typeof n=="boolean"?!!n:n.$valid),...r.reduce((n,p)=>{if(typeof p=="boolean")return n;let{$valid:b,...c}=p;return {...n,...c}},{})}:r.some(n=>!!n)}let m=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"}),R=[...i??[]];if(m._params=R,typeof m=="function"){let r=m(...R);return r._message_patched=!0,r}else return m}function j(e,t){let i,o,u,f,m;typeof e=="function"?(o=e,m=e.constructor.name==="AsyncFunction"):({_type:i,validator:o,_params:f}=e,m=e._async),m?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"}),r=[...f??[]];if(R._params=r,typeof R=="function"){let s=R(...r);return s._message_patched=!0,s}else return R}var zt=createRule({type:"required",validator:e=>a(e),message:"This field is required"});var Ut=createRule({type:"maxLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 Kt=createRule({type:"required",validator(e,t){return t?a(e):!0},message:"This field is required",active({$params:[e]}){return e}});var Q=/^[a-zA-Z]*$/,Ht=createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Q)},message:"The value is not alphabetical"});var Y=/^[a-zA-Z0-9]*$/,Yt=createRule({type:"alpha",validator(e){return l(e)?!0:g(e,Y)},message:"The value must be alpha-numeric"});var ar=createRule({type:"between",validator:(e,t,i)=>{if(a(e)&&a(t)&&a(i)){let o=d(e),u=d(t),f=d(i);return y(o)&&y(u)&&y(f)?o>=u&&o<=f:(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 re=/^[-]?\d*(\.\d+)?$/,sr=createRule({type:"decimal",validator(e){return l(e)?!0:g(e,re)},message:"Value must be decimal"});var ne=/^(?:[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,fr=createRule({type:"email",validator(e){return l(e)?!0:g(e,ne)},message:"Value must be an valid email address"});var oe=/(^[0-9]*$)|(^-[0-9]+$)/,gr=createRule({type:"integer",validator(e){return l(e)?!0:g(e,oe)},message:"Value must be an integer"});var xr=createRule({type:"maxValue",validator:(e,t)=>a(e)&&a(t)?y(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 hr=createRule({type:"minLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 Vr=createRule({type:"minValue",validator:(e,t)=>a(e)&&a(t)?y(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 _r=createRule({type:"exactValue",validator:(e,t)=>a(e)&&a(t)?y(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 Er=createRule({type:"exactLength",validator:(e,t)=>a(e)&&a(t)?y(t)?D(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 pe=/^\d*(\.\d+)?$/,Cr=createRule({type:"numeric",validator(e){return l(e)?!0:g(e,pe)},message:"This field must be numeric"});var Gr=createRule({type:"required",validator(e,t){return t?!0:a(e)},message:"This field is required",active({$params:[e]}){return !e}});var Br=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 ce=/^(?:(?:(?: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,Qr=createRule({type:"url",validator(e){return l(e)?!0:g(e,ce)},message:"The value is not a valid URL address"});function Te(){return navigator.languages!=null?navigator.languages[0]:navigator.language}function h(e){return e?new Intl.DateTimeFormat(Te(),{dateStyle:"short"}).format(new Date(e)):"?"}var aa=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 ${h(e)}`});var la=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 ${h(e)}`});var pa=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 ${h(e)} and ${h(t)}`});function he(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 ca=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(he)},message:"The value is not a valid IP address"});var Da=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(we)},message:"The value is not a valid MAC Address"}),we=e=>e.toLowerCase().match(/^[0-9a-f]{2}$/);var wa=createRule({type:"checked",validator:e=>a(e)?e===!0:!0,message:"This field must be checked"});var Wa=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 za=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 Ua=createRule({type:"regex",validator(e,...t){return a(e)?g(e,...t):!0},message:"This field does not match the required pattern"});export{Ht as alpha,Yt as alphaNum,q as and,C as applyIf,ar as between,wa as checked,Wa as contains,aa as dateAfter,la as dateBefore,pa as dateBetween,sr as decimal,fr as email,za as endsWith,Er as exactLength,_r as exactValue,D as getSize,gr as integer,ca as ipAddress,x as isDate,l as isEmpty,a as isFilled,y as isNumber,Da as macAddress,g as matchRegex,Ut as maxLength,xr as maxValue,hr as minLength,Vr as minValue,j as not,Cr as numeric,O as or,Ua as regex,zt as required,Kt as requiredIf,Gr as requiredUnless,Br as sameAs,Na as startsWith,T as toDate,d as toNumber,Qr as url,N as withAsync,V as withMessage,k as withParams,v as withTooltip};
@@ -255,7 +255,7 @@ function and(...rules) {
255
255
  } else {
256
256
  const $params = rule._params;
257
257
  if (!$params?.length) {
258
- return [null];
258
+ return [];
259
259
  } else {
260
260
  return $params;
261
261
  }
@@ -319,8 +319,15 @@ function and(...rules) {
319
319
  validator,
320
320
  message: "The value does not match all of the provided validators"
321
321
  });
322
- newRule._params = _params;
323
- return newRule;
322
+ const newParams = [..._params ?? []];
323
+ newRule._params = newParams;
324
+ if (typeof newRule === "function") {
325
+ const executedRule = newRule(...newParams);
326
+ executedRule._message_patched = true;
327
+ return executedRule;
328
+ } else {
329
+ return newRule;
330
+ }
324
331
  }
325
332
  function or(...rules) {
326
333
  const isAnyRuleAsync = rules.some((rule) => {
@@ -330,14 +337,14 @@ function or(...rules) {
330
337
  return rule._async;
331
338
  }
332
339
  });
333
- const params = rules.map((rule) => {
340
+ const _params = rules.map((rule) => {
334
341
  if (typeof rule === "function") {
335
342
  return null;
336
343
  } else {
337
344
  return rule._params;
338
345
  }
339
346
  }).flat().filter((param) => !!param);
340
- function computeRules(rules2, value, ...params2) {
347
+ function computeRules(rules2, value, ...params) {
341
348
  const $rules = [];
342
349
  let paramIndex = 0;
343
350
  for (let rule of rules2) {
@@ -346,7 +353,7 @@ function or(...rules) {
346
353
  paramIndex++;
347
354
  } else {
348
355
  const paramsLength = rule._params?.length ?? 0;
349
- $rules.push(rule.validator(value, ...params2.slice(paramIndex, paramsLength)));
356
+ $rules.push(rule.validator(value, ...params.slice(paramIndex, paramsLength)));
350
357
  if (paramsLength) {
351
358
  paramIndex += paramsLength;
352
359
  }
@@ -376,11 +383,11 @@ function or(...rules) {
376
383
  return results.some((result) => !!result);
377
384
  }
378
385
  }
379
- const validator = isAnyRuleAsync ? async (value, ...params2) => {
380
- const results = await Promise.all(computeRules(rules, value, ...params2));
386
+ const validator = isAnyRuleAsync ? async (value, ...params) => {
387
+ const results = await Promise.all(computeRules(rules, value, ...params));
381
388
  return computeMetadata(results);
382
- } : (value, ...params2) => {
383
- const $rules = computeRules(rules, value, ...params2);
389
+ } : (value, ...params) => {
390
+ const $rules = computeRules(rules, value, ...params);
384
391
  return computeMetadata($rules);
385
392
  };
386
393
  const newRule = createRule({
@@ -388,8 +395,15 @@ function or(...rules) {
388
395
  validator,
389
396
  message: "The value does not match any of the provided validators"
390
397
  });
391
- newRule._params = params;
392
- return newRule;
398
+ const newParams = [..._params ?? []];
399
+ newRule._params = newParams;
400
+ if (typeof newRule === "function") {
401
+ const executedRule = newRule(...newParams);
402
+ executedRule._message_patched = true;
403
+ return executedRule;
404
+ } else {
405
+ return newRule;
406
+ }
393
407
  }
394
408
  function not(rule, message) {
395
409
  let _type;
@@ -425,8 +439,15 @@ function not(rule, message) {
425
439
  validator: newValidator,
426
440
  message: message ?? "Error"
427
441
  });
428
- newRule._params = _params;
429
- return newRule;
442
+ const newParams = [..._params ?? []];
443
+ newRule._params = newParams;
444
+ if (typeof newRule === "function") {
445
+ const executedRule = newRule(...newParams);
446
+ executedRule._message_patched = true;
447
+ return executedRule;
448
+ } else {
449
+ return newRule;
450
+ }
430
451
  }
431
452
  var required = createRule({
432
453
  type: "required",
@@ -592,6 +613,22 @@ var minValue = createRule({
592
613
  return `The minimum value allowed is ${count}`;
593
614
  }
594
615
  });
616
+ var exactValue = createRule({
617
+ type: "exactValue",
618
+ validator: (value, count) => {
619
+ if (isFilled(value) && isFilled(count)) {
620
+ if (isNumber(count) && !isNaN(toNumber(value))) {
621
+ return toNumber(value) === count;
622
+ }
623
+ console.warn(`[exactValue] Value or parameter isn't a number, got value: ${value}, parameter: ${count}`);
624
+ return true;
625
+ }
626
+ return true;
627
+ },
628
+ message: ({ $params: [count] }) => {
629
+ return `The value must be equal to ${count}`;
630
+ }
631
+ });
595
632
  var exactLength = createRule({
596
633
  type: "exactLength",
597
634
  validator: (value, count) => {
@@ -824,4 +861,4 @@ var regex = createRule({
824
861
  message: "This field does not match the required pattern"
825
862
  });
826
863
 
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 };
864
+ 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,13 +1,13 @@
1
1
  {
2
2
  "name": "@regle/rules",
3
- "version": "0.5.6",
3
+ "version": "0.5.8",
4
4
  "description": "Collection of rules and helpers for Regle",
5
5
  "dependencies": {
6
- "@regle/core": "0.5.6"
6
+ "@regle/core": "0.5.8"
7
7
  },
8
8
  "devDependencies": {
9
- "@typescript-eslint/eslint-plugin": "8.18.1",
10
- "@typescript-eslint/parser": "8.18.1",
9
+ "@typescript-eslint/eslint-plugin": "8.19.0",
10
+ "@typescript-eslint/parser": "8.19.0",
11
11
  "@vue/reactivity": "3.5.13",
12
12
  "@vue/test-utils": "2.4.6",
13
13
  "bumpp": "9.9.2",
@@ -18,7 +18,7 @@
18
18
  "eslint-plugin-vue": "9.31.0",
19
19
  "prettier": "3.3.3",
20
20
  "tsup": "8.3.5",
21
- "type-fest": "4.30.2",
21
+ "type-fest": "4.31.0",
22
22
  "typescript": "5.6.3",
23
23
  "vitest": "2.1.8",
24
24
  "vue": "3.5.13",
@@ -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"