All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ducks.datasource.Providers.storage.applyPaging.ts Maven / Gradle / Ivy

The newest version!
import { Paging } from '../../Provider'

export type PagingInfo = {
    page: number
    size: number
}

export function applyPaging(
    list: TData[],
    { page, size }: PagingInfo,
): { list: TData[], paging: Pick } {
    if (list.length <= size) {
        return { list, paging: { page: 1 } }
    }

    let newPage = page

    if (list.length < (page - 1) * size) {
        newPage = Math.floor(list.length / size) + 1
    }

    return {
        list: list.slice((newPage - 1) * size, newPage * size),
        paging: { page: newPage },
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy