-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.ts
97 lines (84 loc) · 2.62 KB
/
functions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import type { FieldContext } from 'vee-validate';
type InteractionEventGetter = (ctx: FieldContext) => string[];
const passive = () => [];
const lazy: InteractionEventGetter = ({ meta, errorMessage }) => {
return ['change'];
};
const aggressive: InteractionEventGetter = () => ['input'];
const eager: InteractionEventGetter = ({ meta, errorMessage }) => {
if (errorMessage.value) {
return ['input'];
}
return ['change'];
};
export const modes: any = {
passive,
lazy,
aggressive,
eager,
};
export const sliceText = (text: string, number: number) => {
if (text?.length < number) {
return text
} else {
return text?.slice(0, number) + '...'
}
}
export const formatQueryString = (queryObject: Record<string, any>) => {
const filteredQueryObject: Record<string, string | number> = Object.keys(queryObject)
// .filter((key) => key !== "page")
.reduce((obj, key) => {
obj[key] = queryObject[key];
return obj;
}, {} as Record<string, string | number>);
const queryString = Object.keys(filteredQueryObject)
.map((key) => `${key}=${filteredQueryObject[key]}`)
.join("&");
return queryString;
};
export const handleInputTextArea = (event: Event) => {
const target = event.target as HTMLTextAreaElement;
target.style.height = 'auto';
target.style.height = target.scrollHeight + 'px';
};
export const debounce = (func: Function, delay: number) => {
let timer: number;
return (...args: any[]) => {
clearTimeout(timer);
timer = window.setTimeout(() => {
func(...args);
}, delay);
};
};
export const goTo = (link: string, type: string, show: any, router: any) => {
show
if (type === "category") {
setTimeout(() => {
router.push(`/kategoria/${link}`);
}, 54);
} else if (type === "post") {
setTimeout(() => {
router.push(`/post/${link}`);
}, 54);
} else {
setTimeout(() => {
router.push(`/autor/${link}`);
}, 54);
}
};
export const getDate = () => {
const currentDate = new Date();
const day = String(currentDate.getDate()).padStart(2, "0");
const month = String(currentDate.getMonth() + 1).padStart(2, "0"); // Dodajemy 1, ponieważ miesiące są indeksowane od 0
const year = currentDate.getFullYear();
return `${day}.${month}.${year}`;
}
export const bgDynamicColor = (type: string) => {
if (type === "success") {
return "#CEF2D2";
} else if (type === "warning") {
return "#3AA845";
} else {
return "#FFE5E5";
}
}