@regle/mcp-server 1.18.0-beta.1 → 1.18.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/regle-mcp-server.js +157 -81
- package/package.json +1 -1
package/dist/regle-mcp-server.js
CHANGED
|
@@ -50,6 +50,13 @@ var docs_data_default = {
|
|
|
50
50
|
"path": "advanced-usage/scoped-validation.md",
|
|
51
51
|
"content": "# Scoped validation\n\nScoped validation in Regle is made to port Vuelidate's `nested component validation`.\n\nProblems with Vuelidate's approach:\n - Performances\n - Not declarative\n - Usage (too magic for the user)\n - Type safety\n - Restricted to DOM\n - Have to play with `$scope` and `$stopPropagation` to avoid unwanted behaviour\n\nRegle's solution solves all this problems\n\n## Collecting validation with `useCollectScope` and `useScopedRegle`\n\n### `useScopedRegle`\n\n`useScopedRegle` is a clone of `useRegle`, but with the difference that every time it's used and updated, its state will be collected by the same scope created using `createScopedUseRegle`.\n\nEvery time it's called, a instance will be added for `useCollectScope` to collect.\n\nIt can be called multiple times at any place, not only on components, as it's not restricted by DOM.\n\n### `useCollectScope`\n\nThis composable allow you to retrieve every Regle instances created using the sibling composable `useScopedRegle`.\n\nChildren properties like `$value` and `$errors` will not be objects, and are converted into arrays instead.\n\nYou will also have access to every validation properties like `$error`, `$invalid` etc...\n\n:::code-group\n\n```vue [Parent.vue]\n<template>\n <div>\n <Child1 />\n </div>\n\n <Child2 />\n\n Collected errors: <pre>{{ r$.$errors }}</pre>\n</template>\n\n```\n\n```vue [Child1.vue]\n<template>\n <input v-model=\"r$.$value.firstName\" placeholder=\"Type your firstname\" />\n <ul>\n <li v-for=\"error of r$.$errors.firstName\" :key=\"error\">\n {{ error }}\n </li>\n </ul>\n</template>\n\n```\n\n```vue [Child2.vue]\n<template>\n <input v-model=\"r$.$value.email\" placeholder=\"Type your email\" />\n <ul>\n <li v-for=\"error of r$.$errors.email\" :key=\"error\">\n {{ error }}\n </li>\n </ul>\n</template>\n\n```\n:::\n\nResult:\n\n## Multiple scopes\n\nIf you want to create your own separated scope, you can use `createScopedUseRegle` helper method.\n\nIt's advised to change the name of this composable to avoid conflicts or issues.\n\n```ts [scoped-config.ts]\nimport { createScopedUseRegle } from '@regle/core';\n\nexport const { useScopedRegle, useCollectScope } = createScopedUseRegle();\nexport const { \n useScopedRegle: useContactsRegle, \n useCollectScope: useCollectContacts \n} = createScopedUseRegle();\n```\n\n## Namespaces inside scopes\n\nEach scope can collect a specific namespace. Giving a namespace name will collect only the children with the same namespace name.\n\nThe namespace can be reactive, so it will update every time it changes.\n\nIn this example, only the components using the same scope and namespace will be collected.\n\n:::code-group\n```vue [Parent.vue]\n\n```\n\n```vue [Child1.vue]\n<template>\n <input v-model=\"r$.$value.firstName\" placeholder=\"Type your firstname\" />\n <ul>\n <li v-for=\"error of r$.$errors.firstName\" :key=\"error\">\n {{ error }}\n </li>\n </ul>\n</template>\n\n```\n\n```vue [Child2.vue]\n<template>\n <input v-model=\"r$.$value.email\" placeholder=\"Type your email\" />\n <ul>\n <li v-for=\"error of r$.$errors.email\" :key=\"error\">\n {{ error }}\n </li>\n </ul>\n</template>\n\n```\n\nYou can also collect multiple namespaces at once by passing an array of namespace names to the `useCollectScope` function.\n\n```ts\nconst { r$ } = useCollectScope(['contacts', 'persons']);\n```\n:::\n\n## Inject global config\n\nIf you have a global config already registered, simply pass it as a parameter to your `createScopedUseRegle` function.\n\n```ts twoslash [scoped-config.ts]\nimport { createScopedUseRegle, defineRegleConfig } from '@regle/core';\nimport { required, withMessage } from '@regle/rules';\n\nconst { useRegle } = defineRegleConfig({\n rules: () => ({\n custom: withMessage(required, 'Custom error'),\n }),\n});\n\nexport const { useScopedRegle, useCollectScope } = createScopedUseRegle({customUseRegle: useRegle});\n\nconst {r$} = useScopedRegle({name: ''}, {\n name: {\n cus\n\n }\n})\n\n```\n\n## Custom store for instances\n\nBy default collected instances are stored in a local ref. \n\nYou can provide your own store ref.\n\n```ts\nimport { createScopedUseRegle, type ScopedInstancesRecordLike } from '@regle/core';\n\n// Having a default \nconst myCustomStore = ref<ScopedInstancesRecordLike>({});\n\nconst { useScopedRegle, useCollectScope } = createScopedUseRegle({customStore: myCustomStore});\n```\n\n## Collect instances in a Record\n\nBy default collected instances are stored in a readonly array.\n\nIf you want to store your nested instances in a record it's possible with the `asRecord` option.\n\nThis will **require** every nested `useScopeRegle` to provide a parameter `id`.\n\n:::code-group\n\n```ts [scoped-config.ts]\nimport { createScopedUseRegle } from '@regle/core';\n\nexport const { \n useScopedRegle: useScopedRegleItem, \n useCollectScope: useCollectScopeRecord \n} = createScopedUseRegle({ asRecord: true });\n```\n```vue [Parent.vue]\n\n```\n\n```vue [Child1.vue]\n<template>\n <input v-model=\"r$.$value.firstName\" placeholder=\"Type your firstname\" />\n <ul>\n <li v-for=\"error of r$.$errors.firstName\" :key=\"error\">\n {{ error }}\n </li>\n </ul>\n</template>\n\n```\n\n```vue [Child2.vue]\n<template>\n <input v-model=\"r$.$value.email\" placeholder=\"Type your email\" />\n <ul>\n <li v-for=\"error of r$.$errors.email\" :key=\"error\">\n {{ error }}\n </li>\n </ul>\n</template>\n\n```\n:::\n\n## Manually dispose or register a scope entry\n\n`useScopedRegle` also returns two methods: `dispose` and `register`.\n\nYou can then programmatically handle if your component is collected from inside.\n\n```vue\n\n```\n\n## Manual typing\n\n:::warning\nUse with care, only if you're 100% sure of what return type your collected types will have.\n\nThe order of the collected values can change depending on if they added/deleted.\nThis is here for convenience but not advised.\n:::\n\n```ts twoslash\nimport { useCollectScope } from '@regle/core';\n\nconst { r$ } = useCollectScope<[{ foo: string }]>();\n\nconst { valid, data } = await r$.$validate();\n\n```\n\n## Testing\n\nIf you write unit test for a component using scoped validation, you may encounter problems with the tests failing.\n\nTo solve this, mount your component with the `attachTo` option set to the document element.\n\n```ts\nimport { mount } from '@vue/test-utils';\nimport ComponentUsingCollectScope from './ComponentUsingCollectScope.vue';\n\nconst wrapper = mount(ComponentUsingCollectScope, {\n attachTo: document.documentElement,\n});\n```"
|
|
52
52
|
},
|
|
53
|
+
{
|
|
54
|
+
"id": "advanced-usage-self-validation",
|
|
55
|
+
"title": "Object self validation",
|
|
56
|
+
"category": "advanced-usage",
|
|
57
|
+
"path": "advanced-usage/self-validation.md",
|
|
58
|
+
"content": "# Object self validation\n\nBy default, Regle validates the nested properties of an object. But sometimes you need to validate the object itself, to perform cross-field validation that depends on multiple properties.\n\nThe `$self` property allows you to apply validation rules directly to an object, giving you full control over object-level validation.\n\n## Basic usage\n\nUse `$self` to define rules that validate the object itself rather than its nested properties.\n\n```ts twoslash\nimport { ref } from 'vue';\nimport { useRegle, type Maybe } from '@regle/core';\nimport { required, isFilled, minLength, withMessage } from '@regle/rules';\n\ntype User = {\n firstName: string;\n lastName: string;\n};\n\nconst state = ref<{ user: User }>({\n user: {\n firstName: '',\n lastName: '',\n },\n});\n\nconst { r$ } = useRegle(state, {\n user: {\n $self: {\n // Custom rule: at least one name must be filled\n atLeastOneName: withMessage(\n (value: Maybe<User>) => isFilled(value?.firstName) || isFilled(value?.lastName),\n 'At least one name is required'\n ),\n },\n firstName: { minLength: minLength(3) },\n lastName: { minLength: minLength(3) },\n },\n});\n```\n\nIn this example the `atLeastOneName` custom rule validates that at least one of `firstName` or `lastName` is filled.\n\n## Accessing `$self` status\n\nThe `$self` status is accessible through `r$.fieldName.$self` and provides all standard field status properties:\n\n```vue\n<template>\n <ul>\n <li v-for=\"error of r$.$errors.user.$self\" :key=\"error\">\n {{ error }}\n </li>\n </ul>\n</template>\n```\nResult:"
|
|
59
|
+
},
|
|
53
60
|
{
|
|
54
61
|
"id": "advanced-usage-variants",
|
|
55
62
|
"title": "Variants",
|
|
@@ -132,7 +139,7 @@ var docs_data_default = {
|
|
|
132
139
|
"title": "Built-in rules",
|
|
133
140
|
"category": "rules",
|
|
134
141
|
"path": "core-concepts/rules/built-in-rules.md",
|
|
135
|
-
"content": "# Built-in rules\n\nAll built-in rules are available through the `@regle/rules` package.\n\nDon't forget to install it if you haven't:\n\n::: code-group\n\n```sh [pnpm]\npnpm add @regle/rules\n```\n\n```sh [npm]\nnpm install @regle/rules\n```\n\n```sh [yarn]\nyarn add @regle/rules\n```\n\n```sh [bun]\nbun add @regle/rules\n```\n\n:::\n\n:::tip\nEvery built-in rule will check if the value of the field is set before checking if it's valid.\n\nThis allow to have rules even if the field is not required.\n:::\n\n## `alpha`\n\n_**Params**_\n - `allowSymbols?: MaybeRefOrGetter<boolean>`\n\nAllows only alphabetic characters.\n\n```ts\nimport { alpha } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: { \n alpha,\n // or\n alpha: alpha({ allowSymbols: true }),\n },\n})\n```\n\n## `alphaNum`\n\n_**Params**_\n - `allowSymbols?: MaybeRefOrGetter<boolean>`\n\nAllows only alphanumeric characters.\n\n```ts\nimport { alphaNum } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: { \n alphaNum,\n // or\n alphaNum: alphaNum({ allowSymbols: true }),\n})\n```\n\n## `between`\n\n_**Params**_\n - `min: Ref<number> | number | () => number`\n - `max: Ref<number> | number | () => number`\n - `options?: {allowEqual?: boolean}`\n\nChecks if a number is in specified bounds. `min` and `max` are both inclusive.\n\n```ts\nimport { between } from '@regle/rules';\n\nconst maxCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n between: between(1, 6),\n between: between(1, maxCount, {allowEqual: false}),\n between: between(() => maxCount.value, 10)\n },\n})\n```\n\n## `boolean`\n\nRequires a value to be a native boolean type. Mainly used for typing.\n\n```ts\nimport {type InferInput} from '@regle/core';\nimport { boolean } from '@regle/rules';\n\nconst rules = {\n checkbox: { boolean },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `checked`\n\nRequires a boolean value to be `true`. This is useful for checkbox inputs.\n\n```ts\nimport { checked } from '@regle/rules';\n\nconst { r$ } = useRegle({ confirm: false }, {\n confirm: { checked },\n})\n```\n\n## `contains`\n\n_**Params**_\n- `contain: Ref<string> | string | () => string`\n\nChecks if the string contains the specified substring.\n\n```ts\nimport { contains } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestLib: '' }, {\n bestLib: {\n contains: contains('regle')\n },\n})\n```\n\n## `date`\n\nRequires a value to be a native Date constructor. Mainly used for typing.\n\n```ts\nimport {type InferInput} from '@regle/core';\nimport { date } from '@regle/rules';\n\nconst rules = {\n birthday: { date },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `dateAfter`\n_**Params**_\n - `after: Ref<string | Date> | string | Date | () => string | Date`\n - `options?: {allowEqual?: boolean}`\n\nChecks if the date is after the given parameter.\n\n```ts\nimport { dateAfter } from '@regle/rules';\n\nconst today = ref(new Date());\n\nconst { r$ } = useRegle({ birthday: null as Date | null }, {\n birthday: {\n dateAfter: dateAfter(today),\n // or\n dateAfter: dateAfter(today, { allowEqual: false }),\n },\n})\n```\n\n## `dateBefore`\n_**Params**_\n - `before: Ref<string | Date> | string | Date | () => string | Date`\n - `options?: {allowEqual?: boolean}`\n\nChecks if the date is before the given parameter.\n\n```ts\nimport { dateBefore } from '@regle/rules';\n\nconst today = ref(new Date());\n\nconst { r$ } = useRegle({ birthday: null as Date | null }, {\n birthday: {\n dateBefore: dateBefore(today),\n // or\n dateBefore: dateBefore(today, { allowEqual: false }),\n },\n})\n```\n\n## `dateBetweeen`\n\n_**Params**_\n - `before: Ref<string | Date> | string | Date | () => string | Date`\n - `after: Ref<string | Date> | string | Date | () => string | Date`\n - `options?: {allowEqual?: boolean}`\n\nChecks if the date falls between the specified bounds.\n\n```ts\nimport { dateBetween } from '@regle/rules';\n\nconst before = ref(new Date());\nconst after = ref(new Date(2030, 3, 1));\n\nconst { r$ } = useRegle({ birthday: null as Date | null }, {\n birthday: {\n dateBetween: dateBetween(before, after),\n // or\n dateBetween: dateBetween(before, after, { allowEqual: false }),\n },\n})\n```\n\n## `decimal`\n\nAllows positive and negative decimal numbers.\n\n```ts\nimport { decimal } from '@regle/rules';\n\nconst { r$ } = useRegle({ price: 0 }, {\n price: { decimal },\n})\n```\n\n## `email`\n\nValidates email addresses. Always verify on the server to ensure the address is real and not already in use.\n\n```ts\nimport { email } from '@regle/rules';\n\nconst { r$ } = useRegle({ email: '' }, {\n email: { email },\n})\n```\n\n## `emoji`\n\nValidates emojis.\n\n```ts\nimport { emoji } from '@regle/rules';\n\nconst { r$ } = useRegle({ emoji: '' }, {\n emoji: { emoji },\n})\n```\n\n## `endsWith`\n\n_**Params**_\n- `end: Ref<string> | string | () => string`\n\nChecks if the string ends with the specified substring.\n\n```ts\nimport { endsWith } from '@regle/rules';\n\nconst { r$ } = useRegle({ firstName: '' }, {\n firstName: { endsWith: endsWith('foo') },\n})\n```\n\n## `exactDigits`\n_**Params**_\n - `count: Ref<number> | number | () => number`\n\nRequires the input value to have a strict specified number of digits.\n\n```ts\nimport { exactDigits } from '@regle/rules';\n\nconst exactValue = ref(6);\n\nconst { r$ } = useRegle({ digits: '' }, {\n digits: {\n exactDigits: exactDigits(6),\n // or with ref\n exactDigits: exactDigits(exactValue),\n // or with getter\n exactDigits: exactDigits(() => exactValue.value)\n },\n})\n```\n\n## `exactLength`\n\n_**Params**_\n - `count: Ref<number> | number | () => number`\n\nRequires the input value to have a strict specified length, inclusive. Works with arrays, objects and strings.\n\n```ts\nimport { exactLength } from '@regle/rules';\n\nconst exactValue = ref(6);\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n exactLength: exactLength(6),\n exactLength: exactLength(exactValue),\n exactLength: exactLength(() => exactValue.value)\n },\n})\n```\n\n## `exactValue`\n\n_**Params**_\n - `count: Ref<number> | number | () => number`\n\nRequires a field to have a strict numeric value.\n\n```ts\nimport { exactValue } from '@regle/rules';\n\nconst exactCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n exactValue: exactValue(6),\n exactValue: exactValue(exactCount),\n exactValue: exactValue(() => exactCount.value)\n },\n})\n```\n\n## `file`\n\nRequires a value to be a native File constructor. Mainly used for typing.\n\n```ts\nimport { file } from '@regle/rules';\n\nconst rules = {\n file: { file },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `fileType`\n\nRequires a value to be a file with a specific type.\n\n```ts\nimport { fileType } from '@regle/rules';\n\nconst { r$ } = useRegle({ file: null as File | null }, {\n file: { fileType: fileType(['image/png', 'image/jpeg']) },\n})\n```\n\n## `hexadecimal`\n\nValidates hexadecimal values.\n\n```ts\nimport { hexadecimal } from '@regle/rules';\n\nconst { r$ } = useRegle({ hexadecimal: '' }, {\n hexadecimal: { hexadecimal },\n})\n```\n\n## `hostname`\n\nValidates hostnames.\n\n```ts\nimport { hostname } from '@regle/rules';\n\nconst { r$ } = useRegle({ siteHost: '' }, {\n siteHost: { hostname },\n})\n```\n\n## `httpUrl`\n\n_**Params**_\n- `options?: {protocol?: RegExp}`\n\nValidates HTTP URLs.\n\n```ts\nimport { httpUrl } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestUrl: '' }, {\n bestUrl: { httpUrl },\n // or with custom protocol validation\n bestUrl: { httpUrl: httpUrl({ protocol: /^https$/ }) },\n})\n```\n\n## `integer`\n\nAllows only integers (positive and negative).\n\n```ts\nimport { integer } from '@regle/rules';\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: { integer },\n})\n```\n\n## `ipv4Address`\n\nValidates IPv4 addresses in dotted decimal notation *127.0.0.1*.\n\n```ts\nimport { ipv4Address } from '@regle/rules';\n\nconst { r$ } = useRegle({ address: '' }, {\n address: { ipv4Address },\n})\n```\n\n## `literal`\n\nValidates literal values.\n\n```ts\nimport { literal } from '@regle/rules';\n\nconst { r$ } = useRegle({ value: '' }, {\n value: { literal: literal('foo') },\n})\n```\n\n## `lowercase`\n\nValidates lowercase strings.\n\n```ts\nimport { lowercase } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: { lowercase },\n})\n```\n\n## `macAddress`\n\n_**Params**_\n - `separator?: string | Ref<string> | () => string`\n\nValidates MAC addresses. Call as a function to specify a custom separator (e.g., ':' or an empty string for 00ff1122334455).\n\n```ts\n\nimport { macAddress } from '@regle/rules';\n\nconst maxCount = ref(6);\n\nconst { r$ } = useRegle({ address: '' }, {\n address: {\n macAddress,\n // or\n macAddress: macAddress('-')\n },\n})\n```\n\n## `maxFileSize`\n\nRequires a value to be a file with a maximum size.\n\n```ts\nimport { maxFileSize } from '@regle/rules';\n\nconst { r$ } = useRegle({ file: null as File | null }, {\n file: { maxFileSize: maxFileSize(10_000_000) }, // 10 MB\n})\n```\n\n## `maxLength`\n\n_**Params**_\n - `max: Ref<number> | number | () => number`\n - `options?: {allowEqual?: boolean}`\n\n_**Works with**_\n - `Array | Record | string | number`\n\nRequires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.\n\n```ts\nimport { maxLength } from '@regle/rules';\n\nconst maxValue = ref(6);\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n maxLength: maxLength(6),\n maxLength: maxLength(maxValue),\n maxLength: maxLength(() => maxValue.value)\n },\n})\n```\n\n## `maxValue`\n\n_**Params**_\n - `min: Ref<number> | number | () => number`\n - `options?: {allowEqual?: boolean}`\n\n Requires a field to have a specified maximum numeric value.\n\n```ts\nimport { maxValue } from '@regle/rules';\n\nconst maxCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n maxValue: maxValue(6),\n maxValue: maxValue(maxCount, {allowEqual: false}),\n maxValue: maxValue(() => maxCount.value)\n },\n})\n```\n\n## `minFileSize`\n\nRequires a value to be a file with a minimum size.\n\n```ts\nimport { minFileSize } from '@regle/rules';\n\nconst { r$ } = useRegle({ file: null as File | null }, {\n file: { minFileSize: minFileSize(1_000_000) }, // 1 MB\n})\n```\n\n## `minLength`\n\n_**Params**_\n - `min: Ref<number> | number | () => number`\n - `options?: {allowEqual?: boolean}`\n\n_**Works with**_\n - `Array | Record | string | number`\n\nRequires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.\n\n```ts\nimport { minLength } from '@regle/rules';\n\nconst minValue = ref(6);\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n minLength: minLength(6),\n minLength: minLength(minValue),\n minLength: minLength(() => minValue.value)\n },\n})\n```\n\n## `minValue`\n\n_**Params**_\n - `min: Ref<number> | number | () => number`\n - `options?: {allowEqual?: boolean}`\n\n_**Works with**_\n - `number`\n\nRequires a field to have a specified minimum numeric value.\n\n```ts\nimport { minValue } from '@regle/rules';\n\nconst minCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n minValue: minValue(6),\n minValue: minValue(minCount, {allowEqual: false}),\n minValue: minValue(() => minCount.value)\n },\n})\n```\n\n## `nativeEnum`\n\nValidate against a native Typescript enum value. Similar to Zod's `nativeEnum`\n\n```ts\nimport { nativeEnum } from '@regle/rules';\n\nenum Foo {\n Bar, Baz\n}\n\nconst { r$ } = useRegle({ type: '' }, {\n type: { nativeEnum: nativeEnum(Foo) },\n})\n```\n\n## `number`\n\nRequires a value to be a native number type. Mainly used for typing.\n\n```ts\nimport { number } from '@regle/rules';\n\nconst rules = {\n count: { number },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `numeric`\n\nAllows only numeric values (including numeric strings).\n\n```ts\nimport { numeric } from '@regle/rules';\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: { numeric },\n})\n```\n\n## `oneOf`\n\nAllow only one of the values from a fixed Array of possible entries.\n\n_**Params**_\n - `options: MaybeRefOrGetter<Array<string | number>>`\n\n```ts\nimport { oneOf } from '@regle/rules';\n\nconst { r$ } = useRegle({ aliment: 'Fish' }, {\n aliment: {\n oneOf: oneOf(['Fish', 'Meat', 'Bone'])\n },\n})\n```\n\n## `regex`\n\n_**Params**_\n- `regexps: MaybeRefOrGetter<RegExp | RegExp[]>`\n\nChecks if the value matches one or more regular expressions.\n\n```ts\nimport { regex } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n regex: regex(/^foo/),\n regex: regex([/^bar/, /baz$/]),\n },\n})\n```\n\n## `required`\n\nRequires non-empty data. Checks for empty arrays and strings containing only whitespaces.\n\n```ts\nimport {required} from '@regle/rules';\n\nconst {r$} = useRegle({name: ''}, {\n name: {required},\n})\n```\n\n## `requiredIf`\n\n_**Params**_\n - `condition: Ref<unknown> | unknown | () => unknown` - the property to base the `required` validator on.\n\nRequires non-empty data, only if provided data property, ref, or a function resolves to `true`.\n\n```ts\nimport { requiredIf } from '@regle/rules';\n\nconst form = ref({ name: '', condition: false });\n\nconst conditionRef = ref(false);\n\nconst { r$ } = useRegle(form, {\n name: {\n required: requiredIf(() => form.value.condition),\n required: requiredIf(conditionRef),\n },\n})\n```\n\n## `requiredUnless`\n\n_**Params**_\n - `condition: Ref<unknown> | unknown | () => unknown` - the property to base the `required` validator on.\n\nRequires non-empty data, only if provided data property, ref, or a function resolves to `false`.\n\n```ts\nimport { requiredUnless } from '@regle/rules';\n\nconst form = ref({ name: '', condition: false });\n\nconst conditionRef = ref(false);\n\nconst { r$ } = useRegle(form, {\n name: {\n required: requiredUnless(() => form.value.condition),\n required: requiredUnless(conditionRef)\n },\n})\n```\n\n## `sameAs`\n\n_**Params**_\n * `target: unknown`\n\nChecks if the value matches the specified property or ref.\n\n```ts\nimport { sameAs } from '@regle/rules';\n\nconst form = ref({\n password: '',\n confirmPassword: '',\n});\n\nconst { r$ } = useRegle(form, {\n confirmPassword: {\n sameAs: sameAs(() => form.value.password),\n }\n})\n```\n\n## `startsWith`\n\n_**Params**_\n- `start: Ref<string> | string | () => string`\n\nChecks if the string starts with the specified substring.\n\n```ts\nimport { startsWith } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestLib: '' }, {\n bestLib: {\n startsWith: startsWith('regle')\n },\n})\n```\n\n## `string`\n\nRequires a value to be a native string type. Mainly used for typing\n\n```ts\nimport {type InferInput} from '@regle/core';\nimport { string } from '@regle/rules';\n\nconst rules = {\n firstName: { string },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `type`\n\nDefine the input type of a rule. No runtime validation. \nOverride any input type set by other rules.\n\n```ts\nimport {type InferInput} from '@regle/core';\nimport { type } from '@regle/rules';\n\nconst rules = {\n firstName: { type: type<string>() },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `uppercase`\n\nValidates uppercase strings.\n\n```ts\nimport { uppercase } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: { uppercase },\n})\n```\n\n## `url`\n\n_**Params**_\n- `options?: {protocol?: RegExp}`\n\nValidates URLs.\n\n```ts\nimport { url } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestUrl: '' }, {\n bestUrl: { url },\n // or with custom protocol validation\n bestUrl: { url: url({ protocol: /^https?$/ }) },\n})\n```"
|
|
142
|
+
"content": "# Built-in rules\n\nAll built-in rules are available through the `@regle/rules` package.\n\nDon't forget to install it if you haven't:\n\n::: code-group\n\n```sh [pnpm]\npnpm add @regle/rules\n```\n\n```sh [npm]\nnpm install @regle/rules\n```\n\n```sh [yarn]\nyarn add @regle/rules\n```\n\n```sh [bun]\nbun add @regle/rules\n```\n\n:::\n\n:::tip\nEvery built-in rule will check if the value of the field is set before checking if it's valid.\n\nThis allow to have rules even if the field is not required.\n:::\n\n## `alpha`\n\n_**Params**_\n - `allowSymbols?: MaybeRefOrGetter<boolean>`\n\nAllows only alphabetic characters.\n\n```ts\nimport { alpha } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: { \n alpha,\n // or\n alpha: alpha({ allowSymbols: true }),\n },\n})\n```\n\n## `alphaNum`\n\n_**Params**_\n - `allowSymbols?: MaybeRefOrGetter<boolean>`\n\nAllows only alphanumeric characters.\n\n```ts\nimport { alphaNum } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: { \n alphaNum,\n // or\n alphaNum: alphaNum({ allowSymbols: true }),\n})\n```\n\n## `atLeastOne`\n\n_**Params**_\n - `keys?: MaybeRefOrGetter<string[]>` - Optional list of keys to check. If not provided, checks if the object has at least one filled property.\n\n_**Works with**_\n - `Record | object`\n\nChecks if at least one key is filled in the object. Useful for object-level validation with `$self`.\n\n```ts\nimport { atLeastOne } from '@regle/rules';\n\nconst { r$ } = useRegle({ user: { firstName: '', lastName: '' } }, {\n user: {\n $self: {\n // Check if any property is filled\n atLeastOne,\n // or check specific keys\n atLeastOne: atLeastOne(['firstName', 'lastName']),\n },\n },\n})\n```\n\n## `between`\n\n_**Params**_\n - `min: Ref<number> | number | () => number`\n - `max: Ref<number> | number | () => number`\n - `options?: {allowEqual?: boolean}`\n\nChecks if a number is in specified bounds. `min` and `max` are both inclusive.\n\n```ts\nimport { between } from '@regle/rules';\n\nconst maxCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n between: between(1, 6),\n between: between(1, maxCount, {allowEqual: false}),\n between: between(() => maxCount.value, 10)\n },\n})\n```\n\n## `boolean`\n\nRequires a value to be a native boolean type. Mainly used for typing.\n\n```ts\nimport {type InferInput} from '@regle/core';\nimport { boolean } from '@regle/rules';\n\nconst rules = {\n checkbox: { boolean },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `checked`\n\nRequires a boolean value to be `true`. This is useful for checkbox inputs.\n\n### Note\n\nThis rule does not need `required` to be set, it will assert the value is set.\n\n```ts\nimport { checked } from '@regle/rules';\n\nconst { r$ } = useRegle({ confirm: false }, {\n confirm: { checked },\n})\n```\n\n## `contains`\n\n_**Params**_\n- `contain: Ref<string> | string | () => string`\n\nChecks if the string contains the specified substring.\n\n```ts\nimport { contains } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestLib: '' }, {\n bestLib: {\n contains: contains('regle')\n },\n})\n```\n\n## `date`\n\nRequires a value to be a native Date constructor. Mainly used for typing.\n\n```ts\nimport {type InferInput} from '@regle/core';\nimport { date } from '@regle/rules';\n\nconst rules = {\n birthday: { date },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `dateAfter`\n_**Params**_\n - `after: Ref<string | Date> | string | Date | () => string | Date`\n - `options?: {allowEqual?: boolean}`\n\nChecks if the date is after the given parameter.\n\n```ts\nimport { dateAfter } from '@regle/rules';\n\nconst today = ref(new Date());\n\nconst { r$ } = useRegle({ birthday: null as Date | null }, {\n birthday: {\n dateAfter: dateAfter(today),\n // or\n dateAfter: dateAfter(today, { allowEqual: false }),\n },\n})\n```\n\n## `dateBefore`\n_**Params**_\n - `before: Ref<string | Date> | string | Date | () => string | Date`\n - `options?: {allowEqual?: boolean}`\n\nChecks if the date is before the given parameter.\n\n```ts\nimport { dateBefore } from '@regle/rules';\n\nconst today = ref(new Date());\n\nconst { r$ } = useRegle({ birthday: null as Date | null }, {\n birthday: {\n dateBefore: dateBefore(today),\n // or\n dateBefore: dateBefore(today, { allowEqual: false }),\n },\n})\n```\n\n## `dateBetweeen`\n\n_**Params**_\n - `before: Ref<string | Date> | string | Date | () => string | Date`\n - `after: Ref<string | Date> | string | Date | () => string | Date`\n - `options?: {allowEqual?: boolean}`\n\nChecks if the date falls between the specified bounds.\n\n```ts\nimport { dateBetween } from '@regle/rules';\n\nconst before = ref(new Date());\nconst after = ref(new Date(2030, 3, 1));\n\nconst { r$ } = useRegle({ birthday: null as Date | null }, {\n birthday: {\n dateBetween: dateBetween(before, after),\n // or\n dateBetween: dateBetween(before, after, { allowEqual: false }),\n },\n})\n```\n\n## `decimal`\n\nAllows positive and negative decimal numbers.\n\n```ts\nimport { decimal } from '@regle/rules';\n\nconst { r$ } = useRegle({ price: 0 }, {\n price: { decimal },\n})\n```\n\n## `email`\n\nValidates email addresses. Always verify on the server to ensure the address is real and not already in use.\n\n```ts\nimport { email } from '@regle/rules';\n\nconst { r$ } = useRegle({ email: '' }, {\n email: { email },\n})\n```\n\n## `emoji`\n\nValidates emojis.\n\n```ts\nimport { emoji } from '@regle/rules';\n\nconst { r$ } = useRegle({ emoji: '' }, {\n emoji: { emoji },\n})\n```\n\n## `endsWith`\n\n_**Params**_\n- `end: Ref<string> | string | () => string`\n\nChecks if the string ends with the specified substring.\n\n```ts\nimport { endsWith } from '@regle/rules';\n\nconst { r$ } = useRegle({ firstName: '' }, {\n firstName: { endsWith: endsWith('foo') },\n})\n```\n\n## `exactDigits`\n_**Params**_\n - `count: Ref<number> | number | () => number`\n\nRequires the input value to have a strict specified number of digits.\n\n```ts\nimport { exactDigits } from '@regle/rules';\n\nconst exactValue = ref(6);\n\nconst { r$ } = useRegle({ digits: '' }, {\n digits: {\n exactDigits: exactDigits(6),\n // or with ref\n exactDigits: exactDigits(exactValue),\n // or with getter\n exactDigits: exactDigits(() => exactValue.value)\n },\n})\n```\n\n## `exactLength`\n\n_**Params**_\n - `count: Ref<number> | number | () => number`\n\nRequires the input value to have a strict specified length, inclusive. Works with arrays, objects and strings.\n\n```ts\nimport { exactLength } from '@regle/rules';\n\nconst exactValue = ref(6);\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n exactLength: exactLength(6),\n exactLength: exactLength(exactValue),\n exactLength: exactLength(() => exactValue.value)\n },\n})\n```\n\n## `exactValue`\n\n_**Params**_\n - `count: Ref<number> | number | () => number`\n\nRequires a field to have a strict numeric value.\n\n```ts\nimport { exactValue } from '@regle/rules';\n\nconst exactCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n exactValue: exactValue(6),\n exactValue: exactValue(exactCount),\n exactValue: exactValue(() => exactCount.value)\n },\n})\n```\n\n## `file`\n\nRequires a value to be a native File constructor. Mainly used for typing.\n\n```ts\nimport { file } from '@regle/rules';\n\nconst rules = {\n file: { file },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `fileType`\n\nRequires a value to be a file with a specific type.\n\n```ts\nimport { fileType } from '@regle/rules';\n\nconst { r$ } = useRegle({ file: null as File | null }, {\n file: { fileType: fileType(['image/png', 'image/jpeg']) },\n})\n```\n\n## `hexadecimal`\n\nValidates hexadecimal values.\n\n```ts\nimport { hexadecimal } from '@regle/rules';\n\nconst { r$ } = useRegle({ hexadecimal: '' }, {\n hexadecimal: { hexadecimal },\n})\n```\n\n## `hostname`\n\nValidates hostnames.\n\n```ts\nimport { hostname } from '@regle/rules';\n\nconst { r$ } = useRegle({ siteHost: '' }, {\n siteHost: { hostname },\n})\n```\n\n## `httpUrl`\n\n_**Params**_\n- `options?: {protocol?: RegExp}`\n\nValidates HTTP URLs.\n\n```ts\nimport { httpUrl } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestUrl: '' }, {\n bestUrl: { httpUrl },\n // or with custom protocol validation\n bestUrl: { httpUrl: httpUrl({ protocol: /^https$/ }) },\n})\n```\n\n## `integer`\n\nAllows only integers (positive and negative).\n\n```ts\nimport { integer } from '@regle/rules';\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: { integer },\n})\n```\n\n## `ipv4Address`\n\nValidates IPv4 addresses in dotted decimal notation *127.0.0.1*.\n\n```ts\nimport { ipv4Address } from '@regle/rules';\n\nconst { r$ } = useRegle({ address: '' }, {\n address: { ipv4Address },\n})\n```\n\n## `literal`\n\nValidates literal values.\n\n### Note\n\nThis rule does not need `required` to be set, it will assert the value is set.\n\n```ts\nimport { literal } from '@regle/rules';\n\nconst { r$ } = useRegle({ value: '' }, {\n value: { literal: literal('foo') },\n})\n```\n\n## `lowercase`\n\nValidates lowercase strings.\n\n```ts\nimport { lowercase } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: { lowercase },\n})\n```\n\n## `macAddress`\n\n_**Params**_\n - `separator?: string | Ref<string> | () => string`\n\nValidates MAC addresses. Call as a function to specify a custom separator (e.g., ':' or an empty string for 00ff1122334455).\n\n```ts\n\nimport { macAddress } from '@regle/rules';\n\nconst maxCount = ref(6);\n\nconst { r$ } = useRegle({ address: '' }, {\n address: {\n macAddress,\n // or\n macAddress: macAddress('-')\n },\n})\n```\n\n## `maxFileSize`\n\nRequires a value to be a file with a maximum size.\n\n```ts\nimport { maxFileSize } from '@regle/rules';\n\nconst { r$ } = useRegle({ file: null as File | null }, {\n file: { maxFileSize: maxFileSize(10_000_000) }, // 10 MB\n})\n```\n\n## `maxLength`\n\n_**Params**_\n - `max: Ref<number> | number | () => number`\n - `options?: {allowEqual?: boolean}`\n\n_**Works with**_\n - `Array | Record | string | number`\n\nRequires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings.\n\n```ts\nimport { maxLength } from '@regle/rules';\n\nconst maxValue = ref(6);\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n maxLength: maxLength(6),\n maxLength: maxLength(maxValue),\n maxLength: maxLength(() => maxValue.value)\n },\n})\n```\n\n## `maxValue`\n\n_**Params**_\n - `min: Ref<number> | number | () => number`\n - `options?: {allowEqual?: boolean}`\n\n Requires a field to have a specified maximum numeric value.\n\n```ts\nimport { maxValue } from '@regle/rules';\n\nconst maxCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n maxValue: maxValue(6),\n maxValue: maxValue(maxCount, {allowEqual: false}),\n maxValue: maxValue(() => maxCount.value)\n },\n})\n```\n\n## `minFileSize`\n\nRequires a value to be a file with a minimum size.\n\n```ts\nimport { minFileSize } from '@regle/rules';\n\nconst { r$ } = useRegle({ file: null as File | null }, {\n file: { minFileSize: minFileSize(1_000_000) }, // 1 MB\n})\n```\n\n## `minLength`\n\n_**Params**_\n - `min: Ref<number> | number | () => number`\n - `options?: {allowEqual?: boolean}`\n\n_**Works with**_\n - `Array | Record | string | number`\n\nRequires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings.\n\n```ts\nimport { minLength } from '@regle/rules';\n\nconst minValue = ref(6);\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n minLength: minLength(6),\n minLength: minLength(minValue),\n minLength: minLength(() => minValue.value)\n },\n})\n```\n\n## `minValue`\n\n_**Params**_\n - `min: Ref<number> | number | () => number`\n - `options?: {allowEqual?: boolean}`\n\n_**Works with**_\n - `number`\n\nRequires a field to have a specified minimum numeric value.\n\n```ts\nimport { minValue } from '@regle/rules';\n\nconst minCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n minValue: minValue(6),\n minValue: minValue(minCount, {allowEqual: false}),\n minValue: minValue(() => minCount.value)\n },\n})\n```\n\n## `nativeEnum`\n\nValidate against a native Typescript enum value. Similar to Zod's `nativeEnum`\n\n```ts\nimport { nativeEnum } from '@regle/rules';\n\nenum Foo {\n Bar, Baz\n}\n\nconst { r$ } = useRegle({ type: '' }, {\n type: { nativeEnum: nativeEnum(Foo) },\n})\n```\n\n## `number`\n\nRequires a value to be a native number type. Mainly used for typing.\n\n```ts\nimport { number } from '@regle/rules';\n\nconst rules = {\n count: { number },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `numeric`\n\nAllows only numeric values (including numeric strings).\n\n```ts\nimport { numeric } from '@regle/rules';\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: { numeric },\n})\n```\n\n## `oneOf`\n\nAllow only one of the values from a fixed Array of possible entries.\n\n_**Params**_\n - `options: MaybeRefOrGetter<Array<string | number>>`\n\n```ts\nimport { oneOf } from '@regle/rules';\n\nconst { r$ } = useRegle({ aliment: 'Fish' }, {\n aliment: {\n oneOf: oneOf(['Fish', 'Meat', 'Bone'])\n },\n})\n```\n\n## `regex`\n\n_**Params**_\n- `regexps: MaybeRefOrGetter<RegExp | RegExp[]>`\n\nChecks if the value matches one or more regular expressions.\n\n```ts\nimport { regex } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n regex: regex(/^foo/),\n regex: regex([/^bar/, /baz$/]),\n },\n})\n```\n\n## `required`\n\nRequires non-empty data. Checks for empty arrays and strings containing only whitespaces.\n\n```ts\nimport {required} from '@regle/rules';\n\nconst {r$} = useRegle({name: ''}, {\n name: {required},\n})\n```\n\n## `requiredIf`\n\n_**Params**_\n - `condition: Ref<unknown> | unknown | () => unknown` - the property to base the `required` validator on.\n\nRequires non-empty data, only if provided data property, ref, or a function resolves to `true`.\n\n```ts\nimport { requiredIf } from '@regle/rules';\n\nconst form = ref({ name: '', condition: false });\n\nconst conditionRef = ref(false);\n\nconst { r$ } = useRegle(form, {\n name: {\n required: requiredIf(() => form.value.condition),\n required: requiredIf(conditionRef),\n },\n})\n```\n\n## `requiredUnless`\n\n_**Params**_\n - `condition: Ref<unknown> | unknown | () => unknown` - the property to base the `required` validator on.\n\nRequires non-empty data, only if provided data property, ref, or a function resolves to `false`.\n\n```ts\nimport { requiredUnless } from '@regle/rules';\n\nconst form = ref({ name: '', condition: false });\n\nconst conditionRef = ref(false);\n\nconst { r$ } = useRegle(form, {\n name: {\n required: requiredUnless(() => form.value.condition),\n required: requiredUnless(conditionRef)\n },\n})\n```\n\n## `sameAs`\n\n_**Params**_\n * `target: unknown`\n\nChecks if the value matches the specified property or ref.\n\n```ts\nimport { sameAs } from '@regle/rules';\n\nconst form = ref({\n password: '',\n confirmPassword: '',\n});\n\nconst { r$ } = useRegle(form, {\n confirmPassword: {\n sameAs: sameAs(() => form.value.password),\n }\n})\n```\n\n## `startsWith`\n\n_**Params**_\n- `start: Ref<string> | string | () => string`\n\nChecks if the string starts with the specified substring.\n\n```ts\nimport { startsWith } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestLib: '' }, {\n bestLib: {\n startsWith: startsWith('regle')\n },\n})\n```\n\n## `string`\n\nRequires a value to be a native string type. Mainly used for typing\n\n```ts\nimport {type InferInput} from '@regle/core';\nimport { string } from '@regle/rules';\n\nconst rules = {\n firstName: { string },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `type`\n\nDefine the input type of a rule. No runtime validation. \nOverride any input type set by other rules.\n\n```ts\nimport {type InferInput} from '@regle/core';\nimport { type } from '@regle/rules';\n\nconst rules = {\n firstName: { type: type<string>() },\n}\n\nconst state = ref<InferInput<typeof rules>>({});\n```\n\n## `uppercase`\n\nValidates uppercase strings.\n\n```ts\nimport { uppercase } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: { uppercase },\n})\n```\n\n## `url`\n\n_**Params**_\n- `options?: {protocol?: RegExp}`\n\nValidates URLs.\n\n```ts\nimport { url } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestUrl: '' }, {\n bestUrl: { url },\n // or with custom protocol validation\n bestUrl: { url: url({ protocol: /^https?$/ }) },\n})\n```"
|
|
136
143
|
},
|
|
137
144
|
{
|
|
138
145
|
"id": "core-concepts-rules-index",
|
|
@@ -160,7 +167,7 @@ var docs_data_default = {
|
|
|
160
167
|
"title": "Rules operators",
|
|
161
168
|
"category": "rules",
|
|
162
169
|
"path": "core-concepts/rules/rules-operators.md",
|
|
163
|
-
"content": "# Rules operators\n\nRegle provides tools to combine and operate on different rules. It includes
|
|
170
|
+
"content": "# Rules operators\n\nRegle provides tools to combine and operate on different rules. It includes the following built-in operators, available in `@regle/rules`:\n\n- `and`\n- `or`\n- `xor`\n- `not`\n- `applyIf`\n- `assignIf`\n- `pipe`\n\nThese operators work with any rules you provide, but combining rules with incompatible input types may lead to errors.\n\n:::tip\nAll operators are compatible with wrappers\n:::\n\n## `and`\n\nThe `and` operator combines multiple rules and validates successfully only if all provided rules are valid.\n\n```ts\nimport { useRegle } from '@regle/core';\nimport { and, startsWith, endsWith, withMessage } from '@regle/rules';\n\nconst { r$ } = useRegle(\n { regex: '' },\n {\n regex: {\n myError: withMessage(\n and(startsWith('^'), endsWith('$')),\n ({ $params: [start, end] }) =>\n `Regex should start with \"${start}\" and end with \"${end}\"`\n ),\n },\n }\n);\n```\n\nResult: \n\n## `or`\n\nThe `or` operator validates successfully if at least one of the provided rules is valid.\n\n```ts twoslash\nimport { useRegle } from '@regle/core';\nimport { or, startsWith, endsWith, withMessage } from '@regle/rules';\n\nconst { r$ } = useRegle(\n { regex: '' },\n {\n regex: {\n myError: withMessage(\n or(startsWith('^'), endsWith('$')),\n ({ $params: [start, end] }) =>\n `Field should start with \"${start}\" or end with \"${end}\"`\n ),\n },\n }\n);\n```\n\nResult: \n\n## `xor`\n\nThe `xor` operator (exclusive or) validates successfully if **exactly one** of the provided rules is valid. It fails when none or more than one rule passes.\n\n```ts\nimport { useRegle } from '@regle/core';\nimport { xor, contains, withMessage } from '@regle/rules';\n\nconst { r$ } = useRegle(\n { code: '' },\n {\n code: {\n myError: withMessage(\n xor(contains('A'), contains('B')),\n ({ $params: [charA, charB] }) =>\n `Field should contain either \"${charA}\" or \"${charB}\", but not both`\n ),\n },\n }\n);\n```\n\nResult: \n\n## `not`\n\nThe `not` operator passes when the provided rule fails and fails when the rule passes. It can be combined with other rules.\n\n```ts\nimport { useRegle } from '@regle/core';\nimport { not, required, sameAs, withMessage } from '@regle/rules';\nimport { ref } from 'vue';\n\nconst form = ref({ oldPassword: '', newPassword: '' });\nconst { r$ } = useRegle(form, {\n oldPassword: {\n required,\n },\n newPassword: {\n notEqual: withMessage(\n not(sameAs(() => form.value.oldPassword)),\n 'Your confirm new password must not be the same as your old password'\n ),\n },\n});\n```\n\nResult: \n\n## `applyIf`\n\nThe `applyIf` operator is similar to `requiredIf`, but it can be used with any rule. It simplifies conditional rule declarations.\n\n```ts\nimport { minLength, applyIf } from '@regle/rules';\n\nconst condition = ref(false);\n\nconst { r$ } = useRegle({name: ''}, {\n name: {\n minLength: applyIf(condition, minLength(6))\n },\n});\n```\n\n## `assignIf`\n\nThe `assignIf` is a shorthand for conditional destructuring assignment.\nIt allows to apply multiple rules to a field conditionally.\n\n```ts\nimport { required, email, minLength, assignIf } from '@regle/rules';\n\nconst condition = ref(false);\n\nconst { r$ } = useRegle(ref({ name: '', email: '' }), {\n name: assignIf(condition, { required, minLength: minLength(4) }),\n email: { email },\n});\n```\n\n## `pipe`\n\nThe `pipe` operator chains multiple rules together sequentially. Each rule only runs if all previous rules have passed. This is useful when you want to validate in a specific order and avoid running expensive validations (like async checks) until simpler ones pass.\n\n```ts\nimport { useRegle } from '@regle/core';\nimport { pipe, required, minLength, email } from '@regle/rules';\n\nconst { r$ } = useRegle(\n { email: '' },\n {\n email: pipe(required, minLength(5), email),\n }\n);\n// minLength only runs if required passes\n// email only runs if both required and minLength pass\n```\n\nResult: \n\n:::tip When to use `pipe` vs `and`\n- Use **`and`** when all rules should run simultaneously and you want all errors at once\n- Use **`pipe`** when rules should run sequentially and later rules depend on earlier ones passing (e.g., don't check email format until the field has enough characters)\n:::\n\nThe `pipe` operator also works with async rules. Subsequent rules will wait for async validators to complete before running:\n\n```ts\nimport { pipe, required, withAsync } from '@regle/rules';\n\nconst checkEmailAvailable = withAsync(async (value) => {\n const response = await fetch(`/api/check-email?email=${value}`);\n return response.ok;\n});\n\nconst { r$ } = useRegle(\n { email: '' },\n {\n email: pipe(required, email, checkEmailAvailable),\n }\n);\n// checkEmailAvailable only runs after required and email pass\n```\n\n### Debouncing async validators\n\nWhen using `pipe` with async validators, you can configure a debounce delay to prevent too many API calls while the user is typing. Use the array syntax with an options object as the second argument:\n\n```ts\nimport { pipe, required, email, withAsync } from '@regle/rules';\n\nconst checkEmailAvailable = withAsync(async (value) => {\n const response = await fetch(`/api/check-email?email=${value}`);\n return response.ok;\n});\n\nconst { r$ } = useRegle(\n { email: '' },\n {\n email: pipe(\n [required, email, checkEmailAvailable],\n { debounce: 300 } // Wait 300ms after last input before running async validators\n ),\n }\n);\n```\n\nThe debounce option only affects async validators in the pipe. Synchronous validators (`required`, `email` in the example above) run immediately, while the async validator (`checkEmailAvailable`) will be debounced.\n\n:::info Default debounce\nWhen using `pipe` with async validators, the default debounce delay is **200ms**. You can override this by passing a custom `debounce` value in the options.\n:::"
|
|
164
171
|
},
|
|
165
172
|
{
|
|
166
173
|
"id": "core-concepts-rules-rules-properties",
|
|
@@ -307,7 +314,7 @@ var docs_data_default = {
|
|
|
307
314
|
"title": "Type safe output",
|
|
308
315
|
"category": "typescript",
|
|
309
316
|
"path": "typescript/type-safe-output.md",
|
|
310
|
-
"content": "# Type safe output\n\nWhat would be the benefit of building a validation library without a type safe output?\n\nInspired by the `Zod` parse output type, `Regle` will also infer your validator types to know which properties are _**guaranteed**_ to be defined.\n\n## `$validate` \n\nUsing `r$.$validate` will asynchronously run and wait for all your validators to finish, and will return an object containing the status of your form.\n\n```ts\nconst { valid, data, errors, issues } = await r$.$validate();\n```\n\nIf your *_result_* is `true`, the **data** will be type safe.\n\nIt will check
|
|
317
|
+
"content": "# Type safe output\n\nWhat would be the benefit of building a validation library without a type safe output?\n\nInspired by the `Zod` parse output type, `Regle` will also infer your validator types to know which properties are _**guaranteed**_ to be defined.\n\n## `$validate` \n\nUsing `r$.$validate` will asynchronously run and wait for all your validators to finish, and will return an object containing the status of your form.\n\n```ts\nconst { valid, data, errors, issues } = await r$.$validate();\n```\n\nIf your *_result_* is `true`, the **data** will be type safe.\n\nIt will check the rules to get the ones that ensure the value is set (`required`, `literal`, `checked`)\n\nTt will not work with `requiredIf` or `requiredUnless`, because we can't know the condition at build time.\n\n```ts twoslash\nimport { useRegle } from '@regle/core';\nimport { ref, type Ref, computed } from 'vue';\nimport { required } from '@regle/rules';\n// ---cut---\ntype Form = {\n firstName?: string;\n lastName?: string;\n}\n\nconst form = ref<Form>({ firstName: '', lastName: '' })\n\nconst { r$ } = useRegle(form, {\n lastName: { required },\n});\n\nasync function submit() {\n const { valid, data, errors, issues } = await r$.$validate();\n\n if (valid) {\n console.log(data);\n \n }\n}\n```\n\n<br/>\n\n### `InferSafeOutput`\n\nYou can also statically infer the safe output from any `r$` instance.\n\n```ts twoslash\nimport { ref, type Ref, computed } from 'vue';\nimport { required } from '@regle/rules';\n// ---cut---\nimport { useRegle, InferSafeOutput } from '@regle/core';\ntype Form = {\n firstName?: string;\n lastName?: string;\n}\n\nconst form: Ref<Form> = ref({ firstName: '', lastName: '' })\n\nconst { r$ } = useRegle(form, {\n lastName: { required },\n});\n\ntype FormRequest = InferSafeOutput<typeof r$>;\n\n```"
|
|
311
318
|
},
|
|
312
319
|
{
|
|
313
320
|
"id": "typescript-typing-props",
|
|
@@ -332,11 +339,11 @@ var docs_data_default = {
|
|
|
332
339
|
"description": "Create a typed custom rule that can be used like built-in rules.\nThe created rule can be declared in global options or used directly.\n\nFeatures:\n- Automatically detects if the rule is async\n- Supports parameters for configurable rules\n- Full TypeScript type inference\n- Custom metadata support",
|
|
333
340
|
"parameters": [{
|
|
334
341
|
"name": "definition",
|
|
335
|
-
"type": "RegleRuleInit<TValue, TParams, TReturn, TMetadata, TAsync>",
|
|
342
|
+
"type": "RegleRuleInit<TType, TValue, TParams, TReturn, TMetadata, TAsync, TNonEmpty>",
|
|
336
343
|
"description": "- The rule definition object containing:\n- `validator`: The validation function\n- `message`: Error message (string or function)\n- `type`: Optional rule type identifier\n- `active`: Optional function to conditionally activate the rule\n- `tooltip`: Optional tooltip message",
|
|
337
344
|
"optional": false
|
|
338
345
|
}],
|
|
339
|
-
"returnType": "InferRegleRule<TValue, TParams, TAsync, TMetadata>",
|
|
346
|
+
"returnType": "InferRegleRule<TType, TValue, TParams, TAsync, TMetadata, TNonEmpty>",
|
|
340
347
|
"example": "import { createRule } from '@regle/core';\nimport { isFilled } from '@regle/rules';\n\n// Simple rule without params\nexport const isFoo = createRule({\n validator(value: Maybe<string>) {\n if (isFilled(value)) {\n return value === 'foo';\n }\n return true;\n },\n message: \"The value should be 'foo'\"\n});\n\n// Rule with parameters\nexport const minCustom = createRule({\n validator(value: Maybe<number>, min: number) {\n if (isFilled(value)) {\n return value >= min;\n }\n return true;\n },\n message: ({ $params: [min] }) => `Value must be at least ${min}`\n});\n\n// Usage\nuseRegle({ name: '' }, { name: { isFoo } });\nuseRegle({ count: 0 }, { count: { minCustom: minCustom(5) } });",
|
|
341
348
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/reusable-rules Documentation" }
|
|
342
349
|
},
|
|
@@ -685,7 +692,7 @@ var docs_data_default = {
|
|
|
685
692
|
"description": "",
|
|
686
693
|
"optional": false
|
|
687
694
|
}],
|
|
688
|
-
"returnType": "RegleRuleDefinition
|
|
695
|
+
"returnType": "RegleRuleDefinition<\"alpha\", string, [options?: CommonAlphaOptions], false, boolean, string, string, boolean>",
|
|
689
696
|
"example": "import { alpha } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n alpha,\n // or with symbols allowed\n alpha: alpha({ allowSymbols: true }),\n },\n})",
|
|
690
697
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#alpha Documentation" }
|
|
691
698
|
},
|
|
@@ -699,7 +706,7 @@ var docs_data_default = {
|
|
|
699
706
|
"description": "",
|
|
700
707
|
"optional": false
|
|
701
708
|
}],
|
|
702
|
-
"returnType": "RegleRuleDefinition
|
|
709
|
+
"returnType": "RegleRuleDefinition<\"alphaNum\", string | number, [options?: CommonAlphaOptions], false, boolean, string, string | number, boolean>",
|
|
703
710
|
"example": "import { alphaNum } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n alphaNum,\n // or with symbols allowed\n alphaNum: alphaNum({ allowSymbols: true }),\n },\n})",
|
|
704
711
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#alphanum Documentation" }
|
|
705
712
|
},
|
|
@@ -713,7 +720,7 @@ var docs_data_default = {
|
|
|
713
720
|
"description": "- Two or more rules to combine",
|
|
714
721
|
"optional": false
|
|
715
722
|
}],
|
|
716
|
-
"returnType": "RegleRuleDefinition<\n ExtractValueFromRules<TRules>[number],\n UnwrapTuples<ExtractParamsFromRules<TRules>>,\n GuessAsyncFromRules<TRules>,\n GuessMetadataFromRules<TRules
|
|
723
|
+
"returnType": "RegleRuleDefinition<\n 'and',\n ExtractValueFromRules<TRules>[number],\n UnwrapTuples<ExtractParamsFromRules<TRules>>,\n GuessAsyncFromRules<TRules>,\n GuessMetadataFromRules<TRules>,\n ExtractValueFr...",
|
|
717
724
|
"example": "import { useRegle } from '@regle/core';\nimport { and, startsWith, endsWith, withMessage } from '@regle/rules';\n\nconst { r$ } = useRegle(\n { regex: '' },\n {\n regex: {\n myError: withMessage(\n and(startsWith('^'), endsWith('$')),\n ({ $params: [start, end] }) =>\n `Regex should start with \"${start}\" and end with \"${end}\"`\n ),\n },\n }\n);",
|
|
718
725
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/rules-operators#and Documentation" }
|
|
719
726
|
},
|
|
@@ -721,18 +728,27 @@ var docs_data_default = {
|
|
|
721
728
|
"name": "applyIf",
|
|
722
729
|
"kind": "function",
|
|
723
730
|
"description": "The `applyIf` operator is similar to `requiredIf`, but it can be used with **any rule**.\nIt simplifies conditional rule declarations.",
|
|
724
|
-
"parameters": [
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
731
|
+
"parameters": [
|
|
732
|
+
{
|
|
733
|
+
"name": "_condition",
|
|
734
|
+
"type": "MaybeRefOrGetter<boolean>",
|
|
735
|
+
"description": "- The condition to check (ref, getter, or value)",
|
|
736
|
+
"optional": false
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
"name": "rule",
|
|
740
|
+
"type": "TRule",
|
|
741
|
+
"description": "- The rule to apply conditionally",
|
|
742
|
+
"optional": false
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
"name": "options",
|
|
746
|
+
"type": "ApplyIfOptions",
|
|
747
|
+
"description": "",
|
|
748
|
+
"optional": true
|
|
749
|
+
}
|
|
750
|
+
],
|
|
751
|
+
"returnType": "TRule extends InlineRuleDeclaration<infer TValue, infer TParams, infer TReturn>\n ? RegleRuleDefinition<\n 'applyIf',\n TValue,\n [...TParams, condition: boolean],\n TReturn extends Pr...",
|
|
736
752
|
"example": "import { minLength, applyIf } from '@regle/rules';\n\nconst condition = ref(false);\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n minLength: applyIf(condition, minLength(6))\n },\n});",
|
|
737
753
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/rules-operators#applyif Documentation" }
|
|
738
754
|
},
|
|
@@ -764,6 +780,20 @@ var docs_data_default = {
|
|
|
764
780
|
"example": "import { required, email, minLength, assignIf } from '@regle/rules';\n\nconst condition = ref(false);\n\nconst { r$ } = useRegle(ref({ name: '', email: '' }), {\n name: assignIf(condition, { required, minLength: minLength(4) }),\n email: { email },\n});",
|
|
765
781
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/rules-operators#assignif Documentation" }
|
|
766
782
|
},
|
|
783
|
+
{
|
|
784
|
+
"name": "atLeastOne",
|
|
785
|
+
"kind": "const",
|
|
786
|
+
"description": "Checks if at least one key is filled in the object.",
|
|
787
|
+
"parameters": [{
|
|
788
|
+
"name": "keys",
|
|
789
|
+
"type": "MaybeRefOrGetter<(NoInfer<keyof T> & string)[]>",
|
|
790
|
+
"description": "",
|
|
791
|
+
"optional": true
|
|
792
|
+
}],
|
|
793
|
+
"returnType": "RegleRuleDefinition<\"atLeastOne\", T, [keys?: (NoInfer<keyof T> & string)[]], false, boolean, false, T, boolean>",
|
|
794
|
+
"example": "import { atLeastOne } from '@regle/rules';\n\nconst { r$ } = useRegle({ user: { firstName: '', lastName: '' } }, {\n user: {\n atLeastOne,\n // or\n atLeastOne: atLeastOne(['firstName', 'lastName'])\n // or\n atLeastOne: atLeastOne<{ firstName: string; lastName: string }>(['firstName', 'lastName'])\n },\n});",
|
|
795
|
+
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#atleastone Documentation" }
|
|
796
|
+
},
|
|
767
797
|
{
|
|
768
798
|
"name": "between",
|
|
769
799
|
"kind": "const",
|
|
@@ -774,7 +804,7 @@ var docs_data_default = {
|
|
|
774
804
|
"description": "",
|
|
775
805
|
"optional": false
|
|
776
806
|
}],
|
|
777
|
-
"returnType": "RegleRuleDefinition
|
|
807
|
+
"returnType": "RegleRuleDefinition<\"between\", number, [min: number, max: number, options?: CommonComparisonOptions], false, boolean, number, number, boolean>",
|
|
778
808
|
"example": "import { between } from '@regle/rules';\n\nconst maxCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n between: between(1, 6),\n // or with reactive max\n between: between(1, maxCount, { allowEqual: false }),\n // or with getter\n between: between(() => maxCount.value, 10)\n },\n})",
|
|
779
809
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#between Documentation" }
|
|
780
810
|
},
|
|
@@ -806,7 +836,7 @@ var docs_data_default = {
|
|
|
806
836
|
"description": "",
|
|
807
837
|
"optional": false
|
|
808
838
|
}],
|
|
809
|
-
"returnType": "RegleRuleDefinition
|
|
839
|
+
"returnType": "RegleRuleDefinition<\"contains\", string, [part: string], false, boolean, string, string, boolean>",
|
|
810
840
|
"example": "import { contains } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestLib: '' }, {\n bestLib: {\n contains: contains('regle')\n },\n})",
|
|
811
841
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#contains Documentation" }
|
|
812
842
|
},
|
|
@@ -829,7 +859,7 @@ var docs_data_default = {
|
|
|
829
859
|
"description": "",
|
|
830
860
|
"optional": false
|
|
831
861
|
}],
|
|
832
|
-
"returnType": "RegleRuleDefinition
|
|
862
|
+
"returnType": "RegleRuleDefinition<\"dateAfter\", string | Date, [after: string | Date, options?: CommonComparisonOptions], false, true | { $valid: false; error: \"date-not-after\"; } | { ...; }, string | Date, string |...",
|
|
833
863
|
"example": "import { dateAfter } from '@regle/rules';\n\nconst { r$ } = useRegle({ birthday: null as Date | null }, {\n birthday: {\n dateAfter: dateAfter(new Date()),\n // or with options\n dateAfter: dateAfter(new Date(), { allowEqual: false }),\n },\n})",
|
|
834
864
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#dateafter Documentation" }
|
|
835
865
|
},
|
|
@@ -843,7 +873,7 @@ var docs_data_default = {
|
|
|
843
873
|
"description": "",
|
|
844
874
|
"optional": false
|
|
845
875
|
}],
|
|
846
|
-
"returnType": "RegleRuleDefinition
|
|
876
|
+
"returnType": "RegleRuleDefinition<\"dateBefore\", string | Date, [before: string | Date, options?: CommonComparisonOptions], false, true | { $valid: false; error: \"date-not-before\"; } | { ...; }, string | Date, strin...",
|
|
847
877
|
"example": "import { dateBefore } from '@regle/rules';\n\nconst { r$ } = useRegle({ birthday: null as Date | null }, {\n birthday: {\n dateBefore: dateBefore(new Date()),\n // or with options\n dateBefore: dateBefore(new Date(), { allowEqual: false }),\n },\n})",
|
|
848
878
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#datebefore Documentation" }
|
|
849
879
|
},
|
|
@@ -857,7 +887,7 @@ var docs_data_default = {
|
|
|
857
887
|
"description": "",
|
|
858
888
|
"optional": false
|
|
859
889
|
}],
|
|
860
|
-
"returnType": "RegleRuleDefinition
|
|
890
|
+
"returnType": "RegleRuleDefinition<\"dateBetween\", string | Date, [before: string | Date, after: string | Date, options?: CommonComparisonOptions], false, boolean, string | Date, string | Date, boolean>",
|
|
861
891
|
"example": "import { dateBetween } from '@regle/rules';\n\nconst { r$ } = useRegle({ birthday: null as Date | null }, {\n birthday: {\n dateBetween: dateBetween(new Date(), new Date(2030, 3, 1)),\n // or with options\n dateBetween: dateBetween(new Date(), new Date(2030, 3, 1), { allowEqual: false }),\n },\n})",
|
|
862
892
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#datebetween Documentation" }
|
|
863
893
|
},
|
|
@@ -898,7 +928,7 @@ var docs_data_default = {
|
|
|
898
928
|
"description": "",
|
|
899
929
|
"optional": false
|
|
900
930
|
}],
|
|
901
|
-
"returnType": "RegleRuleDefinition
|
|
931
|
+
"returnType": "RegleRuleDefinition<\"endsWith\", string, [part: string], false, boolean, string, string, boolean>",
|
|
902
932
|
"example": "import { endsWith } from '@regle/rules';\n\nconst { r$ } = useRegle({ firstName: '' }, {\n firstName: { endsWith: endsWith('foo') },\n})",
|
|
903
933
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#endswith Documentation" }
|
|
904
934
|
},
|
|
@@ -912,7 +942,7 @@ var docs_data_default = {
|
|
|
912
942
|
"description": "",
|
|
913
943
|
"optional": false
|
|
914
944
|
}],
|
|
915
|
-
"returnType": "RegleRuleDefinition
|
|
945
|
+
"returnType": "RegleRuleDefinition<\"exactDigits\", string | number, [count: number], false, boolean, unknown, string | number, boolean>",
|
|
916
946
|
"example": "import { exactDigits } from '@regle/rules';\n\nconst exactValue = ref(6);\n\nconst { r$ } = useRegle({ digits: '' }, {\n digits: {\n exactDigits: exactDigits(6),\n // or with reactive value\n exactDigits: exactDigits(exactValue),\n // or with getter\n exactDigits: exactDigits(() => exactValue.value)\n },\n})",
|
|
917
947
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#exactdigits Documentation" }
|
|
918
948
|
},
|
|
@@ -926,7 +956,7 @@ var docs_data_default = {
|
|
|
926
956
|
"description": "",
|
|
927
957
|
"optional": false
|
|
928
958
|
}],
|
|
929
|
-
"returnType": "RegleRuleDefinition
|
|
959
|
+
"returnType": "RegleRuleDefinition<\"exactLength\", string | any[] | Record<PropertyKey, any>, [count: number], false, boolean, unknown, string | any[] | Record<PropertyKey, any>, boolean>",
|
|
930
960
|
"example": "import { exactLength } from '@regle/rules';\n\nconst exactValue = ref(6);\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n exactLength: exactLength(6),\n // or with reactive value\n exactLength: exactLength(exactValue),\n // or with getter\n exactLength: exactLength(() => exactValue.value)\n },\n})",
|
|
931
961
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#exactlength Documentation" }
|
|
932
962
|
},
|
|
@@ -940,7 +970,7 @@ var docs_data_default = {
|
|
|
940
970
|
"description": "",
|
|
941
971
|
"optional": false
|
|
942
972
|
}],
|
|
943
|
-
"returnType": "RegleRuleDefinition
|
|
973
|
+
"returnType": "RegleRuleDefinition<\"exactValue\", number, [count: number], false, boolean, number, number, boolean>",
|
|
944
974
|
"example": "import { exactValue } from '@regle/rules';\n\nconst exactCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n exactValue: exactValue(6),\n // or with reactive value\n exactValue: exactValue(exactCount),\n // or with getter\n exactValue: exactValue(() => exactCount.value)\n },\n})",
|
|
945
975
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#exactvalue Documentation" }
|
|
946
976
|
},
|
|
@@ -963,7 +993,7 @@ var docs_data_default = {
|
|
|
963
993
|
"description": "",
|
|
964
994
|
"optional": false
|
|
965
995
|
}],
|
|
966
|
-
"returnType": "RegleRuleDefinition
|
|
996
|
+
"returnType": "RegleRuleDefinition<\"fileType\", File, [accept: readonly string[]], false, boolean, unknown, File, boolean>",
|
|
967
997
|
"example": "import { type InferInput } from '@regle/core';\nimport { fileType } from '@regle/rules';\n\nconst {r$} = useRegle({ file: null as File | null }, {\n file: { fileType: fileType(['image/png', 'image/jpeg']) },\n})",
|
|
968
998
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#filetype Documentation" }
|
|
969
999
|
},
|
|
@@ -1009,7 +1039,7 @@ var docs_data_default = {
|
|
|
1009
1039
|
"description": "",
|
|
1010
1040
|
"optional": false
|
|
1011
1041
|
}],
|
|
1012
|
-
"returnType": "RegleRuleDefinition
|
|
1042
|
+
"returnType": "RegleRuleDefinition<\"httpUrl\", string, [options?: UrlOptions], false, boolean, unknown, string, boolean>",
|
|
1013
1043
|
"example": "import { httpUrl } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestUrl: '' }, {\n bestUrl: { httpUrl },\n // or to force https protocol\n bestUrl: { httpUrl: httpUrl({ protocol: /^https$/ }) },\n})",
|
|
1014
1044
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#httpurl Documentation" }
|
|
1015
1045
|
},
|
|
@@ -1049,17 +1079,26 @@ var docs_data_default = {
|
|
|
1049
1079
|
"name": "isEmpty",
|
|
1050
1080
|
"kind": "function",
|
|
1051
1081
|
"description": "Checks if a value is empty in any way (including arrays and objects).\nThis is the inverse of `isFilled`.\n\n`isEmpty` also acts as a type guard.\n\nBy default, it considers an empty array as `true`. You can override this behavior with `considerEmptyArrayInvalid`.",
|
|
1052
|
-
"parameters": [
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1082
|
+
"parameters": [
|
|
1083
|
+
{
|
|
1084
|
+
"name": "value",
|
|
1085
|
+
"type": "unknown",
|
|
1086
|
+
"description": "- The target value to check",
|
|
1087
|
+
"optional": false
|
|
1088
|
+
},
|
|
1089
|
+
{
|
|
1090
|
+
"name": "considerEmptyArrayInvalid",
|
|
1091
|
+
"type": "boolean",
|
|
1092
|
+
"description": "- When `false`, empty arrays are not considered empty (default: `true`)",
|
|
1093
|
+
"optional": false
|
|
1094
|
+
},
|
|
1095
|
+
{
|
|
1096
|
+
"name": "considerEmptyObjectInvalid",
|
|
1097
|
+
"type": "boolean",
|
|
1098
|
+
"description": "",
|
|
1099
|
+
"optional": false
|
|
1100
|
+
}
|
|
1101
|
+
],
|
|
1063
1102
|
"returnType": "value is null | undefined | [] | EmptyObject",
|
|
1064
1103
|
"example": "import { createRule, type Maybe } from '@regle/core';\nimport { isEmpty } from '@regle/rules';\n\nconst rule = createRule({\n validator(value: Maybe<string>) {\n if (isEmpty(value)) {\n return true;\n }\n return check(value);\n },\n message: 'Error'\n})",
|
|
1065
1104
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/validations-helpers#isempty Documentation" }
|
|
@@ -1068,17 +1107,26 @@ var docs_data_default = {
|
|
|
1068
1107
|
"name": "isFilled",
|
|
1069
1108
|
"kind": "function",
|
|
1070
1109
|
"description": "Checks if any value you provide is defined (including arrays and objects).\nThis is almost a must-have for optional fields when writing custom rules.\n\n`isFilled` also acts as a type guard.\n\nBy default, it considers an empty array as `false`. You can override this behavior with `considerEmptyArrayInvalid`.",
|
|
1071
|
-
"parameters": [
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1110
|
+
"parameters": [
|
|
1111
|
+
{
|
|
1112
|
+
"name": "value",
|
|
1113
|
+
"type": "T",
|
|
1114
|
+
"description": "- The target value to check",
|
|
1115
|
+
"optional": false
|
|
1116
|
+
},
|
|
1117
|
+
{
|
|
1118
|
+
"name": "considerEmptyArrayInvalid",
|
|
1119
|
+
"type": "boolean",
|
|
1120
|
+
"description": "- When `false`, empty arrays are considered filled (default: `true`)",
|
|
1121
|
+
"optional": false
|
|
1122
|
+
},
|
|
1123
|
+
{
|
|
1124
|
+
"name": "considerEmptyObjectInvalid",
|
|
1125
|
+
"type": "boolean",
|
|
1126
|
+
"description": "",
|
|
1127
|
+
"optional": false
|
|
1128
|
+
}
|
|
1129
|
+
],
|
|
1082
1130
|
"returnType": "value is NonNullable<T>",
|
|
1083
1131
|
"example": "import { createRule } from '@regle/core';\nimport { isFilled } from '@regle/rules';\n\nconst rule = createRule({\n validator(value: unknown) {\n if (isFilled(value)) {\n return check(value);\n }\n return true;\n },\n message: 'Error'\n})",
|
|
1084
1132
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/validations-helpers#isfilled Documentation" }
|
|
@@ -1107,7 +1155,7 @@ var docs_data_default = {
|
|
|
1107
1155
|
"description": "- The literal value to match",
|
|
1108
1156
|
"optional": false
|
|
1109
1157
|
}],
|
|
1110
|
-
"returnType": "RegleRuleDefinition
|
|
1158
|
+
"returnType": "RegleRuleDefinition<\n 'literal',\n TValue,\n [literal: TValue],\n false,\n boolean,\n MaybeInput<TValue>,\n string | number,\n true\n>",
|
|
1111
1159
|
"example": "import { literal } from '@regle/rules';\n\nconst { r$ } = useRegle({ status: '' }, {\n status: { literal: literal('active') },\n})",
|
|
1112
1160
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#literal Documentation" }
|
|
1113
1161
|
},
|
|
@@ -1130,7 +1178,7 @@ var docs_data_default = {
|
|
|
1130
1178
|
"description": "",
|
|
1131
1179
|
"optional": false
|
|
1132
1180
|
}],
|
|
1133
|
-
"returnType": "RegleRuleDefinition
|
|
1181
|
+
"returnType": "RegleRuleDefinition<\"macAddress\", string, [separator?: string], false, boolean, string, string, boolean>",
|
|
1134
1182
|
"example": "import { macAddress } from '@regle/rules';\n\nconst { r$ } = useRegle({ address: '' }, {\n address: {\n macAddress,\n // or with custom separator\n macAddress: macAddress('-')\n },\n})",
|
|
1135
1183
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#macaddress Documentation" }
|
|
1136
1184
|
},
|
|
@@ -1163,7 +1211,7 @@ var docs_data_default = {
|
|
|
1163
1211
|
"description": "",
|
|
1164
1212
|
"optional": false
|
|
1165
1213
|
}],
|
|
1166
|
-
"returnType": "RegleRuleDefinition
|
|
1214
|
+
"returnType": "RegleRuleDefinition<\"maxFileSize\", File, [maxSize: number], false, true | { $valid: boolean; fileSize: number; }, unknown, File, boolean>",
|
|
1167
1215
|
"example": "import { type InferInput } from '@regle/core';\nimport { maxFileSize } from '@regle/rules';\n\nconst {r$} = useRegle({ file: null as File | null }, {\n file: { maxFileSize: maxFileSize(10_000_000) }, // 10 MB\n})",
|
|
1168
1216
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#maxfilesize Documentation" }
|
|
1169
1217
|
},
|
|
@@ -1177,7 +1225,7 @@ var docs_data_default = {
|
|
|
1177
1225
|
"description": "",
|
|
1178
1226
|
"optional": false
|
|
1179
1227
|
}],
|
|
1180
|
-
"returnType": "RegleRuleDefinition
|
|
1228
|
+
"returnType": "RegleRuleDefinition<\"maxLength\", string | any[] | Record<PropertyKey, any>, [max: number, options?: CommonComparisonOptions], false, boolean, unknown, string | any[] | Record<...>, boolean>",
|
|
1181
1229
|
"example": "import { maxLength } from '@regle/rules';\n\nconst maxValue = ref(6);\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n maxLength: maxLength(6),\n // or with reactive value\n maxLength: maxLength(maxValue),\n // or with getter\n maxLength: maxLength(() => maxValue.value)\n },\n})",
|
|
1182
1230
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#maxlength Documentation" }
|
|
1183
1231
|
},
|
|
@@ -1191,7 +1239,7 @@ var docs_data_default = {
|
|
|
1191
1239
|
"description": "",
|
|
1192
1240
|
"optional": false
|
|
1193
1241
|
}],
|
|
1194
|
-
"returnType": "RegleRuleDefinition
|
|
1242
|
+
"returnType": "RegleRuleDefinition<\"maxValue\", string | number, [max: string | number, options?: CommonComparisonOptions], false, boolean, string | number, string | number, boolean>",
|
|
1195
1243
|
"example": "import { maxValue } from '@regle/rules';\n\nconst maxCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n maxValue: maxValue(6),\n // or with options\n maxValue: maxValue(maxCount, { allowEqual: false }),\n // or with getter\n maxValue: maxValue(() => maxCount.value)\n },\n})",
|
|
1196
1244
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#maxvalue Documentation" }
|
|
1197
1245
|
},
|
|
@@ -1205,7 +1253,7 @@ var docs_data_default = {
|
|
|
1205
1253
|
"description": "",
|
|
1206
1254
|
"optional": false
|
|
1207
1255
|
}],
|
|
1208
|
-
"returnType": "RegleRuleDefinition
|
|
1256
|
+
"returnType": "RegleRuleDefinition<\"minFileSize\", File, [minSize: number], false, true | { $valid: boolean; fileSize: number; }, unknown, File, boolean>",
|
|
1209
1257
|
"example": "import { type InferInput } from '@regle/core';\nimport { minFileSize } from '@regle/rules';\n\nconst {r$} = useRegle({ file: null as File | null }, {\n file: { minFileSize: minFileSize(1_000_000) }, // 1 MB\n})",
|
|
1210
1258
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#minfilesize Documentation" }
|
|
1211
1259
|
},
|
|
@@ -1219,7 +1267,7 @@ var docs_data_default = {
|
|
|
1219
1267
|
"description": "",
|
|
1220
1268
|
"optional": false
|
|
1221
1269
|
}],
|
|
1222
|
-
"returnType": "RegleRuleDefinition
|
|
1270
|
+
"returnType": "RegleRuleDefinition<\"minLength\", string | any[] | Record<PropertyKey, any>, [min: number, options?: CommonComparisonOptions], false, boolean, unknown, string | any[] | Record<...>, boolean>",
|
|
1223
1271
|
"example": "import { minLength } from '@regle/rules';\n\nconst minValue = ref(6);\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n minLength: minLength(6),\n // or with reactive value\n minLength: minLength(minValue),\n // or with getter\n minLength: minLength(() => minValue.value)\n },\n})",
|
|
1224
1272
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#minlength Documentation" }
|
|
1225
1273
|
},
|
|
@@ -1233,7 +1281,7 @@ var docs_data_default = {
|
|
|
1233
1281
|
"description": "",
|
|
1234
1282
|
"optional": false
|
|
1235
1283
|
}],
|
|
1236
|
-
"returnType": "RegleRuleDefinition
|
|
1284
|
+
"returnType": "RegleRuleDefinition<\"minValue\", string | number, [min: string | number, options?: CommonComparisonOptions], false, boolean, string | number, string | number, boolean>",
|
|
1237
1285
|
"example": "import { minValue } from '@regle/rules';\n\nconst minCount = ref(6);\n\nconst { r$ } = useRegle({ count: 0 }, {\n count: {\n minValue: minValue(6),\n // or with options\n minValue: minValue(minCount, { allowEqual: false }),\n // or with getter\n minValue: minValue(() => minCount.value)\n },\n})",
|
|
1238
1286
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#minvalue Documentation" }
|
|
1239
1287
|
},
|
|
@@ -1247,7 +1295,7 @@ var docs_data_default = {
|
|
|
1247
1295
|
"description": "- The TypeScript enum to validate against",
|
|
1248
1296
|
"optional": false
|
|
1249
1297
|
}],
|
|
1250
|
-
"returnType": "RegleRuleDefinition
|
|
1298
|
+
"returnType": "RegleRuleDefinition<\n 'nativeEnum',\n MaybeInput<T[keyof T]>,\n [enumLike: T],\n false,\n boolean,\n MaybeInput<T[keyof T]>,\n string | number\n>",
|
|
1251
1299
|
"example": "import { nativeEnum } from '@regle/rules';\n\nenum Foo {\n Bar, Baz\n}\n\nconst { r$ } = useRegle({ type: '' }, {\n type: { nativeEnum: nativeEnum(Foo) },\n})",
|
|
1252
1300
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#nativeenum Documentation" }
|
|
1253
1301
|
},
|
|
@@ -1257,7 +1305,7 @@ var docs_data_default = {
|
|
|
1257
1305
|
"description": "The `not` operator passes when the provided rule **fails** and fails when the rule **passes**.\nIt can be combined with other rules.",
|
|
1258
1306
|
"parameters": [{
|
|
1259
1307
|
"name": "rule",
|
|
1260
|
-
"type": "RegleRuleDefinition<TValue, TParams, TAsync, TMetadata, unknown, TValue extends Date & File & infer M ? M : TValue> | InlineRuleDeclaration<...>",
|
|
1308
|
+
"type": "RegleRuleDefinition<TType, TValue, TParams, TAsync, TMetadata, unknown, TValue extends Date & File & infer M ? M : TValue, boolean> | InlineRuleDeclaration<...>",
|
|
1261
1309
|
"description": "- The rule to negate",
|
|
1262
1310
|
"optional": false
|
|
1263
1311
|
}, {
|
|
@@ -1266,7 +1314,7 @@ var docs_data_default = {
|
|
|
1266
1314
|
"description": "- Optional custom error message",
|
|
1267
1315
|
"optional": true
|
|
1268
1316
|
}],
|
|
1269
|
-
"returnType": "RegleRuleDefinition<TValue
|
|
1317
|
+
"returnType": "RegleRuleDefinition<\n IsUnknown<TType> extends true ? 'not' : `not:${TType & string}`,\n TValue,\n TParams,\n TAsync,\n TMetadata\n>",
|
|
1270
1318
|
"example": "import { useRegle } from '@regle/core';\nimport { not, required, sameAs, withMessage } from '@regle/rules';\nimport { ref } from 'vue';\n\nconst form = ref({ oldPassword: '', newPassword: '' });\n\nconst { r$ } = useRegle(form, {\n oldPassword: { required },\n newPassword: {\n notEqual: withMessage(\n not(sameAs(() => form.value.oldPassword)),\n 'Your new password must not be the same as your old password'\n ),\n },\n});",
|
|
1271
1319
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/rules-operators#not Documentation" }
|
|
1272
1320
|
},
|
|
@@ -1298,7 +1346,7 @@ var docs_data_default = {
|
|
|
1298
1346
|
"description": "- Array of allowed values",
|
|
1299
1347
|
"optional": false
|
|
1300
1348
|
}],
|
|
1301
|
-
"returnType": "RegleRuleDefinition
|
|
1349
|
+
"returnType": "RegleRuleDefinition<\"oneOf\", TValues[number], [options: TValues], false, boolean, TValues[number], string | number, boolean>",
|
|
1302
1350
|
"example": "import { oneOf } from '@regle/rules';\n\nconst { r$ } = useRegle({ aliment: 'Fish' }, {\n aliment: {\n oneOf: oneOf(['Fish', 'Meat', 'Bone'])\n },\n})",
|
|
1303
1351
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#oneof Documentation" }
|
|
1304
1352
|
},
|
|
@@ -1312,10 +1360,24 @@ var docs_data_default = {
|
|
|
1312
1360
|
"description": "- Two or more rules to combine",
|
|
1313
1361
|
"optional": false
|
|
1314
1362
|
}],
|
|
1315
|
-
"returnType": "RegleRuleDefinition<\n ExtractValueFromRules<TRules>[number],\n UnwrapTuples<ExtractParamsFromRules<TRules>>,\n GuessAsyncFromRules<TRules>,\n GuessMetadataFromRules<TRules>\n>",
|
|
1363
|
+
"returnType": "RegleRuleDefinition<\n 'or',\n ExtractValueFromRules<TRules>[number],\n UnwrapTuples<ExtractParamsFromRules<TRules>>,\n GuessAsyncFromRules<TRules>,\n GuessMetadataFromRules<TRules>\n>",
|
|
1316
1364
|
"example": "import { useRegle } from '@regle/core';\nimport { or, startsWith, endsWith, withMessage } from '@regle/rules';\n\nconst { r$ } = useRegle(\n { regex: '' },\n {\n regex: {\n myError: withMessage(\n or(startsWith('^'), endsWith('$')),\n ({ $params: [start, end] }) =>\n `Field should start with \"${start}\" or end with \"${end}\"`\n ),\n },\n }\n);",
|
|
1317
1365
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/rules-operators#or Documentation" }
|
|
1318
1366
|
},
|
|
1367
|
+
{
|
|
1368
|
+
"name": "pipe",
|
|
1369
|
+
"kind": "function",
|
|
1370
|
+
"description": "The `pipe` operator chains multiple rules together, where each rule only runs\nif all previous rules have passed. This is useful for sequential validation\nwhere later rules depend on earlier ones passing.",
|
|
1371
|
+
"parameters": [{
|
|
1372
|
+
"name": "rules",
|
|
1373
|
+
"type": "TRulesDelc",
|
|
1374
|
+
"description": "- Two or more rules to chain together",
|
|
1375
|
+
"optional": false
|
|
1376
|
+
}],
|
|
1377
|
+
"returnType": "Prettify<PipeTupleToObject<TRulesDelc>>",
|
|
1378
|
+
"example": "import { useRegle } from '@regle/core';\nimport { pipe, required, minLength, email } from '@regle/rules';\n\nconst { r$ } = useRegle(\n { email: '' },\n {\n email: pipe(required, minLength(5), email),\n }\n);\n// minLength only runs if required passes\n// email only runs if both required and minLength pass",
|
|
1379
|
+
"tags": { "see": "://reglejs.dev/core-concepts/rules/rules-operators#pipe Documentation" }
|
|
1380
|
+
},
|
|
1319
1381
|
{
|
|
1320
1382
|
"name": "regex",
|
|
1321
1383
|
"kind": "const",
|
|
@@ -1326,7 +1388,7 @@ var docs_data_default = {
|
|
|
1326
1388
|
"description": "",
|
|
1327
1389
|
"optional": false
|
|
1328
1390
|
}],
|
|
1329
|
-
"returnType": "RegleRuleDefinition
|
|
1391
|
+
"returnType": "RegleRuleDefinition<\"regex\", string | number, [regexp: RegExp | RegExp[]], false, boolean, string | number, string | number, boolean>",
|
|
1330
1392
|
"example": "import { regex } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n regex: regex(/^foo/),\n // or with multiple patterns\n regex: regex([/^bar/, /baz$/]),\n },\n})",
|
|
1331
1393
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#regex Documentation" }
|
|
1332
1394
|
},
|
|
@@ -1349,7 +1411,7 @@ var docs_data_default = {
|
|
|
1349
1411
|
"description": "",
|
|
1350
1412
|
"optional": false
|
|
1351
1413
|
}],
|
|
1352
|
-
"returnType": "RegleRuleDefinition
|
|
1414
|
+
"returnType": "RegleRuleDefinition<\"required\", unknown, [condition: boolean], false, boolean, unknown, unknown, boolean>",
|
|
1353
1415
|
"example": "import { requiredIf } from '@regle/rules';\n\nconst form = ref({ name: '', condition: false });\nconst conditionRef = ref(false);\n\nconst { r$ } = useRegle(form, {\n name: {\n required: requiredIf(() => form.value.condition),\n // or with a ref\n required: requiredIf(conditionRef),\n },\n})",
|
|
1354
1416
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#requiredif Documentation" }
|
|
1355
1417
|
},
|
|
@@ -1363,7 +1425,7 @@ var docs_data_default = {
|
|
|
1363
1425
|
"description": "",
|
|
1364
1426
|
"optional": false
|
|
1365
1427
|
}],
|
|
1366
|
-
"returnType": "RegleRuleDefinition
|
|
1428
|
+
"returnType": "RegleRuleDefinition<\"required\", unknown, [condition: boolean], false, boolean, unknown, unknown, boolean>",
|
|
1367
1429
|
"example": "import { requiredUnless } from '@regle/rules';\n\nconst form = ref({ name: '', condition: false });\nconst conditionRef = ref(false);\n\nconst { r$ } = useRegle(form, {\n name: {\n required: requiredUnless(() => form.value.condition),\n // or with a ref\n required: requiredUnless(conditionRef)\n },\n})",
|
|
1368
1430
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#requiredunless Documentation" }
|
|
1369
1431
|
},
|
|
@@ -1382,7 +1444,7 @@ var docs_data_default = {
|
|
|
1382
1444
|
"description": "- Optional name for the other field (used in error message)",
|
|
1383
1445
|
"optional": true
|
|
1384
1446
|
}],
|
|
1385
|
-
"returnType": "RegleRuleDefinition
|
|
1447
|
+
"returnType": "RegleRuleDefinition<\"sameAs\", TTarget, [target: TTarget, otherName?: string], false, boolean, TTarget extends infer M ? M : TTarget, TTarget extends Date & ... 1 more ... & infer M ? M : TTarget, bool...",
|
|
1386
1448
|
"example": "import { sameAs } from '@regle/rules';\n\nconst form = ref({\n password: '',\n confirmPassword: '',\n});\n\nconst { r$ } = useRegle(form, {\n confirmPassword: {\n sameAs: sameAs(() => form.value.password),\n }\n})",
|
|
1387
1449
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#sameas Documentation" }
|
|
1388
1450
|
},
|
|
@@ -1396,7 +1458,7 @@ var docs_data_default = {
|
|
|
1396
1458
|
"description": "",
|
|
1397
1459
|
"optional": false
|
|
1398
1460
|
}],
|
|
1399
|
-
"returnType": "RegleRuleDefinition
|
|
1461
|
+
"returnType": "RegleRuleDefinition<\"startsWith\", string, [part: string], false, boolean, string, string, boolean>",
|
|
1400
1462
|
"example": "import { startsWith } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestLib: '' }, {\n bestLib: {\n startsWith: startsWith('regle')\n },\n})",
|
|
1401
1463
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#startswith Documentation" }
|
|
1402
1464
|
},
|
|
@@ -1442,7 +1504,7 @@ var docs_data_default = {
|
|
|
1442
1504
|
"kind": "function",
|
|
1443
1505
|
"description": "Define the input type of a rule. No runtime validation.\n\nOverride any input type set by other rules.",
|
|
1444
1506
|
"parameters": [],
|
|
1445
|
-
"returnType": "RegleRuleDefinition<unknown, [], false, boolean, MaybeInput<T>>",
|
|
1507
|
+
"returnType": "RegleRuleDefinition<'type', unknown, [], false, boolean, MaybeInput<T>>",
|
|
1446
1508
|
"example": "import { type InferInput } from '@regle/core';\nimport { type } from '@regle/rules';\n\nconst rules = {\n firstName: { type: type<string>() },\n status: { type: type<'active' | 'inactive'>() },\n}\n\nconst state = ref<InferInput<typeof rules>>({});",
|
|
1447
1509
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#type Documentation" }
|
|
1448
1510
|
},
|
|
@@ -1465,7 +1527,7 @@ var docs_data_default = {
|
|
|
1465
1527
|
"description": "",
|
|
1466
1528
|
"optional": false
|
|
1467
1529
|
}],
|
|
1468
|
-
"returnType": "RegleRuleDefinition
|
|
1530
|
+
"returnType": "RegleRuleDefinition<\"url\", string, [options?: UrlOptions], false, boolean, unknown, string, boolean>",
|
|
1469
1531
|
"example": "import { url } from '@regle/rules';\n\nconst { r$ } = useRegle({ bestUrl: '' }, {\n bestUrl: { url },\n // or with custom protocol validation\n bestUrl: { url: url({ protocol: /^https?$/ }) },\n})",
|
|
1470
1532
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/built-in-rules#url Documentation" }
|
|
1471
1533
|
},
|
|
@@ -1484,7 +1546,7 @@ var docs_data_default = {
|
|
|
1484
1546
|
"description": "- Array of reactive dependencies (refs or getters)",
|
|
1485
1547
|
"optional": true
|
|
1486
1548
|
}],
|
|
1487
|
-
"returnType": "RegleRuleDefinition<TValue, UnwrapRegleUniversalParams<TParams>, true, TMetadata>",
|
|
1549
|
+
"returnType": "RegleRuleDefinition<unknown, TValue, UnwrapRegleUniversalParams<TParams>, true, TMetadata>",
|
|
1488
1550
|
"example": "import { withAsync } from '@regle/rules';\n\nconst base = ref('foo');\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n customRule: withAsync(async (value, param) => {\n await someAsyncCall(param)\n }, [base])\n }\n})",
|
|
1489
1551
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/rule-wrappers#withasync Documentation" }
|
|
1490
1552
|
},
|
|
@@ -1494,7 +1556,7 @@ var docs_data_default = {
|
|
|
1494
1556
|
"description": "The `withMessage` wrapper lets you associate an error message with a rule.\nPass your rule as the first argument and the error message as the second.",
|
|
1495
1557
|
"parameters": [{
|
|
1496
1558
|
"name": "rule",
|
|
1497
|
-
"type": "RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetadata>",
|
|
1559
|
+
"type": "RegleRuleWithParamsDefinition<TType, TValue, TParams, TAsync, TMetadata>",
|
|
1498
1560
|
"description": "- The rule to wrap (can be inline function or rule definition)",
|
|
1499
1561
|
"optional": false
|
|
1500
1562
|
}, {
|
|
@@ -1503,7 +1565,7 @@ var docs_data_default = {
|
|
|
1503
1565
|
"description": "- The error message (string or function returning a string)",
|
|
1504
1566
|
"optional": false
|
|
1505
1567
|
}],
|
|
1506
|
-
"returnType": "RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetadata>",
|
|
1568
|
+
"returnType": "RegleRuleWithParamsDefinition<TType, TValue, TParams, TAsync, TMetadata>",
|
|
1507
1569
|
"example": "import { withMessage } from '@regle/rules';\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n // With a static message\n customRule1: withMessage((value) => !!value, \"Custom Error\"),\n // With dynamic message using metadata\n customRule2: withMessage(\n customRuleInlineWithMetaData,\n ({ $value, foo }) => `Custom Error: ${$value} ${foo}`\n ),\n }\n})",
|
|
1508
1570
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/rule-wrappers#withmessage Documentation" }
|
|
1509
1571
|
},
|
|
@@ -1513,7 +1575,7 @@ var docs_data_default = {
|
|
|
1513
1575
|
"description": "The `withParams` wrapper allows your rule to depend on external parameters,\nsuch as a reactive property in your component or store.\n\nBy default, `useRegle` observes changes automatically when rules are defined using getter functions or computed properties.\nHowever, sometimes dependencies cannot be tracked automatically; use `withParams` to manually define them.",
|
|
1514
1576
|
"parameters": [{
|
|
1515
1577
|
"name": "rule",
|
|
1516
|
-
"type": "InlineRuleDeclaration<TValue, TParams, TReturn> | RegleRuleDefinition<TValue, any[], TAsync, TMetadata, unknown, TValue extends Date & ... 1 more ... & infer M ? M : TValue>",
|
|
1578
|
+
"type": "InlineRuleDeclaration<TValue, TParams, TReturn> | RegleRuleDefinition<TType, TValue, any[], TAsync, TMetadata, unknown, TValue extends Date & ... 1 more ... & infer M ? M : TValue, boolean>",
|
|
1517
1579
|
"description": "- The rule function or definition",
|
|
1518
1580
|
"optional": false
|
|
1519
1581
|
}, {
|
|
@@ -1522,7 +1584,7 @@ var docs_data_default = {
|
|
|
1522
1584
|
"description": "- Array of reactive dependencies (refs or getters)",
|
|
1523
1585
|
"optional": false
|
|
1524
1586
|
}],
|
|
1525
|
-
"returnType": "RegleRuleDefinition<TValue, UnwrapRegleUniversalParams<TParams>, TAsync, TMetadata>",
|
|
1587
|
+
"returnType": "RegleRuleDefinition<TType, TValue, UnwrapRegleUniversalParams<TParams>, TAsync, TMetadata>",
|
|
1526
1588
|
"example": "import { withParams } from '@regle/rules';\n\nconst base = ref('foo');\n\nconst { r$ } = useRegle({ name: '' }, {\n name: {\n customRule: withParams((value, param) => value === param, [base]),\n // or with getter\n customRule: withParams((value, param) => value === param, [() => base.value]),\n }\n})",
|
|
1527
1589
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/rule-wrappers#withparams Documentation" }
|
|
1528
1590
|
},
|
|
@@ -1532,7 +1594,7 @@ var docs_data_default = {
|
|
|
1532
1594
|
"description": "The `withTooltip` wrapper allows you to display additional messages for your field that aren't necessarily errors.\nTooltips are aggregated and accessible via `$tooltips` property.",
|
|
1533
1595
|
"parameters": [{
|
|
1534
1596
|
"name": "rule",
|
|
1535
|
-
"type": "RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetadata>",
|
|
1597
|
+
"type": "RegleRuleWithParamsDefinition<TType, TValue, TParams, TAsync, TMetadata>",
|
|
1536
1598
|
"description": "- The rule to wrap (can be inline function or rule definition)",
|
|
1537
1599
|
"optional": false
|
|
1538
1600
|
}, {
|
|
@@ -1541,9 +1603,23 @@ var docs_data_default = {
|
|
|
1541
1603
|
"description": "- The tooltip message (string or function returning a string)",
|
|
1542
1604
|
"optional": false
|
|
1543
1605
|
}],
|
|
1544
|
-
"returnType": "RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetadata>",
|
|
1606
|
+
"returnType": "RegleRuleWithParamsDefinition<TType, TValue, TParams, TAsync, TMetadata>",
|
|
1545
1607
|
"example": "import { withTooltip, minLength } from '@regle/rules';\n\nconst { r$ } = useRegle({ password: '' }, {\n password: {\n minLength: withTooltip(\n minLength(8),\n 'Password should be at least 8 characters for better security'\n ),\n }\n})\n\n// Access tooltips via:\n// r$.password.$tooltips",
|
|
1546
1608
|
"tags": { "see": "://reglejs.dev/core-concepts/rules/rule-wrappers#withtooltip Documentation" }
|
|
1609
|
+
},
|
|
1610
|
+
{
|
|
1611
|
+
"name": "xor",
|
|
1612
|
+
"kind": "function",
|
|
1613
|
+
"description": "The `xor` operator validates successfully if **exactly one** of the provided rules is valid (exclusive or).",
|
|
1614
|
+
"parameters": [{
|
|
1615
|
+
"name": "rules",
|
|
1616
|
+
"type": "[...TRules]",
|
|
1617
|
+
"description": "- Two or more rules to combine",
|
|
1618
|
+
"optional": false
|
|
1619
|
+
}],
|
|
1620
|
+
"returnType": "RegleRuleDefinition<\n 'xor',\n ExtractValueFromRules<TRules>[number],\n UnwrapTuples<ExtractParamsFromRules<TRules>>,\n GuessAsyncFromRules<TRules>,\n GuessMetadataFromRules<TRules>\n>",
|
|
1621
|
+
"example": "import { useRegle } from '@regle/core';\nimport { xor, contains, withMessage } from '@regle/rules';\n\nconst { r$ } = useRegle(\n { code: '' },\n {\n code: {\n myError: withMessage(\n xor(contains('A'), contains('B')),\n ({ $params: [charA, charB] }) =>\n `Field should contain either \"${charA}\" or \"${charB}\", but not both`\n ),\n },\n }\n);",
|
|
1622
|
+
"tags": { "see": "://reglejs.dev/core-concepts/rules/rules-operators#xor Documentation" }
|
|
1547
1623
|
}
|
|
1548
1624
|
],
|
|
1549
1625
|
"@regle/schemas": [
|
|
@@ -1814,7 +1890,7 @@ function searchApi(query) {
|
|
|
1814
1890
|
return results;
|
|
1815
1891
|
}
|
|
1816
1892
|
|
|
1817
|
-
var version = "1.18.0-beta.
|
|
1893
|
+
var version = "1.18.0-beta.2";
|
|
1818
1894
|
|
|
1819
1895
|
let posthogClient = null;
|
|
1820
1896
|
posthogClient = new PostHog("phc_kqgJoylCpKkGkkRGxb4MyN2mViehoQcUFEGwVkk4l8E", {
|