metaforecast/src/web/utils.ts
2022-04-27 23:51:00 +04:00

31 lines
954 B
TypeScript

export const getBasePath = () => {
if (process.env.NEXT_PUBLIC_VERCEL_URL) {
return `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`;
}
// can be used for local development if you prefer non-default port
if (process.env.NEXT_PUBLIC_SITE_URL) {
return process.env.NEXT_PUBLIC_SITE_URL;
}
return "http://localhost:3000";
};
export const cleanText = (text: string): string => {
// Note: should no longer be necessary
let textString = !!text ? text : "";
textString = textString
.replaceAll("] (", "](")
.replaceAll(") )", "))")
.replaceAll("( [", "([")
.replaceAll(") ,", "),")
.replaceAll("==", "") // Denotes a title in markdown
.replaceAll("Background\n", "")
.replaceAll("Context\n", "")
.replaceAll("--- \n", "- ")
.replaceAll(/\[(.*?)\]\(.*?\)/g, "$1");
textString = textString.slice(0, 1) == "=" ? textString.slice(1) : textString;
//console.log(textString)
return textString;
};