New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bramus/pagination-sequence

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bramus/pagination-sequence - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

2

dist/index.js

@@ -1,2 +0,2 @@

var c=(f,i,l=1)=>Array.from({length:(i-f)/l+1},(e,h)=>f+h*l);var I=(f,i,l=2,e=2,h="\u2026")=>{let M=1+e*2+l*2+2,o=Math.min(f,i),p=[];if(i<=M)p=c(1,i);else{let q=l>0?1:o,t={leftEdge:null,glueLeftCenter:null,centerPiece:null,glueCenterRight:null,rightEdge:null};o<M/2?(t.leftEdge=c(1,Math.ceil(M/2)+e),t.centerPiece=[h],l>0&&(t.rightEdge=c(i-(l-1),i))):o>i-M/2?(l>0&&(t.leftEdge=c(q,l)),t.centerPiece=[h],t.rightEdge=c(Math.min(i-Math.floor(M/2)-e,o-e),i)):(t.centerPiece=c(o-e,o+e),l>0&&(t.leftEdge=c(q,l)),l>0&&(t.rightEdge=c(i-(l-1),i)),t.glueLeftCenter=t.centerPiece[0]==l+2?[l+1]:[h],t.glueCenterRight=[h]),p=Object.values(t).filter(r=>r!==null).flat()}return p};export{I as generate};
var i=(o,t,e=1)=>Array.from({length:(t-o)/e+1},(c,f)=>o+f*e);var I=(o,t,e=2,c=2,f="\u2026")=>{let h=1+c*2+e*2+2,r=Math.min(o,t),M=[];if(t<=h)M=i(1,t);else{let p=e>0?1:r,l={leftEdge:null,glueLeftCenter:null,centerPiece:null,glueCenterRight:null,rightEdge:null};r<h/2?(l.leftEdge=i(1,Math.ceil(h/2)+c),l.centerPiece=[f],e>0&&(l.rightEdge=i(t-(e-1),t))):r>t-h/2?(e>0&&(l.leftEdge=i(p,e)),l.centerPiece=[f],l.rightEdge=i(Math.min(t-Math.floor(h/2)-c,r-c),t)):(l.centerPiece=i(r-c,r+c),e>0&&(l.leftEdge=i(p,e)),e>0&&(l.rightEdge=i(t-(e-1),t)),l.glueLeftCenter=l.centerPiece[0]==e+2?[e+1]:[f],l.glueCenterRight=[f]),M=Object.values(l).filter(q=>q!==null).flat()}return M};export{I as generate};
//# sourceMappingURL=index.js.map
{
"name": "@bramus/pagination-sequence",
"version": "1.0.4",
"version": "1.1.0",
"description": "Generate a sequence of numbers for use in a Pagination Component, the clever way.",

@@ -8,2 +8,3 @@ "type": "module",

"module": "dist/index.js",
"main": "dist/index.js",
"scripts": {

@@ -13,3 +14,4 @@ "build": "esbuild --bundle ./src/index.js --outfile=./dist/index.js --format=esm --sourcemap --minify",

"prepublish": "npm run build",
"test": "echo \"Error: no test specified\" && exit 1"
"pretest": "npm run build",
"test": "mocha"
},

@@ -36,7 +38,8 @@ "repository": {

"devDependencies": {
"esbuild": "^0.14"
"esbuild": "^0.14.5",
"mocha": "^9.1.3"
},
"dependencies": {
"@bramus/range": "^1.0.1"
"@bramus/range": "^1.1.0"
}
}

@@ -1,2 +0,2 @@

![JavaScript Pagination Sequence Generator](./screenshots/js-pagination-sequence.png)
[![JavaScript Pagination Sequence Generator](./screenshots/js-pagination-sequence.png)](https://codepen.io/bramus/pen/NWaxNKQ)

@@ -33,3 +33,3 @@ # JavaScript Pagination Sequence Generator

```js
generate(curPage, numPages, numberOfPagesAtEdges = 2, numberOfPagesAroundCurrent = 2, glue = '…');
generate(curPage, numPages, numPagesAtEdges = 2, numPagesAroundCurrent = 2, glue = '…');
```

@@ -41,4 +41,4 @@

- `numPages`: The total number of pages
- `numberOfPagesAtEdges` _(default: 2)_: Number of pages to show on the outer edges.
- `numberOfPagesAroundCurrent` _(default: 2)_: Number of pages to show around the active page.
- `numPagesAtEdges` _(default: 2)_: Number of pages to show on the outer edges.
- `numPagesAroundCurrent` _(default: 2)_: Number of pages to show around the active page.
- `glue` _(default: '…')_: The string to show when there's a gap

@@ -52,3 +52,3 @@

When generating a sequence, it will always generate the same amount of entries, for any `curPage` value. When viewing a page at the edge of a series, this can result in `numberOfPagesAtEdges` being ignored.
When generating a sequence, it will always generate the same amount of entries, for any `curPage` value. When viewing a page at the edge of a series, this can result in `numPagesAtEdges` being ignored.

@@ -55,0 +55,0 @@ For example: Instead of having `generate(2, 12, 1, 1)` return `01-[02]-03-..-12` _(5 entries)_, it will return `01-[02]-03-04-05-..-12` _(7 entries)_. This is a deliberate choice because `generate(7, 12, 1, 1)` will also return 7 entries: `01-..-06-[07]-08-..-12`.

@@ -0,1 +1,2 @@

import { equal, deepEqual } from 'assert';
import { generate } from '../dist/index.js';

@@ -5,3 +6,3 @@

return value.toString().padStart(targetLength, '0');
}
};

@@ -21,107 +22,104 @@ const prettyFormat = (activeValue) => {

return formatted;
}
}
};
};
const runExample = (curPage, numPages, numberOfPagesAtEdges = 2, numberOfPagesAroundCurrent = 2, glue = '…') => {
console.log(generate(curPage, numPages, numberOfPagesAtEdges, numberOfPagesAroundCurrent, glue).map(prettyFormat(curPage)).join('-'));
}
return generate(curPage, numPages, numberOfPagesAtEdges, numberOfPagesAroundCurrent, glue).map(prettyFormat(curPage)).join('-');
};
runExample(1, 11);
runExample(2, 11);
runExample(3, 11);
runExample(4, 11);
runExample(5, 11);
runExample(6, 11);
runExample(7, 11);
runExample(8, 11);
runExample(9, 11);
runExample(10, 11);
runExample(11, 11);
console.log('');
describe('basic series', () => {
it('it should work', () => {
equal(runExample(1, 11), '[01]-02-03-04-05-06-07-08-09-10-11');
equal(runExample(2, 11), '01-[02]-03-04-05-06-07-08-09-10-11');
equal(runExample(3, 11), '01-02-[03]-04-05-06-07-08-09-10-11');
equal(runExample(4, 11), '01-02-03-[04]-05-06-07-08-09-10-11');
equal(runExample(5, 11), '01-02-03-04-[05]-06-07-08-09-10-11');
equal(runExample(6, 11), '01-02-03-04-05-[06]-07-08-09-10-11');
equal(runExample(7, 11), '01-02-03-04-05-06-[07]-08-09-10-11');
equal(runExample(8, 11), '01-02-03-04-05-06-07-[08]-09-10-11');
equal(runExample(9, 11), '01-02-03-04-05-06-07-08-[09]-10-11');
equal(runExample(10, 11), '01-02-03-04-05-06-07-08-09-[10]-11');
equal(runExample(11, 11), '01-02-03-04-05-06-07-08-09-10-[11]');
});
runExample(1, 11, 1);
runExample(2, 11, 1);
runExample(3, 11, 1);
runExample(4, 11, 1);
runExample(5, 11, 1);
runExample(6, 11, 1);
runExample(7, 11, 1);
runExample(8, 11, 1);
runExample(9, 11, 1);
runExample(10, 11, 1);
runExample(11, 11, 1);
console.log('');
it('it should work with adjusted numberOfPagesAtEdges', () => {
equal(runExample(1, 11, 1), '[01]-02-03-04-05-06-07-..-11');
equal(runExample(2, 11, 1), '01-[02]-03-04-05-06-07-..-11');
equal(runExample(3, 11, 1), '01-02-[03]-04-05-06-07-..-11');
equal(runExample(4, 11, 1), '01-02-03-[04]-05-06-07-..-11');
equal(runExample(5, 11, 1), '01-02-03-04-[05]-06-07-..-11');
equal(runExample(6, 11, 1), '01-..-04-05-[06]-07-08-..-11');
equal(runExample(7, 11, 1), '01-..-05-06-[07]-08-09-10-11');
equal(runExample(8, 11, 1), '01-..-05-06-07-[08]-09-10-11');
equal(runExample(9, 11, 1), '01-..-05-06-07-08-[09]-10-11');
equal(runExample(10, 11, 1), '01-..-05-06-07-08-09-[10]-11');
equal(runExample(11, 11, 1), '01-..-05-06-07-08-09-10-[11]');
});
runExample(1, 11, 1, 1);
runExample(2, 11, 1, 1);
runExample(3, 11, 1, 1);
runExample(4, 11, 1, 1);
runExample(5, 11, 1, 1);
runExample(6, 11, 1, 1);
runExample(7, 11, 1, 1);
runExample(8, 11, 1, 1);
runExample(9, 11, 1, 1);
runExample(10, 11, 1, 1);
runExample(11, 11, 1, 1);
console.log('');
it('it should work with adjusted numberOfPagesAtEdges and numberOfPagesAroundCurrent', () => {
equal(runExample(1, 11, 1, 1), '[01]-02-03-04-05-..-11');
equal(runExample(2, 11, 1, 1), '01-[02]-03-04-05-..-11');
equal(runExample(3, 11, 1, 1), '01-02-[03]-04-05-..-11');
equal(runExample(4, 11, 1, 1), '01-02-03-[04]-05-..-11');
equal(runExample(5, 11, 1, 1), '01-..-04-[05]-06-..-11');
equal(runExample(6, 11, 1, 1), '01-..-05-[06]-07-..-11');
equal(runExample(7, 11, 1, 1), '01-..-06-[07]-08-..-11');
equal(runExample(8, 11, 1, 1), '01-..-07-[08]-09-10-11');
equal(runExample(9, 11, 1, 1), '01-..-07-08-[09]-10-11');
equal(runExample(10, 11, 1, 1), '01-..-07-08-09-[10]-11');
equal(runExample(11, 11, 1, 1), '01-..-07-08-09-10-[11]');
});
});
runExample(1, 11, 1);
runExample(2, 11, 1);
runExample(3, 11, 1);
runExample(4, 11, 1);
runExample(5, 11, 1);
runExample(10, 11, 1);
console.log('');
describe('larger series', () => {
it('it should work', () => {
equal(runExample(1, 12), '[01]-02-03-04-05-06-07-08-..-11-12');
equal(runExample(5, 12), '01-02-03-04-[05]-06-07-08-..-11-12');
equal(runExample(10, 12), '01-02-..-05-06-07-08-09-[10]-11-12');
});
runExample(1, 11, 1, 1);
runExample(2, 11, 1, 1);
runExample(3, 11, 1, 1);
runExample(4, 11, 1, 1);
runExample(5, 11, 1, 1);
runExample(10, 11, 1, 1);
console.log('');
it('it should work with adjusted numberOfPagesAroundCurrent', () => {
equal(runExample(1, 11, 2, 1), '[01]-02-03-04-05-06-..-10-11');
equal(runExample(2, 11, 2, 1), '01-[02]-03-04-05-06-..-10-11');
equal(runExample(3, 11, 2, 1), '01-02-[03]-04-05-06-..-10-11');
equal(runExample(5, 11, 2, 1), '01-02-03-04-[05]-06-..-10-11');
equal(runExample(10, 11, 2, 1), '01-02-..-06-07-08-09-[10]-11');
});
runExample(1, 12, 1, 1);
runExample(2, 12, 1, 1);
runExample(3, 12, 1, 1);
runExample(4, 12, 1, 1);
runExample(5, 12, 1, 1);
runExample(6, 12, 1, 1);
runExample(7, 12, 1, 1);
runExample(8, 12, 1, 1);
runExample(9, 12, 1, 1);
runExample(10, 12, 1, 1);
runExample(11, 12, 1, 1);
runExample(12, 12, 1, 1);
console.log('');
it('it should work with adjusted numberOfPagesAtEdges and numberOfPagesAroundCurrent', () => {
equal(runExample(1, 12, 1, 1), '[01]-02-03-04-05-..-12');
equal(runExample(2, 12, 1, 1), '01-[02]-03-04-05-..-12');
equal(runExample(3, 12, 1, 1), '01-02-[03]-04-05-..-12');
equal(runExample(4, 12, 1, 1), '01-02-03-[04]-05-..-12');
equal(runExample(5, 12, 1, 1), '01-..-04-[05]-06-..-12');
equal(runExample(6, 12, 1, 1), '01-..-05-[06]-07-..-12');
equal(runExample(7, 12, 1, 1), '01-..-06-[07]-08-..-12');
equal(runExample(8, 12, 1, 1), '01-..-07-[08]-09-..-12');
equal(runExample(9, 12, 1, 1), '01-..-08-[09]-10-11-12');
equal(runExample(10, 12, 1, 1), '01-..-08-09-[10]-11-12');
equal(runExample(11, 12, 1, 1), '01-..-08-09-10-[11]-12');
equal(runExample(12, 12, 1, 1), '01-..-08-09-10-11-[12]');
});
});
runExample(1, 11, 2, 1);
runExample(2, 11, 2, 1);
runExample(3, 11, 2, 1);
runExample(5, 11, 2, 1);
runExample(10, 11, 2, 1);
console.log('');
runExample(1, 12);
runExample(5, 12);
runExample(10, 12);
console.log('');
runExample(1, 74);
runExample(2, 74);
runExample(3, 74);
runExample(4, 74);
runExample(5, 74);
runExample(6, 74);
runExample(7, 74);
runExample(8, 74);
runExample(9, 74);
console.log('…');
runExample(67, 74);
runExample(68, 74);
runExample(69, 74);
runExample(70, 74);
runExample(71, 74);
runExample(72, 74);
runExample(73, 74);
runExample(74, 74);
describe('large series', () => {
it('it should work', () => {
equal(runExample(1, 74), '[01]-02-03-04-05-06-07-08-..-73-74');
equal(runExample(2, 74), '01-[02]-03-04-05-06-07-08-..-73-74');
equal(runExample(3, 74), '01-02-[03]-04-05-06-07-08-..-73-74');
equal(runExample(4, 74), '01-02-03-[04]-05-06-07-08-..-73-74');
equal(runExample(5, 74), '01-02-03-04-[05]-06-07-08-..-73-74');
equal(runExample(6, 74), '01-02-03-04-05-[06]-07-08-..-73-74');
equal(runExample(7, 74), '01-02-..-05-06-[07]-08-09-..-73-74');
equal(runExample(8, 74), '01-02-..-06-07-[08]-09-10-..-73-74');
equal(runExample(9, 74), '01-02-..-07-08-[09]-10-11-..-73-74');
equal(runExample(67, 74), '01-02-..-65-66-[67]-68-69-..-73-74');
equal(runExample(68, 74), '01-02-..-66-67-[68]-69-70-..-73-74');
equal(runExample(69, 74), '01-02-..-67-68-[69]-70-71-72-73-74');
equal(runExample(70, 74), '01-02-..-67-68-69-[70]-71-72-73-74');
equal(runExample(71, 74), '01-02-..-67-68-69-70-[71]-72-73-74');
equal(runExample(72, 74), '01-02-..-67-68-69-70-71-[72]-73-74');
equal(runExample(73, 74), '01-02-..-67-68-69-70-71-72-[73]-74');
equal(runExample(74, 74), '01-02-..-67-68-69-70-71-72-73-[74]');
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc