2020-12-01 16:27:19 +00:00
|
|
|
import { html, TemplateResult } from "lit-html";
|
2020-12-02 21:14:28 +00:00
|
|
|
import { SpinnerSize } from "./elements/Spinner";
|
2020-12-01 16:27:19 +00:00
|
|
|
|
2021-01-16 18:09:03 +00:00
|
|
|
export function getCookie(name: string): string {
|
|
|
|
let cookieValue = "";
|
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
|
|
|
}
|
2020-11-30 11:33:09 +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;
|
|
|
|
}
|
2020-12-01 16:27:19 +00:00
|
|
|
|
|
|
|
export function htmlFromString(...strings: string[]): TemplateResult {
|
2020-12-06 17:40:25 +00:00
|
|
|
return html(<TemplateStringsArray><unknown>strings);
|
2020-12-01 16:27:19 +00:00
|
|
|
}
|
2020-12-02 21:14:28 +00:00
|
|
|
|
|
|
|
export function loading<T>(v: T, actual: TemplateResult): TemplateResult {
|
|
|
|
if (!v) {
|
|
|
|
return html`<div class="pf-c-empty-state pf-m-full-height">
|
|
|
|
<div class="pf-c-empty-state__content">
|
|
|
|
<div class="pf-l-bullseye">
|
|
|
|
<div class="pf-l-bullseye__item">
|
2020-12-12 19:46:02 +00:00
|
|
|
<ak-spinner size="${SpinnerSize.XLarge}"></ak-spinner>
|
2020-12-02 21:14:28 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
return actual;
|
|
|
|
}
|
2020-12-28 12:07:49 +00:00
|
|
|
|
|
|
|
export function time(t: string): Date {
|
|
|
|
return new Date(parseInt(t, 10) * 1000);
|
|
|
|
}
|