@npmjs_tdsoftware/subidentity
Version:
This package provides functionality to fetch identities and search identities by address or any identity field from any Substrate chain implementing the identities pallet. It was developed for use in SubIdentity, a Substrate identity directory, and contai
43 lines (42 loc) • 1.83 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports._validatePaginationInput = exports._paginate = void 0;
/**
* @param allItems list of items to be paginated
* @param page requested page number
* @param limit number of items per page
*/
function _paginate(allItems, page, limit) {
return __awaiter(this, void 0, void 0, function* () {
const startIndex = (page - 1) * limit;
const endIndex = page * limit;
const items = allItems.slice(startIndex, endIndex);
const totalPageCount = Math.ceil(allItems.length / limit);
const totalItemsCount = allItems.length;
let previous, next;
if (startIndex > 0) {
previous = page - 1;
}
if (endIndex < totalItemsCount) {
next = page + 1;
}
return { totalItemsCount, totalPageCount, previous, next, items };
});
}
exports._paginate = _paginate;
function _validatePaginationInput(page, limit) {
let isValid = false;
if (page > 0 && limit > 0)
isValid = true;
return isValid;
}
exports._validatePaginationInput = _validatePaginationInput;