@synergy-design-system/components
Version:
47 lines (46 loc) • 2.19 kB
TypeScript
/**
* Checks whether a value is a positive integer.
*/
export declare const isValidPositiveInteger: (value: unknown) => value is number;
/**
* Checks whether a value is a non-negative integer.
*/
export declare const isValidNonNegativeInteger: (value: unknown) => value is number;
/**
* Returns the previous value for a changed numeric property when valid,
* otherwise returns the provided fallback.
*/
export declare const getPreviousOrDefault: (changed: Map<PropertyKey, unknown>, key: PropertyKey, fallback: number, validator: (value: unknown) => value is number) => number;
/**
* Calculates the total number of pages based on the total number of items and the selected page size.
*/
export declare const calculateTotalPages: (totalItems: number, pageSize: number) => number;
/**
* Calculates the item start and end indices for the current page based on the total number of items, selected page size, and current page number.
*/
export declare const calculatePageItemIndices: (totalItems: number, pageSize: number, currentPage: number) => {
endIndex: number;
startIndex: number;
};
/**
* Clamps the current page number to ensure it falls within the valid range of 1 to the total number of pages.
* If the provided page number is not a finite number, it defaults to 1.
*/
export declare const clampPage: (page: number, totalPages: number) => number;
/**
* Calculates the total number of pages based on the page size and total number of items.
*/
export declare const getTotalPages: (pageSize: number, totalItems: number) => number;
/**
* Sanitizes the page size options by ensuring they are an array of positive integers.
* If the input is not valid, it defaults to a predefined set of page size options.
*/
export declare const sanitizePageSizeOptions: (pageSizeOptions: unknown) => number[];
/**
* Calculates the maximum number of characters needed to display the page size options.
*/
export declare const getMaxOptionCharCount: (pageSizeOptions: number[]) => number;
/**
* Calculates the number of characters needed to display the total number of pages.
*/
export declare const getTotalPagesCharCount: (pageSize: number, totalItems: number) => number;