/** * A predicate function used to determine whether an item should be included in the filtered results. * Works similarly to the callback function of `Array.prototype.filter`. * * @template {any} ArrayItem * @callback GetFilter * @param {ArrayItem} value - The current element being processed in the array. * @param {number} index - The index of the current element within the array. * @param {ArrayItem[]} array - The full array being processed. * @returns {boolean} Returns `true` to include the element in the results, or `false` to exclude it. */ export type GetFilter = (value: ArrayItem, index: number, array: ArrayItem[]) => boolean; export type GetterResult = { /** * - The subset of items for the requested page. */ items: ArrayItem[]; /** * - The current (validated) page number. */ page: number; /** * - Number of items per page used in the calculation. */ perPage: number; /** * - Total number of items in the filtered data. */ totalItems: number; /** * - Total number of pages available. */ totalPages: number; /** * - Whether a previous page exists. */ hasPrev: boolean; /** * - Whether a next page exists. */ hasNext: boolean; }; /** * @template {any} ArrayItem * @typedef {Object} GetterResult * @property {ArrayItem[]} items - The subset of items for the requested page. * @property {number} page - The current (validated) page number. * @property {number} perPage - Number of items per page used in the calculation. * @property {number} totalItems - Total number of items in the filtered data. * @property {number} totalPages - Total number of pages available. * @property {boolean} hasPrev - Whether a previous page exists. * @property {boolean} hasNext - Whether a next page exists. */ /** * A encapsulated wrapper for array pagination. * Provides methods to retrieve paginated results with metadata, * while keeping the source array safe from direct modifications. * @template {any} ArrayItem */ declare class TinyArrayPaginator { #private; /** * Gets current stored array. * @returns {ArrayItem[]|Set} */ get data(): ArrayItem[] | Set; /** * Replaces the current data array. * @param {ArrayItem[]|Set} value - The new array to be used as the data source. * @throws {TypeError} If the provided value is not an array. */ set data(value: ArrayItem[] | Set); /** * Gets the total number of items in the current data array. * @returns {number} Total number of stored items. */ get size(): number; /** * Creates a new paginator instance for the given data array. * @param {ArrayItem[]|Set} data - The array to be paginated. * @throws {TypeError} If the provided data is not an array. */ constructor(data: ArrayItem[] | Set); /** * Filters data according to a search query and returns paginated results. * @param {Object} settings * @param {number} settings.page - The page number (1-based index). * @param {number} settings.perPage - Items per page. * @param {Record | GetFilter} [settings.filter=null] - Filtering criteria: * - Object: key-value pairs for exact match, substring match, or RegExp * - Function: custom filter function returning true for items to include * @returns {GetterResult} */ get({ page, perPage, filter }: { page: number; perPage: number; filter?: Record | GetFilter; }): GetterResult; } export default TinyArrayPaginator; //# sourceMappingURL=TinyArrayPaginator.d.mts.map