This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/web/src/utils.ts

31 lines
973 B
TypeScript
Raw Normal View History

export function getCookie(name: string) {
2020-10-16 12:10:27 +00:00
let cookieValue = null;
2020-11-21 19:48:49 +00:00
if (document.cookie && document.cookie !== "") {
const cookies = document.cookie.split(";");
2020-10-16 12:10:27 +00:00
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
2020-11-21 19:48:49 +00:00
if (cookie.substring(0, name.length + 1) === name + "=") {
2020-11-26 22:35:59 +00:00
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
2020-10-16 12:10:27 +00:00
break;
}
}
}
return cookieValue;
}
2020-11-21 18:22:53 +00:00
export function convertToSlug(text: string): string {
return text
.toLowerCase()
2020-11-21 19:48:49 +00:00
.replace(/ /g, "-")
.replace(/[^\w-]+/g, "");
2020-11-21 18:22:53 +00:00
}
export function truncate(input?: string, max = 10): string {
input = input || "";
const array = input.trim().split(" ");
const ellipsis = array.length > max ? "..." : "";
return array.slice(0, max).join(" ") + ellipsis;
}