anything-llm/frontend/src/utils/directories.js
Timothy Carambat ecf4295537
Add ability to grab youtube transcripts via doc processor (#470)
* Add ability to grab youtube transcripts via doc processor

* dynamic imports
swap out Github for Youtube in placeholder text
2023-12-18 17:17:26 -08:00

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;
}
}