Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
headless-pagination
Advanced tools
$ npm i -S headless-pagination
constructor
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 1000, // required
initialPage: 1, // optional (default shown), page to show at start
perPage: 24, // optional (default shown), how many items you're showing per page
maxLinks: 7, // optional (default shown), max number of pagination links to show
});
totalPages()
Returns the total number of pages, takes into account a final page without necessarily having max items.
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 100,
perPage: 24,
});
// would be 5 because 100 / 24 = 4.166...
console.log(paginator.totalPages());
hasNext()
Whether or not there is a next page to navigate to. Useful for displaying/disabling arrow based navigation.
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 100,
initialPage: 1,
});
// true
console.log(paginator.hasNext());
hasPrevious()
Whether or not there is a previous page to navigate to. Useful for displaying/disabling arrow based navigation.
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 100,
initialPage: 1,
});
// false, we're on page 1
console.log(paginator.hasPrevious());
from()
Starting item we're currently displaying based on page offset. Useful for showing a message like Showing 24 to 50 results of 100
.
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 100,
initialPage: 2,
perPage: 25,
});
// 26
console.log(paginator.from());
from()
Ending item we're currently displaying based on page offset. Useful for showing a message like Showing 24 to 50 results of 100
.
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 100,
initialPage: 2,
perPage: 25,
});
// 50
console.log(paginator.to());
onNext()
Increments the active page. Will not go further than the max page.
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 50,
initialPage: 1,
perPage: 25,
});
paginator.onNext();
// 2
console.log(paginator.page);
paginator.onNext();
// 2 - doesn't go up past final page
console.log(paginator.page);
onPrevious()
Decrements the active page. Will not go lower than the first page.
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 50,
initialPage: 1,
perPage: 25,
});
// 1
console.log(paginator.page);
paginator.onPrevious();
// 1
console.log(paginator.page);
setPage(newPage: number)
Updates the page to the provided value
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 50,
initialPage: 1,
perPage: 25,
});
// 1
console.log(paginator.page);
paginator.setPage(2);
// 2
console.log(paginator.page);
links()
Returns an array of what links to display to the user.
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 100,
initialPage: 1,
maxLinks: 7,
perPage: 10,
});
// notice how there are only 7 links!
expect(paginator.links()).toEqual([
{ label: 1, active: true, disabled: false },
{ label: 2, active: false, disabled: false },
{ label: 3, active: false, disabled: false },
{ label: 4, active: false, disabled: false },
{ label: 5, active: false, disabled: false },
{ label: '...', active: false, disabled: true },
{ label: 10, active: false, disabled: false },
]);
As you navigate through the pages, the structure of the links may change by introducing multiple ...
items in order to respect the maxLinks
config:
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 100,
initialPage: 1,
maxLinks: 7,
perPage: 10,
});
paginator.setPage(5);
expect(paginator.links()).toEqual([
{ label: 1, active: false, disabled: false },
{ label: '...', active: false, disabled: true },
{ label: 4, active: false, disabled: false },
{ label: 5, active: true, disabled: false },
{ label: 6, active: false, disabled: false },
{ label: '...', active: false, disabled: true },
{ label: 10, active: false, disabled: false },
]);
And finally as you get closer to the last page, the links will expand out on the right:
import Paginator from 'headless-pagination';
const paginator = new Paginator({
totalItems: 100,
initialPage: 1,
maxLinks: 7,
perPage: 10,
});
paginator.setPage(8);
expect(paginator.links()).toEqual([
{ label: 1, active: false, disabled: false },
{ label: '...', active: false, disabled: true },
{ label: 6, active: false, disabled: false },
{ label: 7, active: false, disabled: false },
{ label: 8, active: true, disabled: false },
{ label: 9, active: false, disabled: false },
{ label: 10, active: false, disabled: false },
]);
FAQs
Vanilla JS headless pagination library
The npm package headless-pagination receives a total of 163 weekly downloads. As such, headless-pagination popularity was classified as not popular.
We found that headless-pagination demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.