link-header-pagination
v0.1.0
Published
Generate LinkHeader pagination
Downloads
3
Maintainers
Readme
link-header-pagination
Generate LinkHeader pagination
Setup
npm install link-header-pagination
Usage
import linkHeaderPagination from 'link-header-pagination';
const headers = linkHeaderPagination({ page: 1, perPage: 20, total: 100 });
/*
{
Link: '</?page=1>; rel="current", </?page=2>; rel="next", </?page=5>; rel="last"',
'X-Items-From': '1',
'X-Items-Per-Page': '20',
'X-Items-To': '20',
'X-Items-Total': '100'
}
*/
API
linkHeader(options: LinkHeaderPaginationOptions): Record<string, string>
interface LinkHeaderLinks {
rel: string;
url: string;
}
interface LinkHeaderPaginationOptions {
links?: LinkHeaderLinks[];
page: number;
perPage: number;
total: number;
}
Show your support
Give a ⭐️ if this project helped you!
License
Copyright © 2022 Gil Barbara [email protected].
This project is MIT licensed.