@regle/rules 1.13.1 → 1.14.0

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.
@@ -2,132 +2,346 @@ import { CommonAlphaOptions, CommonComparisonOptions, ExtendedRulesDeclarations,
2
2
  import { ComputedRef, MaybeRef, MaybeRefOrGetter, Ref } from "vue";
3
3
  import { EmptyObject } from "type-fest";
4
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.
5
+ * The `withMessage` wrapper lets you associate an error message with a rule.
6
+ * Pass your rule as the first argument and the error message as the second.
6
7
  *
8
+ * @param rule - The rule to wrap (can be inline function or rule definition)
9
+ * @param newMessage - The error message (string or function returning a string)
10
+ *
11
+ * @example
7
12
  * ```ts
13
+ * import { withMessage } from '@regle/rules';
14
+ *
8
15
  * 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}
16
+ * name: {
17
+ * // With a static message
18
+ * customRule1: withMessage((value) => !!value, "Custom Error"),
19
+ * // With dynamic message using metadata
20
+ * customRule2: withMessage(
21
+ * customRuleInlineWithMetaData,
22
+ * ({ $value, foo }) => `Custom Error: ${$value} ${foo}`
23
+ * ),
24
+ * }
25
+ * })
26
+ * ```
27
+ *
28
+ * @see {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withmessage Documentation}
20
29
  */
21
30
  declare function withMessage<TValue$1 extends any, TParams$1 extends any[], TReturn$1 extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata$1 extends RegleRuleMetadataDefinition = (TReturn$1 extends Promise<infer M> ? M : TReturn$1), TAsync$1 extends boolean = (TReturn$1 extends Promise<any> ? true : false)>(rule: RegleRuleWithParamsDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue$1, RegleRuleMetadataConsumer<TValue$1, TParams$1, TMetadata$1>, string | string[]>): RegleRuleWithParamsDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>;
22
31
  declare function withMessage<TValue$1 extends any, TParams$1 extends unknown[], TReturn$1 extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata$1 extends RegleRuleMetadataDefinition = (TReturn$1 extends Promise<infer M> ? M : TReturn$1), TAsync$1 extends boolean = (TReturn$1 extends Promise<any> ? true : false)>(rule: RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue$1, RegleRuleMetadataConsumer<TValue$1, TParams$1, TMetadata$1>, string | string[]>): RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>;
23
32
  declare function withMessage<TValue$1 extends any, TParams$1 extends any[], TReturn$1 extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TAsync$1 extends boolean = (TReturn$1 extends Promise<any> ? true : false)>(rule: InlineRuleDeclaration<TValue$1, TParams$1, TReturn$1>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue$1, RegleRuleMetadataConsumer<TValue$1, TParams$1, TReturn$1 extends Promise<infer M> ? M : TReturn$1>, string | string[]>): RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TReturn$1 extends Promise<infer M> ? M : TReturn$1>;
24
33
  declare function withMessage<TValue$1 extends any, TParams$1 extends any[], TReturn$1 extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata$1 extends RegleRuleMetadataDefinition = (TReturn$1 extends Promise<infer M> ? M : TReturn$1), TAsync$1 extends boolean = (TReturn$1 extends Promise<any> ? true : false)>(rule: (...args: any[]) => RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>, newMessage: RegleRuleDefinitionWithMetadataProcessor<TValue$1, RegleRuleMetadataConsumer<TValue$1, TParams$1, TMetadata$1>, string | string[]>): RegleRuleWithParamsDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>;
25
34
  /**
26
- * The withTooltip wrapper allows you to display additional messages for your field that arent necessarily errors. Tooltips are aggregated and accessible via $fields.xxx.$tooltips .
35
+ * The `withTooltip` wrapper allows you to display additional messages for your field that aren't necessarily errors.
36
+ * Tooltips are aggregated and accessible via `$tooltips` property.
37
+ *
38
+ * @param rule - The rule to wrap (can be inline function or rule definition)
39
+ * @param newTooltip - The tooltip message (string or function returning a string)
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import { withTooltip, minLength } from '@regle/rules';
44
+ *
45
+ * const { r$ } = useRegle({ password: '' }, {
46
+ * password: {
47
+ * minLength: withTooltip(
48
+ * minLength(8),
49
+ * 'Password should be at least 8 characters for better security'
50
+ * ),
51
+ * }
52
+ * })
53
+ *
54
+ * // Access tooltips via:
55
+ * // r$.password.$tooltips
56
+ * ```
57
+ *
58
+ * @see {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withtooltip Documentation}
27
59
  */
28
60
  declare function withTooltip<TValue$1 extends any, TParams$1 extends any[], TReturn$1 extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata$1 extends RegleRuleMetadataDefinition = (TReturn$1 extends Promise<infer M> ? M : TReturn$1), TAsync$1 extends boolean = (TReturn$1 extends Promise<any> ? true : false)>(rule: RegleRuleWithParamsDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>, newTooltip: RegleRuleDefinitionWithMetadataProcessor<TValue$1, RegleRuleMetadataConsumer<TValue$1, TParams$1, TMetadata$1>, string | string[]>): RegleRuleWithParamsDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>;
29
61
  declare function withTooltip<TValue$1 extends any, TParams$1 extends any[], TReturn$1 extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TMetadata$1 extends RegleRuleMetadataDefinition = (TReturn$1 extends Promise<infer M> ? M : TReturn$1), TAsync$1 extends boolean = (TReturn$1 extends Promise<any> ? true : false)>(rule: RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>, newTooltip: RegleRuleDefinitionWithMetadataProcessor<TValue$1, RegleRuleMetadataConsumer<TValue$1, TParams$1, TMetadata$1>, string | string[]>): RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>;
30
62
  declare function withTooltip<TValue$1 extends any, TParams$1 extends any[], TReturn$1 extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition>, TAsync$1 extends boolean = (TReturn$1 extends Promise<any> ? true : false)>(rule: InlineRuleDeclaration<TValue$1, TParams$1, TReturn$1>, newTooltip: RegleRuleDefinitionWithMetadataProcessor<TValue$1, RegleRuleMetadataConsumer<TValue$1, TParams$1, TReturn$1 extends Promise<infer M> ? M : TReturn$1>, string | string[]>): RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TReturn$1 extends Promise<infer M> ? M : TReturn$1>;
31
63
  /**
32
- * withAsync works like withParams, but is specifically designed for async rules that depend on external values.
64
+ * `withAsync` works like `withParams`, but is specifically designed for async rules that depend on external values.
65
+ *
66
+ * @param rule - The async rule function
67
+ * @param depsArray - Array of reactive dependencies (refs or getters)
33
68
  *
69
+ * @example
34
70
  * ```ts
35
- *import { withAsync } from '@regle/rules';
36
-
37
- const base = ref('foo');
38
-
39
- const { r$ } = useRegle({ name: '' }, {
40
- name: {
41
- customRule: withAsync(async (value, param) => {
42
- await someAsyncCall(param)
43
- }, [base])
44
- }
45
- })
71
+ * import { withAsync } from '@regle/rules';
72
+ *
73
+ * const base = ref('foo');
74
+ *
75
+ * const { r$ } = useRegle({ name: '' }, {
76
+ * name: {
77
+ * customRule: withAsync(async (value, param) => {
78
+ * await someAsyncCall(param)
79
+ * }, [base])
80
+ * }
81
+ * })
46
82
  * ```
47
- * Docs: {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withasync}
83
+ *
84
+ * @see {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withasync Documentation}
48
85
  */
49
86
  declare function withAsync<TValue$1, TParams$1 extends (Ref<unknown> | (() => unknown))[] = [], TReturn$1 extends Promise<RegleRuleMetadataDefinition> = Promise<RegleRuleMetadataDefinition>, TMetadata$1 extends RegleRuleMetadataDefinition = (TReturn$1 extends Promise<infer M> ? M : TReturn$1)>(rule: InlineRuleDeclaration<TValue$1, TParams$1, TReturn$1>, depsArray?: [...TParams$1]): RegleRuleDefinition<TValue$1, UnwrapRegleUniversalParams<TParams$1>, true, TMetadata$1>;
50
87
  declare function withAsync<TValue$1 extends any, TParams$1 extends any[], TMetadata$1 extends RegleRuleMetadataDefinition>(rule: RegleRuleWithParamsDefinition<TValue$1, TParams$1, true, TMetadata$1>, depsArray?: [...TParams$1]): RegleRuleWithParamsDefinition<TValue$1, TParams$1, true, TMetadata$1>;
51
88
  /**
52
- * The withParams wrapper allows your rule to depend on external parameters, such as a reactive property in your component or store.
89
+ * The `withParams` wrapper allows your rule to depend on external parameters,
90
+ * such as a reactive property in your component or store.
53
91
  *
54
- * By default, useRegle observes changes automatically when rules are defined using getter functions or computed properties.
92
+ * By default, `useRegle` observes changes automatically when rules are defined using getter functions or computed properties.
93
+ * However, sometimes dependencies cannot be tracked automatically; use `withParams` to manually define them.
55
94
  *
95
+ * @param rule - The rule function or definition
96
+ * @param depsArray - Array of reactive dependencies (refs or getters)
97
+ *
98
+ * @example
56
99
  * ```ts
57
100
  * import { withParams } from '@regle/rules';
58
-
59
- const base = ref('foo');
60
-
61
- const { r$ } = useRegle({ name: '' }, {
62
- name: {
63
- customRule: withParams((value, param) => value === param, [base]),
64
- // or
65
- customRule: withParams((value, param) => value === param, [() => base.value]),
66
- }
67
- })
68
- * ```
69
- * Docs: {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withparams}
101
+ *
102
+ * const base = ref('foo');
103
+ *
104
+ * const { r$ } = useRegle({ name: '' }, {
105
+ * name: {
106
+ * customRule: withParams((value, param) => value === param, [base]),
107
+ * // or with getter
108
+ * customRule: withParams((value, param) => value === param, [() => base.value]),
109
+ * }
110
+ * })
111
+ * ```
112
+ *
113
+ * @see {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withparams Documentation}
70
114
  */
71
115
  declare function withParams<TValue$1, TParams$1 extends (Ref<unknown> | (() => unknown))[] = [], TReturn$1 extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TMetadata$1 extends RegleRuleMetadataDefinition = (TReturn$1 extends Promise<infer M> ? M : TReturn$1), TAsync$1 extends boolean = (TReturn$1 extends Promise<any> ? true : false)>(rule: InlineRuleDeclaration<TValue$1, TParams$1, TReturn$1> | RegleRuleDefinition<TValue$1, any[], TAsync$1, TMetadata$1>, depsArray: [...TParams$1]): RegleRuleDefinition<TValue$1, UnwrapRegleUniversalParams<TParams$1>, TAsync$1, TMetadata$1>;
72
116
  declare function withParams<TValue$1 extends any, TParams$1 extends any[], TReturn$1 extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TMetadata$1 extends RegleRuleMetadataDefinition = (TReturn$1 extends Promise<infer M> ? M : TReturn$1), TAsync$1 extends boolean = (TReturn$1 extends Promise<any> ? true : false)>(rule: RegleRuleWithParamsDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>, depsArray: [...TParams$1]): RegleRuleWithParamsDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>;
73
117
  /**
74
- * The applyIf operator is similar to requiredIf, but it can be used with any rule.
118
+ * The `applyIf` operator is similar to `requiredIf`, but it can be used with **any rule**.
75
119
  * It simplifies conditional rule declarations.
76
120
  *
121
+ * @param _condition - The condition to check (ref, getter, or value)
122
+ * @param rule - The rule to apply conditionally
123
+ * @returns A rule that only applies when the condition is truthy
124
+ *
77
125
  * @example
78
126
  * ```ts
127
+ * import { minLength, applyIf } from '@regle/rules';
128
+ *
79
129
  * const condition = ref(false);
80
- * const { r$ } = useRegle({name: ''}, {
130
+ *
131
+ * const { r$ } = useRegle({ name: '' }, {
81
132
  * name: {
82
133
  * minLength: applyIf(condition, minLength(6))
83
134
  * },
84
135
  * });
85
- *
86
136
  * ```
137
+ *
138
+ * @see {@link https://reglejs.dev/core-concepts/rules/rules-operators#applyif Documentation}
87
139
  */
88
140
  declare function applyIf<TRule extends FormRuleDeclaration<any>>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rule: TRule): TRule extends InlineRuleDeclaration<infer TValue, infer TParams, infer TReturn> ? RegleRuleDefinition<TValue, [...TParams, condition: boolean], TReturn extends Promise<any> ? true : false, TReturn extends Promise<infer M> ? M : TReturn> : TRule extends FormRuleDeclaration<infer TValue, infer TParams, any, infer TMetadata, infer TAsync> ? RegleRuleDefinition<TValue, [...TParams, condition: boolean], TAsync, TMetadata> : TRule;
89
141
  /**
90
- * This is almost a must have for optional fields. It checks if any value you provided is defined (including arrays and objects). You can base your validator result on this.
142
+ * Checks if any value you provide is defined (including arrays and objects).
143
+ * This is almost a must-have for optional fields when writing custom rules.
144
+ *
145
+ * `isFilled` also acts as a type guard.
146
+ *
147
+ * By default, it considers an empty array as `false`. You can override this behavior with `considerEmptyArrayInvalid`.
148
+ *
149
+ * @param value - The target value to check
150
+ * @param considerEmptyArrayInvalid - When `false`, empty arrays are considered filled (default: `true`)
151
+ * @returns `true` if the value is filled, `false` otherwise
152
+ *
153
+ * @example
154
+ * ```ts
155
+ * import { createRule } from '@regle/core';
156
+ * import { isFilled } from '@regle/rules';
91
157
  *
92
- * isFilled also acts as a type guard.
158
+ * const rule = createRule({
159
+ * validator(value: unknown) {
160
+ * if (isFilled(value)) {
161
+ * return check(value);
162
+ * }
163
+ * return true;
164
+ * },
165
+ * message: 'Error'
166
+ * })
167
+ * ```
93
168
  *
94
- * @param value - the target value
95
- * @param [considerEmptyArrayInvalid=true] - will return true if set to `false`. (default: `true`)
169
+ * @see {@link https://reglejs.dev/core-concepts/rules/validations-helpers#isfilled Documentation}
96
170
  */
97
171
  declare function isFilled<T extends unknown>(value: T, considerEmptyArrayInvalid?: boolean): value is NonNullable<T>;
98
172
  /**
99
- * This is a type guard that will check if the passed value is a real Number. This also returns false for NaN, so this is better than typeof value === "number".
173
+ * Type guard that checks if the passed value is a real `Number`.
174
+ * Returns `false` for `NaN`, making it safer than `typeof value === "number"`.
175
+ *
176
+ * @param value - The value to check
177
+ * @returns `true` if value is a valid number (not `NaN`), `false` otherwise
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * import { createRule, type Maybe } from '@regle/core';
182
+ * import { isFilled, isNumber } from '@regle/rules';
183
+ *
184
+ * const rule = createRule({
185
+ * validator(value: Maybe<number | string>) {
186
+ * if (isFilled(value) && isNumber(value)) {
187
+ * return checkNumber(value);
188
+ * }
189
+ * return true;
190
+ * },
191
+ * message: 'Error'
192
+ * })
193
+ * ```
194
+ *
195
+ * @see {@link https://reglejs.dev/core-concepts/rules/validations-helpers#isnumber Documentation}
100
196
  */
101
197
  declare function isNumber(value: unknown): value is number;
102
198
  /**
103
- * This utility can take multiple regular expressions as arguments. It checks the input's validity and tests it against the provided regex patterns.
199
+ * Tests a value against one or more regular expressions.
200
+ * Returns `true` if the value is empty or matches **all** provided patterns.
201
+ *
202
+ * @param _value - The value to test
203
+ * @param expr - One or more RegExp patterns to match against
204
+ * @returns `true` if empty or all patterns match, `false` otherwise
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * import { createRule, type Maybe } from '@regle/core';
209
+ * import { isFilled, matchRegex } from '@regle/rules';
210
+ *
211
+ * const regex = createRule({
212
+ * validator(value: Maybe<string>, regexps: RegExp[]) {
213
+ * if (isFilled(value)) {
214
+ * return matchRegex(value, ...regexps);
215
+ * }
216
+ * return true;
217
+ * },
218
+ * message: 'Error'
219
+ * })
220
+ * ```
221
+ *
222
+ * @see {@link https://reglejs.dev/core-concepts/rules/validations-helpers#matchregex Documentation}
104
223
  */
105
224
  declare function matchRegex(_value: string | number | null | undefined, ...expr: RegExp[]): boolean;
106
225
  /**
107
- * This helper will return the length of any data type you pass. It works with strings, arrays, objects and numbers.
226
+ * Returns the length/size of any data type. Works with strings, arrays, objects and numbers.
227
+ *
228
+ * @param value - The value to get the size of
229
+ * @returns The length of strings/arrays, number of keys for objects, or the number itself
230
+ *
231
+ * @example
232
+ * ```ts
233
+ * import { createRule, type Maybe } from '@regle/core';
234
+ * import { isFilled, getSize } from '@regle/rules';
235
+ *
236
+ * const rule = createRule({
237
+ * validator(value: Maybe<string | Array<number>>) {
238
+ * if (isFilled(value)) {
239
+ * return getSize(value) > 6;
240
+ * }
241
+ * return true;
242
+ * },
243
+ * message: 'Error'
244
+ * })
245
+ * ```
246
+ *
247
+ * @see {@link https://reglejs.dev/core-concepts/rules/validations-helpers#getsize Documentation}
108
248
  */
109
249
  declare function getSize(value: MaybeRef<string | any[] | Record<string, any> | number>): number;
110
250
  /**
111
- * This utility converts any string (or number) into a number using the Number constructor.
251
+ * Converts any string (or number) into a number using the `Number` constructor.
252
+ *
253
+ * @param argument - The value to convert
254
+ * @returns The converted number (⚠️ Warning: returned value can be `NaN`)
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * import { toNumber, isNumber } from '@regle/rules';
259
+ *
260
+ * const num = toNumber('42'); // 42
261
+ * const invalid = toNumber('abc'); // NaN
262
+ *
263
+ * // Always check for NaN when using toNumber
264
+ * if (!isNaN(toNumber(value))) {
265
+ * // Safe to use as number
266
+ * }
267
+ * ```
112
268
  *
113
- * @returns ⚠️ Warning, returned value can be NaN
269
+ * @see {@link https://reglejs.dev/core-concepts/rules/validations-helpers#tonumber Documentation}
114
270
  */
115
271
  declare function toNumber<T extends number | string | undefined>(argument: T): number;
116
272
  /**
117
- * This is the inverse of isFilled. It will check if the value is in any way empty (including arrays and objects)
273
+ * Checks if a value is empty in any way (including arrays and objects).
274
+ * This is the inverse of `isFilled`.
275
+ *
276
+ * `isEmpty` also acts as a type guard.
277
+ *
278
+ * By default, it considers an empty array as `true`. You can override this behavior with `considerEmptyArrayInvalid`.
279
+ *
280
+ * @param value - The target value to check
281
+ * @param considerEmptyArrayInvalid - When `false`, empty arrays are not considered empty (default: `true`)
282
+ * @returns `true` if the value is empty, `false` otherwise
118
283
  *
119
- * isEmpty also acts as a type guard.
284
+ * @example
285
+ * ```ts
286
+ * import { createRule, type Maybe } from '@regle/core';
287
+ * import { isEmpty } from '@regle/rules';
120
288
  *
121
- * @param value - the target value
122
- * @param [considerEmptyArrayInvalid=true] - will return false if set to `false`. (default: `true`)
289
+ * const rule = createRule({
290
+ * validator(value: Maybe<string>) {
291
+ * if (isEmpty(value)) {
292
+ * return true;
293
+ * }
294
+ * return check(value);
295
+ * },
296
+ * message: 'Error'
297
+ * })
298
+ * ```
299
+ *
300
+ * @see {@link https://reglejs.dev/core-concepts/rules/validations-helpers#isempty Documentation}
123
301
  */
124
302
  declare function isEmpty(value: unknown, considerEmptyArrayInvalid?: boolean): value is null | undefined | [] | EmptyObject;
125
303
  /**
126
- * This is a useful helper that can check if the provided value is a Date, it is used internally for date rules. This can also check strings.
304
+ * Checks if the provided value is a valid Date. Used internally for date rules.
305
+ * Can also validate date strings.
306
+ *
307
+ * @param value - The value to check
308
+ * @returns `true` if the value is a valid Date or date string, `false` otherwise
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * import { createRule, type Maybe } from '@regle/core';
313
+ * import { isFilled, isDate } from '@regle/rules';
314
+ *
315
+ * const rule = createRule({
316
+ * validator(value: Maybe<string | Date>) {
317
+ * if (isFilled(value) && isDate(value)) {
318
+ * return checkDate(value);
319
+ * }
320
+ * return true;
321
+ * },
322
+ * message: 'Error'
323
+ * })
324
+ * ```
325
+ *
326
+ * @see {@link https://reglejs.dev/core-concepts/rules/validations-helpers#isdate Documentation}
127
327
  */
128
328
  declare function isDate(value: unknown): value is Date | string;
129
329
  /**
130
- * This utility will coerce any string, number or Date value into a Date using the Date constructor.
330
+ * Coerces any string, number, or Date value into a `Date` using the `Date` constructor.
331
+ *
332
+ * @param argument - The value to convert to a Date
333
+ * @returns A new Date object (may be invalid if input cannot be parsed)
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * import { toDate } from '@regle/rules';
338
+ *
339
+ * const date1 = toDate('2024-01-15'); // Date object
340
+ * const date2 = toDate(1705276800000); // Date from timestamp
341
+ * const date3 = toDate(new Date()); // Clone of Date
342
+ * ```
343
+ *
344
+ * @see {@link https://reglejs.dev/core-concepts/rules/validations-helpers#todate Documentation}
131
345
  */
132
346
  declare function toDate(argument: Maybe<Date | number | string>): Date;
133
347
  type ExtractValueFromRules<T extends any[]> = T extends [infer F, ...infer R] ? F extends RegleRuleDefinition<infer V, any, any, any> ? [V, ...ExtractValueFromRules<R>] : F extends InlineRuleDeclaration<infer V, any> ? [V, ...ExtractValueFromRules<R>] : [F, ...ExtractValueFromRules<R>] : [];
@@ -145,78 +359,277 @@ type GuessMetadataFromRules<T extends any[], TMeta = ExtractMetadata<ExtractMeta
145
359
  type FilterTuple<T extends any[]> = T extends [infer F, ...infer R] ? [F] extends [[]] ? [...FilterTuple<R>] : [F, ...FilterTuple<R>] : [];
146
360
  type UnwrapTuples<T extends any[]> = FilterTuple<T> extends [infer U extends any[]] ? U : FilterTuple<T>;
147
361
  /**
148
- * The and operator combines multiple rules and validates successfully only if all provided rules are valid.
362
+ * The `and` operator combines multiple rules and validates successfully only if **all** provided rules are valid.
363
+ *
364
+ * @param rules - Two or more rules to combine
365
+ * @returns A combined rule that passes when all provided rules pass
366
+ *
367
+ * @example
368
+ * ```ts
369
+ * import { useRegle } from '@regle/core';
370
+ * import { and, startsWith, endsWith, withMessage } from '@regle/rules';
371
+ *
372
+ * const { r$ } = useRegle(
373
+ * { regex: '' },
374
+ * {
375
+ * regex: {
376
+ * myError: withMessage(
377
+ * and(startsWith('^'), endsWith('$')),
378
+ * ({ $params: [start, end] }) =>
379
+ * `Regex should start with "${start}" and end with "${end}"`
380
+ * ),
381
+ * },
382
+ * }
383
+ * );
384
+ * ```
385
+ *
386
+ * @see {@link https://reglejs.dev/core-concepts/rules/rules-operators#and Documentation}
149
387
  */
150
388
  declare function and<const TRules extends [FormRuleDeclaration<any, any>, ...FormRuleDeclaration<any, any>[]]>(...rules: [...TRules]): RegleRuleDefinition<ExtractValueFromRules<TRules>[number], UnwrapTuples<ExtractParamsFromRules<TRules>>, GuessAsyncFromRules<TRules>, GuessMetadataFromRules<TRules>>;
151
389
  /**
152
- * The or operator validates successfully if at least one of the provided rules is valid.
390
+ * The `or` operator validates successfully if **at least one** of the provided rules is valid.
391
+ *
392
+ * @param rules - Two or more rules to combine
393
+ * @returns A combined rule that passes when any of the provided rules pass
394
+ *
395
+ * @example
396
+ * ```ts
397
+ * import { useRegle } from '@regle/core';
398
+ * import { or, startsWith, endsWith, withMessage } from '@regle/rules';
399
+ *
400
+ * const { r$ } = useRegle(
401
+ * { regex: '' },
402
+ * {
403
+ * regex: {
404
+ * myError: withMessage(
405
+ * or(startsWith('^'), endsWith('$')),
406
+ * ({ $params: [start, end] }) =>
407
+ * `Field should start with "${start}" or end with "${end}"`
408
+ * ),
409
+ * },
410
+ * }
411
+ * );
412
+ * ```
413
+ *
414
+ * @see {@link https://reglejs.dev/core-concepts/rules/rules-operators#or Documentation}
153
415
  */
154
416
  declare function or<TRules extends [FormRuleDeclaration<any, any>, ...FormRuleDeclaration<any, any>[]]>(...rules: [...TRules]): RegleRuleDefinition<ExtractValueFromRules<TRules>[number], UnwrapTuples<ExtractParamsFromRules<TRules>>, GuessAsyncFromRules<TRules>, GuessMetadataFromRules<TRules>>;
155
417
  /**
156
- * The not operator passes when the provided rule fails and fails when the rule passes. It can be combined with other rules.
418
+ * The `not` operator passes when the provided rule **fails** and fails when the rule **passes**.
419
+ * It can be combined with other rules.
420
+ *
421
+ * @param rule - The rule to negate
422
+ * @param message - Optional custom error message
423
+ * @returns A negated rule
424
+ *
425
+ * @example
426
+ * ```ts
427
+ * import { useRegle } from '@regle/core';
428
+ * import { not, required, sameAs, withMessage } from '@regle/rules';
429
+ * import { ref } from 'vue';
430
+ *
431
+ * const form = ref({ oldPassword: '', newPassword: '' });
432
+ *
433
+ * const { r$ } = useRegle(form, {
434
+ * oldPassword: { required },
435
+ * newPassword: {
436
+ * notEqual: withMessage(
437
+ * not(sameAs(() => form.value.oldPassword)),
438
+ * 'Your new password must not be the same as your old password'
439
+ * ),
440
+ * },
441
+ * });
442
+ * ```
443
+ *
444
+ * @see {@link https://reglejs.dev/core-concepts/rules/rules-operators#not Documentation}
157
445
  */
158
446
  declare function not<TValue$1, TParams$1 extends any[] = [], TReturn$1 extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = RegleRuleMetadataDefinition, TMetadata$1 extends RegleRuleMetadataDefinition = (TReturn$1 extends Promise<infer M> ? M : TReturn$1), TAsync$1 extends boolean = (TReturn$1 extends Promise<any> ? true : false)>(rule: RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1> | InlineRuleDeclaration<TValue$1, TParams$1, TReturn$1>, message?: RegleRuleDefinitionWithMetadataProcessor<TValue$1, RegleRuleMetadataConsumer<TValue$1, TParams$1, TMetadata$1>, string | string[]>): RegleRuleDefinition<TValue$1, TParams$1, TAsync$1, TMetadata$1>;
159
447
  /**
160
- * The assignIf is a shorthand for conditional destructuring assignment.
161
- * It allows to apply multiple rules to a field conditionally.
448
+ * The `assignIf` is a shorthand for conditional destructuring assignment.
449
+ * It allows applying **multiple rules** to a field conditionally.
450
+ *
451
+ * @param _condition - The condition to check (ref, getter, or value)
452
+ * @param rules - An object of rules to apply conditionally
453
+ * @returns A computed ref containing the rules that only apply when the condition is truthy
162
454
  *
163
455
  * @example
164
456
  * ```ts
457
+ * import { required, email, minLength, assignIf } from '@regle/rules';
458
+ *
165
459
  * const condition = ref(false);
166
460
  *
167
461
  * const { r$ } = useRegle(ref({ name: '', email: '' }), {
168
462
  * name: assignIf(condition, { required, minLength: minLength(4) }),
169
463
  * email: { email },
170
- * })
464
+ * });
171
465
  * ```
466
+ *
467
+ * @see {@link https://reglejs.dev/core-concepts/rules/rules-operators#assignif Documentation}
172
468
  */
173
469
  declare function assignIf<TValue$1 extends unknown = any, TCustomRules extends Partial<ExtendedRulesDeclarations> = Partial<ExtendedRulesDeclarations>, TRulesDelc extends RegleRuleDecl<TValue$1, TCustomRules> = RegleRuleDecl<TValue$1, TCustomRules>>(_condition: MaybeRefOrGetter<Maybe<boolean>>, rules: MaybeRefOrGetter<TRulesDelc>, otherwiseRules?: MaybeRefOrGetter<TRulesDelc>): ComputedRef<TRulesDelc>;
174
470
  /**
175
471
  * Allows only alphabetic characters.
176
472
  *
177
- * @param [options] - Alpha rules options
178
- * */
473
+ * @param options - Optional configuration for alpha validation
474
+ *
475
+ * @example
476
+ * ```ts
477
+ * import { alpha } from '@regle/rules';
478
+ *
479
+ * const { r$ } = useRegle({ name: '' }, {
480
+ * name: {
481
+ * alpha,
482
+ * // or with symbols allowed
483
+ * alpha: alpha({ allowSymbols: true }),
484
+ * },
485
+ * })
486
+ * ```
487
+ *
488
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#alpha Documentation}
489
+ */
179
490
  declare const alpha: RegleRuleWithParamsDefinition<string, [options?: CommonAlphaOptions | undefined], false, boolean, MaybeInput<string>, string>;
180
491
  /**
181
492
  * Allows only alphanumeric characters.
182
493
  *
183
- * @param [options] - Alpha rules options
494
+ * @param options - Optional configuration for alphanumeric validation
495
+ *
496
+ * @example
497
+ * ```ts
498
+ * import { alphaNum } from '@regle/rules';
499
+ *
500
+ * const { r$ } = useRegle({ name: '' }, {
501
+ * name: {
502
+ * alphaNum,
503
+ * // or with symbols allowed
504
+ * alphaNum: alphaNum({ allowSymbols: true }),
505
+ * },
506
+ * })
507
+ * ```
508
+ *
509
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#alphanum Documentation}
184
510
  */
185
511
  declare const alphaNum: RegleRuleWithParamsDefinition<string | number, [options?: CommonAlphaOptions | undefined], false, boolean, MaybeInput<string>>;
186
512
  /**
187
- * Checks if a number is in specified bounds. min and max are both inclusive.
513
+ * Checks if a number is in specified bounds. `min` and `max` are both inclusive by default.
514
+ *
515
+ * @param min - The minimum limit
516
+ * @param max - The maximum limit
517
+ * @param options - Optional configuration (e.g., `{ allowEqual: false }` for exclusive bounds)
518
+ *
519
+ * @example
520
+ * ```ts
521
+ * import { between } from '@regle/rules';
522
+ *
523
+ * const maxCount = ref(6);
188
524
  *
189
- * @param min - the minimum limit
190
- * @param max - the maximum limit
525
+ * const { r$ } = useRegle({ count: 0 }, {
526
+ * count: {
527
+ * between: between(1, 6),
528
+ * // or with reactive max
529
+ * between: between(1, maxCount, { allowEqual: false }),
530
+ * // or with getter
531
+ * between: between(() => maxCount.value, 10)
532
+ * },
533
+ * })
534
+ * ```
535
+ *
536
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#between Documentation}
191
537
  */
192
538
  declare const between: RegleRuleWithParamsDefinition<number, [min: number, max: number, options?: CommonComparisonOptions], false, boolean, MaybeInput<number>>;
193
539
  /**
194
- * Requires a value to be a native boolean type
540
+ * Requires a value to be a native boolean type.
541
+ *
542
+ * Mainly used for typing with `InferInput`.
543
+ *
544
+ * @example
545
+ * ```ts
546
+ * import { type InferInput } from '@regle/core';
547
+ * import { boolean } from '@regle/rules';
548
+ *
549
+ * const rules = {
550
+ * checkbox: { boolean },
551
+ * }
552
+ *
553
+ * const state = ref<InferInput<typeof rules>>({});
554
+ * ```
195
555
  *
196
- * Mainly used for typing
556
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#boolean Documentation}
197
557
  */
198
558
  declare const boolean: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<boolean>, unknown>;
199
559
  /**
200
- * Requires a boolean value to be true. This is useful for checkbox inputs.
560
+ * Requires a boolean value to be `true`. This is useful for checkbox inputs like "accept terms".
561
+ *
562
+ * @example
563
+ * ```ts
564
+ * import { checked } from '@regle/rules';
565
+ *
566
+ * const { r$ } = useRegle({ confirm: false }, {
567
+ * confirm: { checked },
568
+ * })
569
+ * ```
570
+ *
571
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#checked Documentation}
201
572
  */
202
573
  declare const checked: RegleRuleDefinition<boolean, [], false, boolean, MaybeInput<boolean>>;
203
574
  /**
204
575
  * Checks if the string contains the specified substring.
205
576
  *
206
- * @param part - the part the value needs to contain
577
+ * @param part - The substring the value must contain
578
+ *
579
+ * @example
580
+ * ```ts
581
+ * import { contains } from '@regle/rules';
582
+ *
583
+ * const { r$ } = useRegle({ bestLib: '' }, {
584
+ * bestLib: {
585
+ * contains: contains('regle')
586
+ * },
587
+ * })
588
+ * ```
589
+ *
590
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#contains Documentation}
207
591
  */
208
592
  declare const contains: RegleRuleWithParamsDefinition<string, [part: MaybeInput<string>], false, boolean, MaybeInput<string>>;
209
593
  /**
210
- * Requires a value to be a native Date constructor
594
+ * Requires a value to be a native `Date` constructor.
595
+ *
596
+ * Mainly used for typing with `InferInput`.
597
+ *
598
+ * @example
599
+ * ```ts
600
+ * import { type InferInput } from '@regle/core';
601
+ * import { date } from '@regle/rules';
211
602
  *
212
- * Mainly used for typing
603
+ * const rules = {
604
+ * birthday: { date },
605
+ * }
606
+ *
607
+ * const state = ref<InferInput<typeof rules>>({});
608
+ * ```
609
+ *
610
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#date Documentation}
213
611
  */
214
612
  declare const date: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<Date>, unknown>;
215
613
  /**
216
614
  * Checks if the date is after the given parameter.
217
615
  *
218
- * @param after - the date to compare to
219
- * @param options - comparison options
616
+ * @param after - The date to compare to (can be a `Date`, string, ref, or getter)
617
+ * @param options - Optional configuration (e.g., `{ allowEqual: false }`)
618
+ *
619
+ * @example
620
+ * ```ts
621
+ * import { dateAfter } from '@regle/rules';
622
+ *
623
+ * const { r$ } = useRegle({ birthday: null as Date | null }, {
624
+ * birthday: {
625
+ * dateAfter: dateAfter(new Date()),
626
+ * // or with options
627
+ * dateAfter: dateAfter(new Date(), { allowEqual: false }),
628
+ * },
629
+ * })
630
+ * ```
631
+ *
632
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#dateafter Documentation}
220
633
  */
221
634
  declare const dateAfter: RegleRuleWithParamsDefinition<string | Date, [after: MaybeInput<string | Date>, options?: CommonComparisonOptions], false, true | {
222
635
  $valid: false;
@@ -228,8 +641,23 @@ declare const dateAfter: RegleRuleWithParamsDefinition<string | Date, [after: Ma
228
641
  /**
229
642
  * Checks if the date is before the given parameter.
230
643
  *
231
- * @param before - the date to compare to
232
- * @param options - comparison options
644
+ * @param before - The date to compare to (can be a `Date`, string, ref, or getter)
645
+ * @param options - Optional configuration (e.g., `{ allowEqual: false }`)
646
+ *
647
+ * @example
648
+ * ```ts
649
+ * import { dateBefore } from '@regle/rules';
650
+ *
651
+ * const { r$ } = useRegle({ birthday: null as Date | null }, {
652
+ * birthday: {
653
+ * dateBefore: dateBefore(new Date()),
654
+ * // or with options
655
+ * dateBefore: dateBefore(new Date(), { allowEqual: false }),
656
+ * },
657
+ * })
658
+ * ```
659
+ *
660
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#datebefore Documentation}
233
661
  */
234
662
  declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [before: MaybeInput<string | Date>, options?: CommonComparisonOptions], false, true | {
235
663
  $valid: false;
@@ -241,101 +669,368 @@ declare const dateBefore: RegleRuleWithParamsDefinition<string | Date, [before:
241
669
  /**
242
670
  * Checks if the date falls between the specified bounds.
243
671
  *
244
- * @param before - the minimum limit
245
- * @param after - the maximum limit
246
- * @param options - comparison options
672
+ * @param before - The minimum date limit
673
+ * @param after - The maximum date limit
674
+ * @param options - Optional configuration (e.g., `{ allowEqual: false }`)
675
+ *
676
+ * @example
677
+ * ```ts
678
+ * import { dateBetween } from '@regle/rules';
679
+ *
680
+ * const { r$ } = useRegle({ birthday: null as Date | null }, {
681
+ * birthday: {
682
+ * dateBetween: dateBetween(new Date(), new Date(2030, 3, 1)),
683
+ * // or with options
684
+ * dateBetween: dateBetween(new Date(), new Date(2030, 3, 1), { allowEqual: false }),
685
+ * },
686
+ * })
687
+ * ```
688
+ *
689
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#datebetweeen Documentation}
247
690
  */
248
691
  declare const dateBetween: RegleRuleWithParamsDefinition<string | Date, [before: MaybeInput<string | Date>, after: MaybeInput<string | Date>, options?: CommonComparisonOptions], false, boolean, MaybeInput<string | Date>>;
249
692
  /**
250
693
  * Allows positive and negative decimal numbers.
694
+ *
695
+ * @example
696
+ * ```ts
697
+ * import { decimal } from '@regle/rules';
698
+ *
699
+ * const { r$ } = useRegle({ price: 0 }, {
700
+ * price: { decimal },
701
+ * })
702
+ * ```
703
+ *
704
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#decimal Documentation}
251
705
  */
252
706
  declare const decimal: RegleRuleDefinition<string | number, [], false, boolean, MaybeInput<number | undefined>>;
253
707
  /**
254
708
  * Validates email addresses. Always verify on the server to ensure the address is real and not already in use.
709
+ *
710
+ * @example
711
+ * ```ts
712
+ * import { email } from '@regle/rules';
713
+ *
714
+ * const { r$ } = useRegle({ email: '' }, {
715
+ * email: { email },
716
+ * })
717
+ * ```
718
+ *
719
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#email Documentation}
255
720
  */
256
721
  declare const email: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
257
722
  /**
258
723
  * Checks if the string ends with the specified substring.
259
724
  *
260
- * @param part - the value the field must end with
725
+ * @param part - The substring the value must end with
726
+ *
727
+ * @example
728
+ * ```ts
729
+ * import { endsWith } from '@regle/rules';
730
+ *
731
+ * const { r$ } = useRegle({ firstName: '' }, {
732
+ * firstName: { endsWith: endsWith('foo') },
733
+ * })
734
+ * ```
735
+ *
736
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#endswith Documentation}
261
737
  */
262
738
  declare const endsWith: RegleRuleWithParamsDefinition<string, [part: MaybeInput<string>], false, boolean, MaybeInput<string>>;
263
739
  /**
264
- * Requires the input value to have a strict specified length, inclusive. Works with arrays, objects and strings.
740
+ * Requires the input value to have a strict specified length. Works with arrays, objects and strings.
741
+ *
742
+ * @param count - The exact required length
743
+ *
744
+ * @example
745
+ * ```ts
746
+ * import { exactLength } from '@regle/rules';
747
+ *
748
+ * const exactValue = ref(6);
265
749
  *
266
- * @param count - the required length
750
+ * const { r$ } = useRegle({ name: '' }, {
751
+ * name: {
752
+ * exactLength: exactLength(6),
753
+ * // or with reactive value
754
+ * exactLength: exactLength(exactValue),
755
+ * // or with getter
756
+ * exactLength: exactLength(() => exactValue.value)
757
+ * },
758
+ * })
759
+ * ```
760
+ *
761
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#exactlength Documentation}
267
762
  */
268
763
  declare const exactLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number], false, boolean>;
269
764
  /**
270
765
  * Requires a field to have a strict numeric value.
766
+ *
767
+ * @param count - The exact required numeric value
768
+ *
769
+ * @example
770
+ * ```ts
771
+ * import { exactValue } from '@regle/rules';
772
+ *
773
+ * const exactCount = ref(6);
774
+ *
775
+ * const { r$ } = useRegle({ count: 0 }, {
776
+ * count: {
777
+ * exactValue: exactValue(6),
778
+ * // or with reactive value
779
+ * exactValue: exactValue(exactCount),
780
+ * // or with getter
781
+ * exactValue: exactValue(() => exactCount.value)
782
+ * },
783
+ * })
784
+ * ```
785
+ *
786
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#exactvalue Documentation}
271
787
  */
272
788
  declare const exactValue: RegleRuleWithParamsDefinition<number, [count: number], false, boolean, MaybeInput<number>>;
273
789
  /**
274
- * Allows only hexadecimal values.
790
+ * Validates hexadecimal values.
791
+ *
792
+ * @example
793
+ * ```ts
794
+ * import { hexadecimal } from '@regle/rules';
795
+ *
796
+ * const { r$ } = useRegle({ hexadecimal: '' }, {
797
+ * hexadecimal: { hexadecimal },
798
+ * })
799
+ * ```
800
+ *
801
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#hexadecimal Documentation}
275
802
  */
276
803
  declare const hexadecimal: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
277
804
  /**
278
805
  * Allows only integers (positive and negative).
806
+ *
807
+ * @example
808
+ * ```ts
809
+ * import { integer } from '@regle/rules';
810
+ *
811
+ * const { r$ } = useRegle({ count: 0 }, {
812
+ * count: { integer },
813
+ * })
814
+ * ```
815
+ *
816
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#integer Documentation}
279
817
  */
280
818
  declare const integer: RegleRuleDefinition<string | number, [], false, boolean, MaybeInput<number>>;
281
819
  /**
282
- * Validates IPv4 addresses in dotted decimal notation 127.0.0.1.
820
+ * Validates IPv4 addresses in dotted decimal notation (e.g., `127.0.0.1`).
821
+ *
822
+ * @example
823
+ * ```ts
824
+ * import { ipv4Address } from '@regle/rules';
825
+ *
826
+ * const { r$ } = useRegle({ address: '' }, {
827
+ * address: { ipv4Address },
828
+ * })
829
+ * ```
830
+ *
831
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#ipv4address Documentation}
283
832
  */
284
833
  declare const ipv4Address: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
285
834
  /**
286
- * Allow only one possible literal value
835
+ * Allow only one possible literal value.
836
+ *
837
+ * @param literal - The literal value to match
838
+ *
839
+ * @example
840
+ * ```ts
841
+ * import { literal } from '@regle/rules';
842
+ *
843
+ * const { r$ } = useRegle({ status: '' }, {
844
+ * status: { literal: literal('active') },
845
+ * })
846
+ * ```
847
+ *
848
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#literal Documentation}
287
849
  */
288
850
  declare function literal<const TValue$1 extends string | number>(literal: MaybeRefOrGetter<TValue$1>): RegleRuleDefinition<TValue$1, [literal: TValue$1], false, boolean, MaybeInput<TValue$1>, string | number>;
289
851
  /**
290
- * Validates MAC addresses. Call as a function to specify a custom separator (e.g., ':' or an empty string for 00ff1122334455).
852
+ * Validates MAC addresses. Call as a function to specify a custom separator (e.g., `':'` or an empty string for `00ff1122334455`).
853
+ *
854
+ * @param separator - The custom separator (default: `':'`)
855
+ *
856
+ * @example
857
+ * ```ts
858
+ * import { macAddress } from '@regle/rules';
291
859
  *
292
- * @param separator - the custom separator
860
+ * const { r$ } = useRegle({ address: '' }, {
861
+ * address: {
862
+ * macAddress,
863
+ * // or with custom separator
864
+ * macAddress: macAddress('-')
865
+ * },
866
+ * })
867
+ * ```
868
+ *
869
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#macaddress Documentation}
293
870
  */
294
871
  declare const macAddress: RegleRuleWithParamsDefinition<string, [separator?: string | undefined], false, boolean, MaybeInput<string>>;
295
872
  /**
296
873
  * Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.
297
874
  *
298
- * @param max - the maximum length
299
- * @param options - comparison options
875
+ * @param max - The maximum length
876
+ * @param options - Optional configuration (e.g., `{ allowEqual: false }`)
877
+ *
878
+ * @example
879
+ * ```ts
880
+ * import { maxLength } from '@regle/rules';
881
+ *
882
+ * const maxValue = ref(6);
883
+ *
884
+ * const { r$ } = useRegle({ name: '' }, {
885
+ * name: {
886
+ * maxLength: maxLength(6),
887
+ * // or with reactive value
888
+ * maxLength: maxLength(maxValue),
889
+ * // or with getter
890
+ * maxLength: maxLength(() => maxValue.value)
891
+ * },
892
+ * })
893
+ * ```
894
+ *
895
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#maxlength Documentation}
300
896
  */
301
- declare const maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
897
+ declare const maxLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [max: number, options?: CommonComparisonOptions], false, boolean>;
302
898
  /**
303
899
  * Requires a field to have a specified maximum numeric value.
304
900
  *
305
- * @param max - the maximum value
306
- * @param options - comparison options
901
+ * @param max - The maximum value
902
+ * @param options - Optional configuration (e.g., `{ allowEqual: false }`)
903
+ *
904
+ * @example
905
+ * ```ts
906
+ * import { maxValue } from '@regle/rules';
907
+ *
908
+ * const maxCount = ref(6);
909
+ *
910
+ * const { r$ } = useRegle({ count: 0 }, {
911
+ * count: {
912
+ * maxValue: maxValue(6),
913
+ * // or with options
914
+ * maxValue: maxValue(maxCount, { allowEqual: false }),
915
+ * // or with getter
916
+ * maxValue: maxValue(() => maxCount.value)
917
+ * },
918
+ * })
919
+ * ```
920
+ *
921
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#maxvalue Documentation}
307
922
  */
308
- declare const maxValue: RegleRuleWithParamsDefinition<number | string, [count: number | string, options?: CommonComparisonOptions], false, boolean, MaybeInput<number | string>>;
923
+ declare const maxValue: RegleRuleWithParamsDefinition<number | string, [max: number | string, options?: CommonComparisonOptions], false, boolean, MaybeInput<number | string>>;
309
924
  /**
310
925
  * Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.
311
926
  *
312
- * @param min - the minimum value
313
- * @param options - comparison options
927
+ * @param min - The minimum length
928
+ * @param options - Optional configuration (e.g., `{ allowEqual: false }`)
929
+ *
930
+ * @example
931
+ * ```ts
932
+ * import { minLength } from '@regle/rules';
933
+ *
934
+ * const minValue = ref(6);
935
+ *
936
+ * const { r$ } = useRegle({ name: '' }, {
937
+ * name: {
938
+ * minLength: minLength(6),
939
+ * // or with reactive value
940
+ * minLength: minLength(minValue),
941
+ * // or with getter
942
+ * minLength: minLength(() => minValue.value)
943
+ * },
944
+ * })
945
+ * ```
946
+ *
947
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#minlength Documentation}
314
948
  */
315
- declare const minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [count: number, options?: CommonComparisonOptions], false, boolean>;
949
+ declare const minLength: RegleRuleWithParamsDefinition<string | any[] | Record<PropertyKey, any>, [min: number, options?: CommonComparisonOptions], false, boolean>;
316
950
  /**
317
951
  * Requires a field to have a specified minimum numeric value.
318
952
  *
319
- * @param count - the minimum count
320
- * @param options - comparison options
953
+ * @param min - The minimum value
954
+ * @param options - Optional configuration (e.g., `{ allowEqual: false }`)
955
+ *
956
+ * @example
957
+ * ```ts
958
+ * import { minValue } from '@regle/rules';
959
+ *
960
+ * const minCount = ref(6);
961
+ *
962
+ * const { r$ } = useRegle({ count: 0 }, {
963
+ * count: {
964
+ * minValue: minValue(6),
965
+ * // or with options
966
+ * minValue: minValue(minCount, { allowEqual: false }),
967
+ * // or with getter
968
+ * minValue: minValue(() => minCount.value)
969
+ * },
970
+ * })
971
+ * ```
972
+ *
973
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#minvalue Documentation}
321
974
  */
322
- declare const minValue: RegleRuleWithParamsDefinition<number | string, [count: number | string, options?: CommonComparisonOptions], false, boolean, MaybeInput<number | string>>;
975
+ declare const minValue: RegleRuleWithParamsDefinition<number | string, [min: number | string, options?: CommonComparisonOptions], false, boolean, MaybeInput<number | string>>;
323
976
  type EnumLike = {
324
977
  [k: string]: string | number;
325
978
  [nu: number]: string;
326
979
  };
327
980
  /**
328
- * Validate against a native Typescript enum value.
981
+ * Validate against a native TypeScript enum value. Similar to Zod's `nativeEnum`.
982
+ *
983
+ * @param enumLike - The TypeScript enum to validate against
984
+ *
985
+ * @example
986
+ * ```ts
987
+ * import { nativeEnum } from '@regle/rules';
988
+ *
989
+ * enum Foo {
990
+ * Bar, Baz
991
+ * }
992
+ *
993
+ * const { r$ } = useRegle({ type: '' }, {
994
+ * type: { nativeEnum: nativeEnum(Foo) },
995
+ * })
996
+ * ```
997
+ *
998
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#nativeenum Documentation}
329
999
  */
330
1000
  declare function nativeEnum<T extends EnumLike>(enumLike: T): RegleRuleDefinition<MaybeInput<T[keyof T]>, [enumLike: T], false, boolean, MaybeInput<T[keyof T]>, string | number>;
331
1001
  /**
332
- * Requires a value to be a native number type
1002
+ * Requires a value to be a native number type.
1003
+ *
1004
+ * Mainly used for typing with `InferInput`.
1005
+ *
1006
+ * @example
1007
+ * ```ts
1008
+ * import { type InferInput } from '@regle/core';
1009
+ * import { number } from '@regle/rules';
1010
+ *
1011
+ * const rules = {
1012
+ * count: { number },
1013
+ * }
1014
+ *
1015
+ * const state = ref<InferInput<typeof rules>>({});
1016
+ * ```
333
1017
  *
334
- * Mainly used for typing
1018
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#number Documentation}
335
1019
  */
336
1020
  declare const number: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<number>, unknown>;
337
1021
  /**
338
1022
  * Allows only numeric values (including numeric strings).
1023
+ *
1024
+ * @example
1025
+ * ```ts
1026
+ * import { numeric } from '@regle/rules';
1027
+ *
1028
+ * const { r$ } = useRegle({ count: 0 }, {
1029
+ * count: { numeric },
1030
+ * })
1031
+ * ```
1032
+ *
1033
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#numeric Documentation}
339
1034
  */
340
1035
  declare const numeric: RegleRuleDefinition<string | number, [], false, boolean, MaybeInput<string | number>>;
341
1036
  interface OneOfFn {
@@ -345,26 +1040,105 @@ interface OneOfFn {
345
1040
  }
346
1041
  /**
347
1042
  * Allow only one of the values from a fixed Array of possible entries.
1043
+ *
1044
+ * @param options - Array of allowed values
1045
+ *
1046
+ * @example
1047
+ * ```ts
1048
+ * import { oneOf } from '@regle/rules';
1049
+ *
1050
+ * const { r$ } = useRegle({ aliment: 'Fish' }, {
1051
+ * aliment: {
1052
+ * oneOf: oneOf(['Fish', 'Meat', 'Bone'])
1053
+ * },
1054
+ * })
1055
+ * ```
1056
+ *
1057
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#oneof Documentation}
348
1058
  */
349
1059
  declare const oneOf: OneOfFn;
350
1060
  /**
351
1061
  * Checks if the value matches one or more regular expressions.
1062
+ *
1063
+ * @param regexp - A single RegExp or an array of RegExp patterns
1064
+ *
1065
+ * @example
1066
+ * ```ts
1067
+ * import { regex } from '@regle/rules';
1068
+ *
1069
+ * const { r$ } = useRegle({ name: '' }, {
1070
+ * name: {
1071
+ * regex: regex(/^foo/),
1072
+ * // or with multiple patterns
1073
+ * regex: regex([/^bar/, /baz$/]),
1074
+ * },
1075
+ * })
1076
+ * ```
1077
+ *
1078
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#regex Documentation}
352
1079
  */
353
1080
  declare const regex: RegleRuleWithParamsDefinition<string | number, [regexp: RegExp | RegExp[]], false, boolean, MaybeInput<string | number>>;
354
1081
  /**
355
1082
  * Requires non-empty data. Checks for empty arrays and strings containing only whitespaces.
1083
+ *
1084
+ * @example
1085
+ * ```ts
1086
+ * import { required } from '@regle/rules';
1087
+ *
1088
+ * const { r$ } = useRegle({ name: '' }, {
1089
+ * name: { required },
1090
+ * })
1091
+ * ```
1092
+ *
1093
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#required Documentation}
356
1094
  */
357
1095
  declare const required: RegleRuleDefinition<unknown, [], false, boolean, unknown>;
358
1096
  /**
359
- * Requires non-empty data, only if provided data property, ref, or a function resolves to true.
1097
+ * Requires non-empty data, only if provided data property, ref, or a function resolves to `true`.
1098
+ *
1099
+ * @param condition - The condition to enable the required rule (can be a ref, getter, or value)
1100
+ *
1101
+ * @example
1102
+ * ```ts
1103
+ * import { requiredIf } from '@regle/rules';
1104
+ *
1105
+ * const form = ref({ name: '', condition: false });
1106
+ * const conditionRef = ref(false);
1107
+ *
1108
+ * const { r$ } = useRegle(form, {
1109
+ * name: {
1110
+ * required: requiredIf(() => form.value.condition),
1111
+ * // or with a ref
1112
+ * required: requiredIf(conditionRef),
1113
+ * },
1114
+ * })
1115
+ * ```
360
1116
  *
361
- * @param condition - the condition to enable the required rule
1117
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#requiredif Documentation}
362
1118
  */
363
1119
  declare const requiredIf: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
364
1120
  /**
365
- * Requires non-empty data, only if provided data property, ref, or a function resolves to false.
1121
+ * Requires non-empty data, only if provided data property, ref, or a function resolves to `false`.
1122
+ *
1123
+ * @param condition - The condition to disable the required rule (can be a ref, getter, or value)
1124
+ *
1125
+ * @example
1126
+ * ```ts
1127
+ * import { requiredUnless } from '@regle/rules';
1128
+ *
1129
+ * const form = ref({ name: '', condition: false });
1130
+ * const conditionRef = ref(false);
1131
+ *
1132
+ * const { r$ } = useRegle(form, {
1133
+ * name: {
1134
+ * required: requiredUnless(() => form.value.condition),
1135
+ * // or with a ref
1136
+ * required: requiredUnless(conditionRef)
1137
+ * },
1138
+ * })
1139
+ * ```
366
1140
  *
367
- * @param condition - the condition to disable the required rule
1141
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#requiredunless Documentation}
368
1142
  */
369
1143
  declare const requiredUnless: RegleRuleWithParamsDefinition<unknown, [condition: boolean], false, boolean>;
370
1144
  interface SameAsFn {
@@ -373,29 +1147,103 @@ interface SameAsFn {
373
1147
  (target: MaybeRefOrGetter<unknown>, otherName?: MaybeRefOrGetter<string>): RegleRuleDefinition<unknown, [target: any, otherName?: string], false, boolean, unknown extends MaybeInput<infer M> ? M : MaybeInput<unknown>>;
374
1148
  }
375
1149
  /**
376
- * Checks if the value matches the specified property or ref.
1150
+ * Checks if the value matches the specified property or ref. Useful for password confirmation fields.
1151
+ *
1152
+ * @param target - The target value to compare against (can be a ref or getter)
1153
+ * @param otherName - Optional name for the other field (used in error message)
1154
+ *
1155
+ * @example
1156
+ * ```ts
1157
+ * import { sameAs } from '@regle/rules';
1158
+ *
1159
+ * const form = ref({
1160
+ * password: '',
1161
+ * confirmPassword: '',
1162
+ * });
1163
+ *
1164
+ * const { r$ } = useRegle(form, {
1165
+ * confirmPassword: {
1166
+ * sameAs: sameAs(() => form.value.password),
1167
+ * }
1168
+ * })
1169
+ * ```
1170
+ *
1171
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#sameas Documentation}
377
1172
  */
378
1173
  declare const sameAs: SameAsFn;
379
1174
  /**
380
1175
  * Checks if the string starts with the specified substring.
381
1176
  *
382
- * @private part - the value the field must start with
1177
+ * @param part - The substring the value must start with
1178
+ *
1179
+ * @example
1180
+ * ```ts
1181
+ * import { startsWith } from '@regle/rules';
1182
+ *
1183
+ * const { r$ } = useRegle({ bestLib: '' }, {
1184
+ * bestLib: {
1185
+ * startsWith: startsWith('regle')
1186
+ * },
1187
+ * })
1188
+ * ```
1189
+ *
1190
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#startswith Documentation}
383
1191
  */
384
1192
  declare const startsWith: RegleRuleWithParamsDefinition<string, [part: MaybeInput<string>], false, boolean, MaybeInput<string>>;
385
1193
  /**
386
- * Requires a value to be a native string type
1194
+ * Requires a value to be a native string type.
1195
+ *
1196
+ * Mainly used for typing with `InferInput`.
1197
+ *
1198
+ * @example
1199
+ * ```ts
1200
+ * import { type InferInput } from '@regle/core';
1201
+ * import { string } from '@regle/rules';
1202
+ *
1203
+ * const rules = {
1204
+ * firstName: { string },
1205
+ * }
1206
+ *
1207
+ * const state = ref<InferInput<typeof rules>>({});
1208
+ * ```
387
1209
  *
388
- * Mainly used for typing
1210
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#string Documentation}
389
1211
  */
390
1212
  declare const string: RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<string>, unknown>;
391
1213
  /**
392
1214
  * Define the input type of a rule. No runtime validation.
393
1215
  *
394
1216
  * Override any input type set by other rules.
1217
+ *
1218
+ * @example
1219
+ * ```ts
1220
+ * import { type InferInput } from '@regle/core';
1221
+ * import { type } from '@regle/rules';
1222
+ *
1223
+ * const rules = {
1224
+ * firstName: { type: type<string>() },
1225
+ * status: { type: type<'active' | 'inactive'>() },
1226
+ * }
1227
+ *
1228
+ * const state = ref<InferInput<typeof rules>>({});
1229
+ * ```
1230
+ *
1231
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#type Documentation}
395
1232
  */
396
1233
  declare function type<T>(): RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<T>>;
397
1234
  /**
398
1235
  * Validates URLs.
1236
+ *
1237
+ * @example
1238
+ * ```ts
1239
+ * import { url } from '@regle/rules';
1240
+ *
1241
+ * const { r$ } = useRegle({ bestUrl: '' }, {
1242
+ * bestUrl: { url },
1243
+ * })
1244
+ * ```
1245
+ *
1246
+ * @see {@link https://reglejs.dev/core-concepts/rules/built-in-rules#url Documentation}
399
1247
  */
400
1248
  declare const url: RegleRuleDefinition<string, [], false, boolean, MaybeInput<string>>;
401
1249
  export { EnumLike, alpha, alphaNum, and, applyIf, assignIf, between, boolean, checked, contains, date, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, hexadecimal, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, url, withAsync, withMessage, withParams, withTooltip };