30 lines
790 B
TypeScript
30 lines
790 B
TypeScript
export function formatDate(date: Date): string {
|
|
const options = { year: "numeric", month: "long", day: "numeric" } as const;
|
|
return new Intl.DateTimeFormat("en-US", options).format(date);
|
|
}
|
|
|
|
export function safeFileName(inputString: string): string {
|
|
// Convert the string to lowercase
|
|
let fileName = inputString.toLowerCase();
|
|
|
|
// Replace spaces with underscores
|
|
fileName = fileName.replace(/ /g, "_");
|
|
|
|
// Remove characters that are not safe for file names
|
|
fileName = fileName.replace(/[^\w.-]/g, "");
|
|
|
|
return fileName;
|
|
}
|
|
|
|
export function extractHashTags(inputString: string) {
|
|
const hashtags = [];
|
|
|
|
for (
|
|
const [hashtag] of inputString.matchAll(/(?<!\()\B(\#[a-zA-Z\-]+\b)(?!;)/g)
|
|
) {
|
|
hashtags.push(hashtag.replace(/\#/g, ""));
|
|
}
|
|
|
|
return hashtags;
|
|
}
|