function usePagination( current: number, total: number, voidFormat: string | undefined | null = null, ) { let center: number[] = [] // Initialize center as an empty array if (total < 6) { return new Array(total).fill(total).map((_v, i) => i + 1) } if (current > 2 && current < total - 1) { center = [current - 1, current, current + 1] } else if (current === 2) { center = [current, current + 1] } else if (current === 1) { center = [current + 1, current + 2] } else if (current === total - 1) { center = [current - 1, current] } else if (current === total) { center = [current - 2, current - 1] } const arr = [1, ...center, total] if (arr.length < 2) { return arr // If the array has fewer than 2 elements, no changes are needed } const result = [arr[0]] // Start with the first element for (let i = 1; i < arr.length; i++) { if (arr[i] !== arr[i - 1] + 1) { // @ts-expect-error Argument of type 'string | null' is not assignable to parameter of type 'number'.Type 'null' is not assignable to type 'number'.ts(2345) result.push(voidFormat) // Add dots if the current number is not consecutive } result.push(arr[i]) // Add the current number } return result } export default usePagination