pagination-ui-less
Version:
A Pagination manager library without UI.
3 lines (2 loc) • 1.19 kB
JavaScript
function e(e){var n=e.pagesLength,t=void 0===n?1:n,r=e.currentPage,a=void 0===r?1:r,u=e.onChange,i=function(e){a=Number(e);var n=o();return"function"==typeof u&&u(n),n},o=function(){var e=function(){if(a-2<=0)return 1;var e=a+2-t;return e>0?a-2-e:a-2}(),n=Array(5).fill(e).map(function(e,n){var t=e+n;return{isActive:t===a,action:"setPage",value:t}}).filter(function(e){var n=e.value;return n>=1&&n<=t}),r=n.some(function(e){return 1===e.value})?[]:[{action:"setPage",value:1}],u=n.some(function(e){return e.value===t})?[]:[{action:"setPage",value:t}],i=1===a?[]:[{action:"previousPage",value:"Prev"}],o=a===t?[]:[{action:"nextPage",value:"Next"}],c=function(e){return e?[{action:null,value:"..."}]:[]},f=Array.from(n,function(e){return e.value});return{currentPage:a,pages:[].concat(i,r,c(Math.min.apply(Math,f)>2),n,c(Math.max.apply(Math,f)<t-1),u,o)}};return{setPage:i,setPagesLength:function(e,n){return t=e,n&&(a=n),o()},getPages:o,getCurrentPage:function(){return a},nextPage:function(){return i(a+1)},previousPage:function(){return i(a-1)},firstPage:function(){return i(1)},lastPage:function(){return i(t)}}}export{e as default};
//# sourceMappingURL=index.modern.module.js.map