Are you an LLM? You can read better optimized documentation at /advanced-usage/rule-metadata.md for this page in Markdown format
Rules metadata
Rule validator functions can return more than just a boolean. It can return any object as long as it returns an object containing at least $valid: boolean.
This additional data can be utilized by your message handler, active handler, or any other part of your application that has access to the regle instance.
ts
import {} from '@regle/rules';
import {} from '@regle/core';
const = ((: unknown) => {
return {
: true,
: 100
}
}, ({}) => `Hello ${}`)
const { } = ({: ''}, {
: {}
})
.....
Using metadata in createRule
You can use createRule to define your custom rules. Let's explore a real-world example by creating a password strength validator.
ts
import { , } from '@regle/core';
import { } from '@regle/rules';
import { , type } from 'check-password-strength';
export const = ({
(: <string>, ?: <string>) {
if (()) {
const = (, );
return {
: . > 1,
,
};
}
return { : true };
},
({ }) {
return `Your password is ${?.}`;
},
});vue
<template>
<>
<
v-model=".."
="{ : .. }"
="Type your password"
/>
< ="button" @=".({: true})">Reset</>
</>
<
="password-strength"
="[`level-${.....?.}`]">
</>
< v-if="...">
< v-for=" of .." ="">
{{ }}
</>
</>
< v-else-if=".." ="success">
Your password is strong enough
</>
</template>
<script setup lang="ts">
import { } from '@regle/core';
const { } = (
{ : '' },
{
: {
: (),
},
}
);
</script>Result:

