mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-21 06:13:33 +00:00
21 lines
648 B
TypeScript
21 lines
648 B
TypeScript
export const absolutifyLink = (rel: string): string => {
|
|
const anchor = document.createElement("a");
|
|
anchor.setAttribute("href", rel);
|
|
return anchor.href;
|
|
};
|
|
|
|
export const isURL = (str: string): boolean => {
|
|
const urlRegex = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i;
|
|
return urlRegex.test(str);
|
|
};
|
|
|
|
export const generateRandomString = () => {
|
|
const characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
let randomString = "";
|
|
for (let i = 0; i < 6; i++) {
|
|
const randomIndex = Math.floor(Math.random() * characters.length);
|
|
randomString += characters.charAt(randomIndex);
|
|
}
|
|
return randomString;
|
|
};
|