Files
lucent-laravel/front/js/helpers.js
T

33 lines
726 B
JavaScript
Raw Permalink Normal View History

2024-01-11 18:58:04 +02:00
import {formatDistanceToNow, parseJSON, format, parse} from "date-fns";
2023-10-02 23:10:49 +03:00
export function friendlyDate(date) {
return formatDistanceToNow(parseJSON(date), {addSuffix: true});
}
2023-10-23 22:12:17 +03:00
export function readableDate(date) {
2024-01-11 18:58:04 +02:00
if(!date){
return "";
}
2023-10-23 22:12:17 +03:00
return format(parseJSON(date), "dd MMM yyyy");
}
export function readableDatetime(date) {
2024-01-11 18:58:04 +02:00
if(!date){
return "";
}
2023-10-23 22:12:17 +03:00
return format(parseJSON(date), "dd MMM yyyy HH:mm");
}
2023-10-02 23:10:49 +03:00
export function stripHtml(html = "") {
let tmp = document.createElement("div");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}
export function randomId(length = 10) {
return Math.random().toString(36).substring(2, length + 2);
}