corporate-frontend-mithril
Version:
Corporate frontend MithrilJS modules
42 lines (37 loc) • 893 B
JavaScript
const unescape = function (text) {
if (text) {
return text.replace('+', '+');
}
};
const pagination = (c, m) => {
// https://gist.github.com/kottenator/9d936eb3e4e3c3e02598
var current = c,
last = m,
delta = 5,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
for (let i = 1; i <= last; i++) {
if (i == 1 || i == last || i >= left && i < right) {
range.push(i);
}
}
for (let i of range) {
if (l) {
if (i - l === 2) {
rangeWithDots.push(l + 1);
} else if (i - l !== 1) {
rangeWithDots.push('...');
}
}
rangeWithDots.push(i);
l = i;
}
return rangeWithDots;
};
module.exports = {
unescape,
pagination,
};