@econneq/utility-functions 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/utilsGeneral.d.ts +1 -5
- package/dist/utilsGeneral.d.ts.map +1 -1
- package/dist/utilsGeneral.js +0 -39
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,35 +7,6 @@ export type SelectOptions = string | {
|
|
|
7
7
|
label: string;
|
|
8
8
|
value: string | number;
|
|
9
9
|
};
|
|
10
|
-
export interface InterLoginData {
|
|
11
|
-
username: string;
|
|
12
|
-
password: string;
|
|
13
|
-
parent?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export interface JwtPayload {
|
|
16
|
-
iss?: string;
|
|
17
|
-
sub?: string;
|
|
18
|
-
aud?: string[] | string;
|
|
19
|
-
exp: number;
|
|
20
|
-
nbf?: number;
|
|
21
|
-
iat?: number;
|
|
22
|
-
jti?: string;
|
|
23
|
-
user_id?: number;
|
|
24
|
-
username?: string;
|
|
25
|
-
matricle?: string;
|
|
26
|
-
photo?: string;
|
|
27
|
-
is_superuser?: boolean;
|
|
28
|
-
is_staff?: boolean;
|
|
29
|
-
is_active?: boolean;
|
|
30
|
-
is_hod?: boolean;
|
|
31
|
-
role?: string;
|
|
32
|
-
dept?: string[] | any;
|
|
33
|
-
page?: string[] | any;
|
|
34
|
-
school?: number[] | any;
|
|
35
|
-
domain?: number[] | any;
|
|
36
|
-
language?: string[];
|
|
37
|
-
last_login?: any;
|
|
38
|
-
}
|
|
39
10
|
export interface InterField {
|
|
40
11
|
name: string;
|
|
41
12
|
label: string;
|
|
@@ -62,6 +33,6 @@ export interface InterFieldList {
|
|
|
62
33
|
mobileCols: 1 | 2;
|
|
63
34
|
fields: InterField[];
|
|
64
35
|
}
|
|
65
|
-
export { capitalizeEachWord, errorLog,
|
|
36
|
+
export { capitalizeEachWord, errorLog, getStoredFont, getTimeAgo, getLanguage, getTemplate, decodeUrlID, Alert, validateFormFields, lastYears, formatText, } from './utilsGeneral.js';
|
|
66
37
|
export { getProfile, getClass, getClassName, getLevel, getAcademicYear, getAcademicYearStudent } from './utilsSchool.js';
|
|
67
38
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAA;AAG9E,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,eAAe,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;IAChH,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;IACxF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACtD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,WAAW,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;IAClB,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,OAAO,EACL,kBAAkB,EAAE,QAAQ,EAC5B,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EACnD,WAAW,EACX,KAAK,EAAE,kBAAkB,EAAE,SAAS,EAAE,UAAU,GACjD,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,UAAU,EAAE,QAAQ,EAAE,YAAY,EAClC,QAAQ,EAAE,eAAe,EAAE,sBAAsB,EAClD,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { capitalizeEachWord, errorLog,
|
|
1
|
+
export { capitalizeEachWord, errorLog, getStoredFont, getTimeAgo, getLanguage, getTemplate, decodeUrlID, Alert, validateFormFields, lastYears, formatText, } from './utilsGeneral.js';
|
|
2
2
|
export { getProfile, getClass, getClassName, getLevel, getAcademicYear, getAcademicYearStudent } from './utilsSchool.js';
|
package/dist/utilsGeneral.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { InterFieldList
|
|
1
|
+
import { InterFieldList } from ".";
|
|
2
2
|
export declare const capitalizeEachWord: (str: string) => string;
|
|
3
3
|
export declare const errorLog: (err: any, show?: boolean) => string;
|
|
4
|
-
export declare const logout: () => void;
|
|
5
|
-
export declare const getToken: () => string | null;
|
|
6
|
-
export declare const getUser: () => JwtPayload | null;
|
|
7
4
|
export declare const getStoredFont: (FONTS: string[]) => string;
|
|
8
5
|
export declare const getTimeAgo: (dateStr: string, type: "past" | "future") => string;
|
|
9
6
|
export declare const getLanguage: () => "en" | "fr";
|
|
10
7
|
export declare const getTemplate: () => number;
|
|
11
8
|
export declare const decodeUrlID: (urlID: string) => string;
|
|
12
|
-
export declare const removeEmptyFields: (obj: any) => any;
|
|
13
9
|
export declare const Alert: ({ title, duration, status }: {
|
|
14
10
|
title: string;
|
|
15
11
|
duration: 1000 | 1500 | 2000 | 3000 | 4000 | 5000;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilsGeneral.d.ts","sourceRoot":"","sources":["../src/utilsGeneral.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utilsGeneral.d.ts","sourceRoot":"","sources":["../src/utilsGeneral.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,CAAC;AAKnC,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,WAM7C,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,KAAK,GAAG,EAAE,OAAO,OAAO,WAyBhD,CAAC;AAGF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,WAO5C,CAAC;AAEF,eAAO,MAAM,UAAU,GACnB,SAAS,MAAM,EACf,MAAM,MAAM,GAAG,QAAQ,KACxB,MA0CF,CAAC;AAEF,eAAO,MAAM,WAAW,mBAOvB,CAAC;AAEF,eAAO,MAAM,WAAW,cAMvB,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,WAIxC,CAAA;AAED,eAAO,MAAM,KAAK,GACd,6BACI;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,SAU7F,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,UAAU,GAAG,EAAE,mBAAmB,cAAc,EAAE,2BAkDpF,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM;;;GAKvC,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,WAiDtC,CAAC"}
|
package/dist/utilsGeneral.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import Swal from "sweetalert2";
|
|
2
|
-
import Cookies from "js-cookie";
|
|
3
|
-
import { jwtDecode } from "jwt-decode";
|
|
4
2
|
const currentYear = new Date().getFullYear();
|
|
5
3
|
export const capitalizeEachWord = (str) => {
|
|
6
4
|
if (!str)
|
|
@@ -38,32 +36,6 @@ export const errorLog = (err, show) => {
|
|
|
38
36
|
}
|
|
39
37
|
return mes;
|
|
40
38
|
};
|
|
41
|
-
export const logout = () => {
|
|
42
|
-
// 1. Clear Local Storage
|
|
43
|
-
localStorage.removeItem("token");
|
|
44
|
-
const tokenDeleteString = "token=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;";
|
|
45
|
-
document.cookie = tokenDeleteString;
|
|
46
|
-
// 3. Fallback: Clear ALL cookies (your original loop)
|
|
47
|
-
const cookies = document.cookie.split(";");
|
|
48
|
-
for (let i = 0; i < cookies.length; i++) {
|
|
49
|
-
const cookie = cookies[i];
|
|
50
|
-
const eqPos = cookie.indexOf("=");
|
|
51
|
-
const name = eqPos > -1 ? cookie.substr(0, eqPos).trim() : cookie.trim();
|
|
52
|
-
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;`;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
export const getToken = () => {
|
|
56
|
-
if (typeof window === "undefined") {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
return Cookies.get("token") || localStorage.getItem("token");
|
|
60
|
-
};
|
|
61
|
-
export const getUser = () => {
|
|
62
|
-
// const token = typeof window !== 'undefined' ? localStorage.getItem("token") : null;
|
|
63
|
-
const token = getToken();
|
|
64
|
-
const user = token ? jwtDecode(token) : null;
|
|
65
|
-
return user;
|
|
66
|
-
};
|
|
67
39
|
export const getStoredFont = (FONTS) => {
|
|
68
40
|
if (typeof window === "undefined")
|
|
69
41
|
return FONTS[0]; // Default for SSR
|
|
@@ -144,17 +116,6 @@ export const decodeUrlID = (urlID) => {
|
|
|
144
116
|
const id = Buffer.from(base64DecodedString, 'base64').toString('utf-8'); // Decoding from base64
|
|
145
117
|
return id.split(":")[1];
|
|
146
118
|
};
|
|
147
|
-
export const removeEmptyFields = (obj) => {
|
|
148
|
-
const newObj = {};
|
|
149
|
-
for (const key in obj) {
|
|
150
|
-
// Keep File objects and non-empty values
|
|
151
|
-
if (obj[key] instanceof File ||
|
|
152
|
-
(obj[key] !== null && obj[key] !== undefined && obj[key] !== '')) {
|
|
153
|
-
newObj[key] = obj[key];
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return newObj;
|
|
157
|
-
};
|
|
158
119
|
export const Alert = ({ title, duration, status = true }) => {
|
|
159
120
|
Swal.fire({
|
|
160
121
|
title: capitalizeEachWord(title),
|