diff --git a/docs/src/advanced-usage/async-validation.md b/docs/src/advanced-usage/async-validation.md index 29747735..2ba9ee23 100644 --- a/docs/src/advanced-usage/async-validation.md +++ b/docs/src/advanced-usage/async-validation.md @@ -23,7 +23,7 @@ To declare an async rule, you simply have to use the `async await` syntax. ```ts const myAsyncRule = async (value: Maybe) => { - if (ruleHelpers.isFilled(value)) { + if (isFilled(value)) { return await someStuff(); } return true; @@ -40,7 +40,7 @@ In the same way of an inline rule, your validator function must be using `async ```ts const myAsyncRule = createRule({ validator(value: Maybe) { - if (ruleHelpers.isFilled(value)) { + if (isFilled(value)) { return await someStuff(); } return true; @@ -92,12 +92,12 @@ function timeout(count: number) { } // ---cut--- import { createRule, useRegle, type Maybe } from '@regle/core'; -import { email, ruleHelpers } from '@regle/rules'; +import { email, isEmpty } from '@regle/rules'; import { ref } from 'vue'; const checkEmailExists = createRule({ async validator(value: Maybe) { - if (ruleHelpers.isEmpty(value) || !email.exec(value)) { + if (isEmpty(value) || !email.exec(value)) { return true; } diff --git a/docs/src/advanced-usage/rule-metadata.md b/docs/src/advanced-usage/rule-metadata.md index 7386781c..e8048e4f 100644 --- a/docs/src/advanced-usage/rule-metadata.md +++ b/docs/src/advanced-usage/rule-metadata.md @@ -20,12 +20,12 @@ You can use `createRule` to define your custom rules. Let's explore a real-world // @filename strongPassword.ts // ---cut--- import { createRule, Maybe } from '@regle/core'; -import { ruleHelpers } from '@regle/rules'; +import { isFilled } from '@regle/rules'; import { passwordStrength, type Options } from 'check-password-strength'; export const strongPassword = createRule({ validator(value: Maybe, options?: Options) { - if (ruleHelpers.isFilled(value)) { + if (isFilled(value)) { const result = passwordStrength(value, options); return { $valid: result.id > 1, diff --git a/docs/src/advanced-usage/validations-helpers.md b/docs/src/advanced-usage/validations-helpers.md index 978091d7..73f5b49b 100644 --- a/docs/src/advanced-usage/validations-helpers.md +++ b/docs/src/advanced-usage/validations-helpers.md @@ -11,7 +11,7 @@ To simplify this process, Regle provides a set of utility functions to assist in These utilities can be accessed via: ```ts -import { ruleHelpers } from '@regle/rules'; +import { isFilled, isEmpty, getSize, ... } from '@regle/rules'; ``` ## Runtime and Type guards @@ -27,16 +27,16 @@ You can base your validator result on this. const check = (value: any) => false; //---cut--- import { createRule } from '@regle/core'; -import { ruleHelpers } from '@regle/rules'; +import { isFilled } from '@regle/rules'; const rule = createRule({ validator(value: unknown) { - if (ruleHelpers.isFilled(value)) { + if (isFilled(value)) { return check(value); } return true; }, - message: '' + message: 'Error' }) ``` @@ -50,17 +50,17 @@ This is the inverse of `isFilled`. It will check if the value is in any way empt const check = (value: any) => false; //---cut--- import { createRule, type Maybe } from '@regle/core'; -import { ruleHelpers } from '@regle/rules'; +import { isEmpty } from '@regle/rules'; const rule = createRule({ validator(value: Maybe) { - if (ruleHelpers.isEmpty(value)) { + if (isEmpty(value)) { return true; } return check(value); // ^? }, - message: '' + message: 'Error' }) ``` @@ -74,17 +74,17 @@ This also returns false for `NaN`, so this is better than `typeof value === "num const checkNumber = (value: number) => false; //---cut--- import { createRule, type Maybe } from '@regle/core'; -import { ruleHelpers } from '@regle/rules'; +import { isFilled, isNumber } from '@regle/rules'; const rule = createRule({ validator(value: Maybe) { - if (ruleHelpers.isFilled(value) && ruleHelpers.isNumber(value)) { + if (isFilled(value) && isNumber(value)) { return checkNumber(value); // ^? } return true; }, - message: '' + message: 'Error' }) ``` @@ -98,58 +98,58 @@ This can also check strings. const checkDate = (value: Date) => false; //---cut--- import { createRule, type Maybe } from '@regle/core'; -import { ruleHelpers } from '@regle/rules'; +import { isFilled, isDate } from '@regle/rules'; const rule = createRule({ validator(value: Maybe) { - if (ruleHelpers.isFilled(value) && ruleHelpers.isDate(value)) { + if (isFilled(value) && isDate(value)) { return checkDate(value); // ^? } return true; }, - message: '' + message: 'Error' }) ``` ## Operations utils -### `size` +### `getSize` This helper will return the length of any data type you pass. It works with strings, arrays, objects and numbers. ```ts twoslash import { createRule, type Maybe } from '@regle/core'; -import { ruleHelpers } from '@regle/rules'; +import { isFilled, getSize } from '@regle/rules'; const rule = createRule({ validator(value: Maybe>) { - if (ruleHelpers.isFilled(value)) { - return ruleHelpers.size(value) > 6; + if (isFilled(value)) { + return getSize(value) > 6; } return true; }, - message: '' + message: 'Error' }) ``` -### `regex` +### `matchRegex` This utility can take multiple regular expressions as arguments. It checks the input's validity and tests it against the provided regex patterns. ```ts twoslash import { createRule, type Maybe } from '@regle/core'; -import { ruleHelpers } from '@regle/rules'; +import { isFilled, matchRegex } from '@regle/rules'; const rule = createRule({ validator(value: Maybe, ...regexps: RegExp[]) { - if (ruleHelpers.isFilled(value)) { - return ruleHelpers.regex(value, ...regexps); + if (isFilled(value)) { + return matchRegex(value, ...regexps); } return true; }, - message: '' + message: 'Error' }) ``` diff --git a/docs/src/core-concepts/global-config.md b/docs/src/core-concepts/global-config.md index c9c07375..ce58f4a9 100644 --- a/docs/src/core-concepts/global-config.md +++ b/docs/src/core-concepts/global-config.md @@ -52,11 +52,11 @@ const someAsyncCall = async () => await Promise.resolve(true); // ---cut--- // @noErrors import { defineRegleConfig, createRule, Maybe } from '@regle/core'; -import { withMessage, ruleHelpers } from '@regle/rules'; +import { withMessage, isFilled } from '@regle/rules'; const asyncEmail = createRule({ async validator(value: Maybe) { - if (!ruleHelpers.isFilled(value)) { + if (!isFilled(value)) { return true; } diff --git a/docs/src/core-concepts/rules/reusable-rules.md b/docs/src/core-concepts/rules/reusable-rules.md index 51838d62..57c497aa 100644 --- a/docs/src/core-concepts/rules/reusable-rules.md +++ b/docs/src/core-concepts/rules/reusable-rules.md @@ -19,11 +19,11 @@ Example: Recreating a simple `required` rule ```ts twoslash // @noErrors import { createRule } from '@regle/core'; -import { ruleHelpers } from '@regle/rules'; +import { isFilled } from '@regle/rules'; export const required = createRule({ validator: (value: unknown) => { - return ruleHelpers.isFilled(value); + return isFilled(value); }, message: 'This field is required', }); @@ -165,7 +165,7 @@ useRegle(state, rules); ```ts twoslash include requiredIf [requiredIf.ts] // @noErrors import { createRule, useRegle } from '@regle/core'; -import { ruleHelpers } from '@regle/rules'; +import { isFilled } from '@regle/rules'; import { ref } from 'vue'; export const requiredIf = createRule({ @@ -173,7 +173,7 @@ export const requiredIf = createRule({ // Params like `condition` will always be unwrapped here // no need to check if it's a value, a ref or a getter function if (condition) { - return ruleHelpers.isFilled(value); + return isFilled(value); } return true; }, @@ -268,12 +268,12 @@ function timeout(count: number) { } // ---cut--- import { createRule, useRegle, type Maybe } from '@regle/core'; -import { email, ruleHelpers } from '@regle/rules'; +import { email, isEmpty } from '@regle/rules'; import { ref } from 'vue'; const checkEmailExists = createRule({ async validator(value: Maybe) { - if (ruleHelpers.isEmpty(value) || !email.exec(value)) { + if (isEmpty(value) || !email.exec(value)) { return true; } diff --git a/docs/src/integrations/nuxt.md b/docs/src/integrations/nuxt.md index 5f1abcae..d1dda002 100644 --- a/docs/src/integrations/nuxt.md +++ b/docs/src/integrations/nuxt.md @@ -48,11 +48,11 @@ The following exports will become globally available in your Nuxt application: - defineRegleConfig - inferRules - `@regle/rules` Note: Built-in rules are not auto-injected to minimize the risk of name conflicts. - - ruleHelpers - withAsync - withMessage - withParams - withTooltip - `@regle/zod` (if present) - useZodRegle - +- `@regle/valibot` (if present) + - useValibotRegle diff --git a/docs/src/parts/components/metadata/UsingMetadataCreateRule.vue b/docs/src/parts/components/metadata/UsingMetadataCreateRule.vue index 3c666e77..d3635f9b 100644 --- a/docs/src/parts/components/metadata/UsingMetadataCreateRule.vue +++ b/docs/src/parts/components/metadata/UsingMetadataCreateRule.vue @@ -10,9 +10,7 @@ -
+
    @@ -21,27 +19,25 @@
-
- Your password is strong enough -
+
Your password is strong enough