mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-15 10:50:31 +01:00
ecf4295537
* Add ability to grab youtube transcripts via doc processor * dynamic imports swap out Github for Youtube in placeholder text
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
export function formatDate(dateString) {
|
|
const date = isNaN(new Date(dateString).getTime())
|
|
? new Date()
|
|
: new Date(dateString);
|
|
const options = { year: "numeric", month: "short", day: "numeric" };
|
|
const formattedDate = date.toLocaleDateString("en-US", options);
|
|
return formattedDate;
|
|
}
|
|
|
|
export function getFileExtension(path) {
|
|
return path?.split(".")?.slice(-1)?.[0] || "file";
|
|
}
|
|
|
|
export function middleTruncate(str, n) {
|
|
const fileExtensionPattern = /([^.]*)$/;
|
|
const extensionMatch = str.includes(".") && str.match(fileExtensionPattern);
|
|
|
|
if (str.length <= n) return str;
|
|
|
|
if (extensionMatch && extensionMatch[1]) {
|
|
const extension = extensionMatch[1];
|
|
const nameWithoutExtension = str.replace(fileExtensionPattern, "");
|
|
const truncationPoint = Math.max(0, n - extension.length - 4);
|
|
const truncatedName =
|
|
nameWithoutExtension.substr(0, truncationPoint) +
|
|
"..." +
|
|
nameWithoutExtension.slice(-4);
|
|
|
|
return truncatedName + extension;
|
|
} else {
|
|
return str.length > n ? str.substr(0, n - 8) + "..." + str.slice(-4) : str;
|
|
}
|
|
}
|