diff --git a/package-lock.json b/package-lock.json index e8bd93ce..01108791 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "it-tools", "version": "0.0.0", "dependencies": { + "@it-tools/bip39": "^0.0.4", "@vicons/material": "^0.12.0", "@vicons/tabler": "^0.12.0", "@vueuse/core": "^8.2.1", @@ -686,6 +687,18 @@ "node": ">=8" } }, + "node_modules/@it-tools/bip39": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/@it-tools/bip39/-/bip39-0.0.4.tgz", + "integrity": "sha512-0PWO7VKi6VALiFcm8z2WgxzSZ5wAko0OctBZ0I5+jjtSIXm3t1d54yrrHfgFOZDTyMpCXi638oLpzqexcfRtbA==", + "dependencies": { + "js-sha256": "^0.9.0", + "nanoid": "^3.3.2" + }, + "funding": { + "url": "https://github.com/sponsors/CorentinTh" + } + }, "node_modules/@jridgewell/resolve-uri": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.0.5.tgz", @@ -4961,6 +4974,11 @@ "@sideway/pinpoint": "^2.0.0" } }, + "node_modules/js-sha256": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", + "integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==" + }, "node_modules/js-stringify": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/js-stringify/-/js-stringify-1.0.2.tgz", @@ -8416,6 +8434,15 @@ "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==", "dev": true }, + "@it-tools/bip39": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/@it-tools/bip39/-/bip39-0.0.4.tgz", + "integrity": "sha512-0PWO7VKi6VALiFcm8z2WgxzSZ5wAko0OctBZ0I5+jjtSIXm3t1d54yrrHfgFOZDTyMpCXi638oLpzqexcfRtbA==", + "requires": { + "js-sha256": "^0.9.0", + "nanoid": "^3.3.2" + } + }, "@jridgewell/resolve-uri": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.0.5.tgz", @@ -11516,6 +11543,11 @@ "@sideway/pinpoint": "^2.0.0" } }, + "js-sha256": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", + "integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==" + }, "js-stringify": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/js-stringify/-/js-stringify-1.0.2.tgz", diff --git a/package.json b/package.json index 06c90490..0bfc4b76 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore" }, "dependencies": { + "@it-tools/bip39": "^0.0.4", "@vicons/material": "^0.12.0", "@vicons/tabler": "^0.12.0", "@vueuse/core": "^8.2.1", diff --git a/src/composable/validation.ts b/src/composable/validation.ts new file mode 100644 index 00000000..09b1fce4 --- /dev/null +++ b/src/composable/validation.ts @@ -0,0 +1,27 @@ +import { reactive, watch, type Ref } from 'vue'; + +type UseValidationRule = { + validator: (value: T) => boolean + message: string +} + +export function useValidation({ source, rules }: { source: Ref; rules: UseValidationRule[] }) { + 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; +} diff --git a/src/plugins/naive.plugin.ts b/src/plugins/naive.plugin.ts index b04df564..86a46174 100644 --- a/src/plugins/naive.plugin.ts +++ b/src/plugins/naive.plugin.ts @@ -42,9 +42,13 @@ import { NH3, NEllipsis, NTag, + NInputGroup, + NInputGroupLabel, } from 'naive-ui'; const components = [ + NInputGroup, + NInputGroupLabel, NTag, NResult, NEllipsis, diff --git a/src/tools/bip39-generator/bip39-generator.vue b/src/tools/bip39-generator/bip39-generator.vue index 2a363081..a0b564d5 100644 --- a/src/tools/bip39-generator/bip39-generator.vue +++ b/src/tools/bip39-generator/bip39-generator.vue @@ -1,27 +1,45 @@