| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| function formatDate(date, format) { |
| if (!date) return ''; |
|
|
| |
| const dateObj = typeof date === 'string' ? new Date(date) : date; |
|
|
| if (!(dateObj instanceof Date) || isNaN(dateObj)) { |
| return ''; |
| } |
|
|
| |
| const year = dateObj.getFullYear(); |
| const month = dateObj.getMonth() + 1; |
| const day = dateObj.getDate(); |
| const hours = dateObj.getHours(); |
| const minutes = dateObj.getMinutes(); |
| const seconds = dateObj.getSeconds(); |
|
|
| |
| if (!format) format = 'YYYY-MM-DD'; |
|
|
| return format |
| .replace('YYYY', year) |
| .replace('MM', month.toString().padStart(2, '0')) |
| .replace('DD', day.toString().padStart(2, '0')) |
| .replace('HH', hours.toString().padStart(2, '0')) |
| .replace('mm', minutes.toString().padStart(2, '0')) |
| .replace('ss', seconds.toString().padStart(2, '0')); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| function limit(text, length) { |
| if (!text) return ''; |
|
|
| text = String(text); |
|
|
| if (text.length <= length) { |
| return text; |
| } |
|
|
| return text.substring(0, length) + '...'; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| function toLowerCase(text) { |
| if (!text) return ''; |
| return String(text).toLowerCase(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| function toUpperCase(text) { |
| if (!text) return ''; |
| return String(text).toUpperCase(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| function json(obj) { |
| return JSON.stringify(obj, null, 2); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| function extractDomain(url) { |
| if (!url) return ''; |
|
|
| try { |
| |
| let domain = String(url).replace(/^[a-zA-Z]+:\/\//, ''); |
|
|
| |
| domain = domain.split('/')[0].split('?')[0].split('#')[0]; |
|
|
| |
| domain = domain.split(':')[0]; |
|
|
| return domain; |
| } catch (e) { |
| return String(url); |
| } |
| } |
|
|
| |
| module.exports = { |
| formatDate, |
| limit, |
| toLowerCase, |
| toUpperCase, |
| json, |
| extractDomain, |
| }; |
|
|