import {formatDistanceToNow, parseJSON, format, parse} from "date-fns";

export function friendlyDate(date) {
    return formatDistanceToNow(parseJSON(date), {addSuffix: true});
}

export function readableDate(date) {
    if(!date){
        return "";
    }
    return format(parseJSON(date), "dd MMM yyyy");
}

export function readableDatetime(date) {
    if(!date){
        return "";
    }

    return format(parseJSON(date), "dd MMM yyyy HH:mm");
}


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);
}
