aboutsummaryrefslogtreecommitdiff
path: root/src/composable
diff options
context:
space:
mode:
Diffstat (limited to 'src/composable')
-rw-r--r--src/composable/computedRefreshable.ts3
-rw-r--r--src/composable/copy.ts2
-rw-r--r--src/composable/downloadBase64.ts4
-rw-r--r--src/composable/fuzzySearch.ts8
-rw-r--r--src/composable/validation.test.ts3
-rw-r--r--src/composable/validation.ts37
6 files changed, 30 insertions, 27 deletions
diff --git a/src/composable/computedRefreshable.ts b/src/composable/computedRefreshable.ts
index 89ab734..8680d06 100644
--- a/src/composable/computedRefreshable.ts
+++ b/src/composable/computedRefreshable.ts
@@ -11,7 +11,8 @@ function computedRefreshable<T>(getter: () => T, { throttle }: { throttle?: numb
if (throttle) {
watchThrottled(getter, update, { throttle });
- } else {
+ }
+ else {
watch(getter, update);
}
diff --git a/src/composable/copy.ts b/src/composable/copy.ts
index af4921b..6c1eca0 100644
--- a/src/composable/copy.ts
+++ b/src/composable/copy.ts
@@ -1,4 +1,4 @@
-import { useClipboard, type MaybeRef, get } from '@vueuse/core';
+import { type MaybeRef, get, useClipboard } from '@vueuse/core';
import { useMessage } from 'naive-ui';
export function useCopy({ source, text = 'Copied to the clipboard' }: { source: MaybeRef<unknown>; text?: string }) {
diff --git a/src/composable/downloadBase64.ts b/src/composable/downloadBase64.ts
index 9348363..3904315 100644
--- a/src/composable/downloadBase64.ts
+++ b/src/composable/downloadBase64.ts
@@ -5,8 +5,8 @@ function getFileExtensionFromBase64({
base64String,
defaultExtension = 'txt',
}: {
- base64String: string;
- defaultExtension?: string;
+ base64String: string
+ defaultExtension?: string
}) {
const hasMimeType = base64String.match(/data:(.*?);base64/i);
diff --git a/src/composable/fuzzySearch.ts b/src/composable/fuzzySearch.ts
index b46f9de..66480f7 100644
--- a/src/composable/fuzzySearch.ts
+++ b/src/composable/fuzzySearch.ts
@@ -1,4 +1,4 @@
-import { get, type MaybeRef } from '@vueuse/core';
+import { type MaybeRef, get } from '@vueuse/core';
import Fuse from 'fuse.js';
import { computed } from 'vue';
@@ -9,9 +9,9 @@ function useFuzzySearch<Data>({
data,
options = {},
}: {
- search: MaybeRef<string>;
- data: Data[];
- options?: Fuse.IFuseOptions<Data>;
+ search: MaybeRef<string>
+ data: Data[]
+ options?: Fuse.IFuseOptions<Data>
}) {
const fuse = new Fuse(data, options);
diff --git a/src/composable/validation.test.ts b/src/composable/validation.test.ts
index 0bcb51f..4464bea 100644
--- a/src/composable/validation.test.ts
+++ b/src/composable/validation.test.ts
@@ -1,4 +1,3 @@
-/* eslint-disable @typescript-eslint/no-empty-function */
import { describe, expect, it } from 'vitest';
import { isFalsyOrHasThrown } from './validation';
@@ -11,7 +10,7 @@ describe('useValidation', () => {
expect(isFalsyOrHasThrown(() => {})).toBe(true);
expect(
isFalsyOrHasThrown(() => {
- throw new Error();
+ throw new Error('message');
}),
).toBe(true);
});
diff --git a/src/composable/validation.ts b/src/composable/validation.ts
index e7fc70c..472ca4b 100644
--- a/src/composable/validation.ts
+++ b/src/composable/validation.ts
@@ -1,45 +1,48 @@
-import { get, type MaybeRef } from '@vueuse/core';
+import { type MaybeRef, get } from '@vueuse/core';
import _ from 'lodash';
-import { reactive, watch, type Ref } from 'vue';
+import { type Ref, reactive, watch } from 'vue';
type ValidatorReturnType = unknown;
export interface UseValidationRule<T> {
- validator: (value: T) => ValidatorReturnType;
- message: string;
+ validator: (value: T) => ValidatorReturnType
+ message: string
}
export function isFalsyOrHasThrown(cb: () => ValidatorReturnType): boolean {
try {
const returnValue = cb();
- if (_.isNil(returnValue)) return true;
+ if (_.isNil(returnValue)) {
+ return true;
+ }
return returnValue === false;
- } catch (_) {
+ }
+ catch (_) {
return true;
}
}
-export type ValidationAttrs = {
- feedback: string;
- validationStatus: string | undefined;
-};
+export interface ValidationAttrs {
+ feedback: string
+ validationStatus: string | undefined
+}
export function useValidation<T>({
source,
rules,
watch: watchRefs = [],
}: {
- source: Ref<T>;
- rules: MaybeRef<UseValidationRule<T>[]>;
- watch?: Ref<unknown>[];
+ source: Ref<T>
+ rules: MaybeRef<UseValidationRule<T>[]>
+ watch?: Ref<unknown>[]
}) {
const state = reactive<{
- message: string;
- status: undefined | 'error';
- isValid: boolean;
- attrs: ValidationAttrs;
+ message: string
+ status: undefined | 'error'
+ isValid: boolean
+ attrs: ValidationAttrs
}>({
message: '',
status: undefined,