update 16/01
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
|
||||
// Add tất cả sp trong data product vào 1 mảng
|
||||
import { productList } from '@/data/products';
|
||||
|
||||
@@ -5,6 +8,41 @@ export function getAllProducts() {
|
||||
return productList.flatMap((group:any) => group.list);
|
||||
}
|
||||
|
||||
|
||||
export function formatTextList(
|
||||
text?: string | any[],
|
||||
limit = 5
|
||||
) {
|
||||
if (!text) return '';
|
||||
|
||||
if (typeof window === 'undefined') {
|
||||
// server: trả raw HTML
|
||||
return Array.isArray(text)
|
||||
? String(text[1] ?? '')
|
||||
: String(text);
|
||||
}
|
||||
|
||||
const html = Array.isArray(text)
|
||||
? String(text[1] ?? '')
|
||||
: String(text);
|
||||
|
||||
if (!html) return '';
|
||||
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, 'text/html');
|
||||
|
||||
const nodes = Array.from(
|
||||
doc.body.querySelectorAll('p, div, li')
|
||||
);
|
||||
|
||||
return nodes
|
||||
.slice(0, limit)
|
||||
.map(node => `<div class="item">${node.innerHTML}</div>`)
|
||||
.join('');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Format giá
|
||||
export function formatPrice(amount: number) {
|
||||
return amount.toLocaleString('vi-VN');
|
||||
|
||||
Reference in New Issue
Block a user