mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 16:56:14 -04:00
feat(tool): bip39-generator
This commit is contained in:
parent
3ae872847b
commit
d55329f3ab
5 changed files with 193 additions and 28 deletions
27
src/composable/validation.ts
Normal file
27
src/composable/validation.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { reactive, watch, type Ref } from 'vue';
|
||||
|
||||
type UseValidationRule<T> = {
|
||||
validator: (value: T) => boolean
|
||||
message: string
|
||||
}
|
||||
|
||||
export function useValidation<T>({ source, rules }: { source: Ref<T>; rules: UseValidationRule<T>[] }) {
|
||||
const state = reactive<{
|
||||
message: string,
|
||||
status: undefined | 'error'
|
||||
}>({
|
||||
message: '',
|
||||
status: undefined
|
||||
})
|
||||
|
||||
watch([source], () => {
|
||||
for(const rule of rules) {
|
||||
if(!rule.validator(source.value)){
|
||||
state.message = rule.message
|
||||
state.status = 'error'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return state;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue