From 66c1f302310af620050bc5254a90076d6f25adea Mon Sep 17 00:00:00 2001 From: zM_ Date: Tue, 12 Oct 2021 22:39:54 +0200 Subject: [PATCH] add types definition --- public/index.html | 4 +- src/components/AutoDecoder.vue | 40 ++++--- src/components/DropdownSetting.vue | 177 ++++++++++++++++++++++++----- src/components/TextSetting.vue | 10 +- src/encoders/ascii.ts | 20 ++-- src/encoders/base64.ts | 86 +++++++------- src/encoders/decimal.ts | 40 ++++--- src/encoders/hex.ts | 29 ++--- src/encoders/info.ts | 31 ++--- src/encoders/url.ts | 20 ++-- src/encoders/xor.ts | 35 +++--- src/main.ts | 9 +- src/scss/_variables.scss | 1 + src/types/Encoder.ts | 43 +++++++ src/types/GenericSetting.ts | 25 ++++ src/types/MultichoiceSetting.ts | 29 +++++ src/types/Setting.ts | 15 +++ 17 files changed, 442 insertions(+), 172 deletions(-) create mode 100644 src/types/Encoder.ts create mode 100644 src/types/GenericSetting.ts create mode 100644 src/types/MultichoiceSetting.ts create mode 100644 src/types/Setting.ts diff --git a/public/index.html b/public/index.html index 3e5a139..ba0af67 100644 --- a/public/index.html +++ b/public/index.html @@ -5,11 +5,11 @@ - <%= htmlWebpackPlugin.options.title %> + Decodapz
diff --git a/src/components/AutoDecoder.vue b/src/components/AutoDecoder.vue index 01bd9d0..6a8992e 100644 --- a/src/components/AutoDecoder.vue +++ b/src/components/AutoDecoder.vue @@ -14,9 +14,9 @@ - - - + @@ -29,18 +29,6 @@ import TextSetting from './TextSetting.vue' import DropdownSetting from './DropdownSetting.vue' import CheckboxSetting from './CheckboxSetting.vue' -function pick(obj, predicate) { - if (!obj || typeof obj !== 'object') return obj - - const newObj = {} - - for (const [name, value] of Object.entries(obj)) { - if (!predicate(name, value)) continue - newObj[name] = value - } - return newObj -} - export default { name: 'AutoDecoder', components: { @@ -60,13 +48,12 @@ export default { }, data() { const encoder = this.getEncoder(this.type) - Promise.resolve(encoder.encode(this.value)).then((value) => { this.encodedValue = value }) return { - encoder: encoder, + encoder, encodedValue: '', hasError: false, isFocused: false @@ -90,6 +77,17 @@ export default { } }, methods: { + pick(obj, predicate) { + if (!obj || typeof obj !== 'object') return obj + + const newObj = {} + + for (const [name, value] of Object.entries(obj)) { + if (!predicate(name, value)) continue + newObj[name] = value + } + return newObj + }, async decode(string) { return await this.decodeValue(this.type.toLowerCase(), string) }, @@ -118,13 +116,13 @@ export default { }, computed: { stringSettings() { - return pick(this.encoder.settings, (name, setting) => setting.type === String) + return this.encoder.stringSettings }, booleanSettings() { - return pick(this.encoder.settings, (name, setting) => setting.type === Boolean) + return this.encoder.booleanSettings }, - complexSettings() { - return pick(this.encoder.settings, (name, setting) => setting.type === Object) + objectSettings() { + return this.encoder.objectSettings } }, mounted() { diff --git a/src/components/DropdownSetting.vue b/src/components/DropdownSetting.vue index aca31b6..9b6cb39 100644 --- a/src/components/DropdownSetting.vue +++ b/src/components/DropdownSetting.vue @@ -1,15 +1,39 @@ @@ -24,19 +100,14 @@ export default {