mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-25 17:26:15 -04:00
chore(lint): switched to a better lint config
This commit is contained in:
parent
4d2b037dbe
commit
33c9b6643f
178 changed files with 4105 additions and 3371 deletions
|
@ -11,7 +11,8 @@ function computedRefreshable<T>(getter: () => T, { throttle }: { throttle?: numb
|
|||
|
||||
if (throttle) {
|
||||
watchThrottled(getter, update, { throttle });
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
watch(getter, update);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 }) {
|
||||
|
|
|
@ -5,8 +5,8 @@ function getFileExtensionFromBase64({
|
|||
base64String,
|
||||
defaultExtension = 'txt',
|
||||
}: {
|
||||
base64String: string;
|
||||
defaultExtension?: string;
|
||||
base64String: string
|
||||
defaultExtension?: string
|
||||
}) {
|
||||
const hasMimeType = base64String.match(/data:(.*?);base64/i);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue