mirror of
https://github.com/CorentinTh/it-tools.git
synced 2026-05-27 01:12:36 -04:00
feat(tool): bip39-generator
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user