import * as React from 'react'; export function formatDescription(description?: string) { if (!description) return ''; return description.replace(/<[^>]*>/g, '').trim(); } export function formatVideoDuration(duration: number) { return `${paddingNumber(Math.floor(duration / 60))}:${paddingNumber(duration % 60)}`; } export function paddingNumber(num: number, length: number = 2) { const numToStr = num.toString(); if (numToStr.length >= length) return numToStr; const paddingArr = new Array(length - numToStr.length); paddingArr.fill('0'); return [...paddingArr, numToStr].join(''); } export function isEventFromLink( event: React.MouseEvent ) { let target = event.target as HTMLElement; const currentTarget = event.currentTarget; let isFromLink = false; while ( currentTarget !== target ) { if (target.tagName === 'a') { isFromLink = true; break; } target = target.parentElement; } return isFromLink; } export const lengthFormat = (text: string) => { if (text.length >= 22) { return `${text.slice(0, 22)}...` } else { return text } }