import dayjs from 'dayjs' export const getTime = (str) => { let time = dayjs() const arr = str.split(':') if (arr.length < 3) { arr.push('00') } arr.forEach((el, i) => i === 0 ? (time = time.hour(el)) : (i === 1 ? ( time = time.minute(el)) : (time = time.second(el)))) return time } export const getRestTime = (time) => { let hour = 0, minute = 0, second = 0 if (time) { const endTime = getTime(time) const now = dayjs() hour = endTime.diff(now, 'hour') minute = endTime.diff(now, 'minute') - hour * 60 second = endTime.diff(now, 'second') - hour * 60 * 60 - minute * 60 } return [hour, minute, second] } export function parseURL(url) { const regex = /^(https?):\/\/([^:/?]+)(?::(\d+))?([^?#]+)?(\?[^#]+)?(#.+)?$/; const match = url.match(regex); if (!match) return null; const [, protocol, host, port, path, query, fragment] = match; let params = {} if (query) { const arr = query.slice(1).split('&') arr.forEach(el => { const _ = el.split('=') params[_[0]] = _[1] }) } return { protocol: protocol, host: host, port: port ? parseInt(port) : null, path: path || null, query: query ? query.slice(1) : null, fragment: fragment ? fragment.slice(1) : null, params }; }