@majapisoftwares/ui 4.3.14 → 4.3.16
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/utils/getInitials.d.ts
CHANGED
package/utils/getInitials.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Gets all the initials of a name.
|
|
3
3
|
*/
|
|
4
|
-
export default function getInitials(name
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export default function getInitials(name) {
|
|
5
|
+
if (!name)
|
|
6
|
+
return "";
|
|
7
|
+
// Normalize to decompose diacritics, then remove any non-letter characters.
|
|
8
|
+
const normalizeAndClean = (s) => s
|
|
9
|
+
.normalize("NFD") // decompose combined letters (e.g., é -> e + ´)
|
|
10
|
+
.replace(/\p{M}/gu, "") // remove diacritic marks
|
|
11
|
+
.replace(/[^A-Za-zÀ-ÖØ-öø-ÿ]/g, "") // strip anything that's not a letter (basic Latin + Latin-1 Supplement)
|
|
12
|
+
.trim();
|
|
13
|
+
// Split into words, clean each word, take first letter of up to two words.
|
|
14
|
+
const words = name.split(/\s+/);
|
|
15
|
+
const initials = words
|
|
16
|
+
.map((w) => normalizeAndClean(w))
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
.slice(0, 2)
|
|
19
|
+
.map((w) => w.charAt(0).toUpperCase())
|
|
20
|
+
.join("");
|
|
21
|
+
return initials;
|
|
8
22
|
}
|
package/utils/formatTime.d.ts
DELETED
package/utils/formatTime.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export default function formatTime(time) {
|
|
2
|
-
const totalSeconds = Math.floor(time / 1000);
|
|
3
|
-
const hours = Math.floor(totalSeconds / 3600);
|
|
4
|
-
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
|
5
|
-
const remainingSeconds = totalSeconds % 60;
|
|
6
|
-
let formattedTime = "";
|
|
7
|
-
if (hours > 0) {
|
|
8
|
-
formattedTime += `${hours}h `;
|
|
9
|
-
}
|
|
10
|
-
if (minutes > 0) {
|
|
11
|
-
formattedTime += `${minutes}m `;
|
|
12
|
-
}
|
|
13
|
-
if (remainingSeconds > 0) {
|
|
14
|
-
formattedTime += `${remainingSeconds}s`;
|
|
15
|
-
}
|
|
16
|
-
return formattedTime.trim();
|
|
17
|
-
}
|
|
18
|
-
export function parseFormattedTime(formattedTime) {
|
|
19
|
-
if (!formattedTime) {
|
|
20
|
-
return 0;
|
|
21
|
-
}
|
|
22
|
-
const timeParts = formattedTime.split(" ");
|
|
23
|
-
let totalMilliseconds = 0;
|
|
24
|
-
timeParts.forEach((part) => {
|
|
25
|
-
const unit = part.slice(-1); // Get the last character (h, m, or s)
|
|
26
|
-
const value = parseFloat(part.slice(0, -1)); // Get the numeric value
|
|
27
|
-
if (!isNaN(value)) {
|
|
28
|
-
if (unit === "h") {
|
|
29
|
-
totalMilliseconds += value * 3600000; // Convert hours to milliseconds
|
|
30
|
-
}
|
|
31
|
-
else if (unit === "m") {
|
|
32
|
-
totalMilliseconds += value * 60000; // Convert minutes to milliseconds
|
|
33
|
-
}
|
|
34
|
-
else if (unit === "s") {
|
|
35
|
-
totalMilliseconds += value * 1000; // Convert seconds to milliseconds
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return totalMilliseconds;
|
|
40
|
-
}
|