<commit_before>import {Defaults} from './common/defaults';
import {IPager} from './contracts/IPager';
import {filter} from './filterAnnotation';
import {IFilterConfig} from './contracts/IFilterConfig';

export class PagedPager implements IPager {
    private pageSizeInternal = Defaults.pagedListSettings.defaultPageSize;

    @filter({ defaultValue: 1, parameterName: Defaults.pagedListSettings.pageNumberParameterName } as IFilterConfig)
    private pageNumberInternal = 1;

    defaultPageSize = Defaults.pagedListSettings.defaultPageSize;
    maxPageSize = Defaults.pagedListSettings.maxPageSize;
    minPageSize = Defaults.pagedListSettings.minPageSize;
    totalCount: number = 0;
    loadedCount: number = 0;
    displayFrom = 0;
    displayTo = 0;

    get pageCount(): number {
        return Math.ceil(this.totalCount / this.pageSizeInternal);
    }
    get pageNumber(): number {
        return this.pageNumberInternal;
    }
    set pageNumber(value: number) {
        const valueStr = (value + '').replace(/[^0-9]/g, '');
        let pageNumber = parseInt(valueStr, 10) ? parseInt(valueStr, 10) : 1;
        if (pageNumber > this.pageCount) {
            pageNumber = this.pageCount;
        }
        if (pageNumber < 1) {
            pageNumber = 1;
        }
        this.pageNumberInternal = pageNumber;
    }
    @filter({
        defaultValue: function (): number { return this.defaultPageSize; },
        parameterName: Defaults.pagedListSettings.pageSizeParameterName,
        persisted: Defaults.pagedListSettings.persistPageSize
    })
    get pageSize(): number {
        return this.pageSizeInternal;
    }
    set pageSize(value: number) {
        const valueStr = (value + '').replace(/[^0-9]/g, '');
        let pageSize = parseInt(valueStr, 10) ? parseInt(valueStr, 10) : this.defaultPageSize;

        if (pageSize > this.maxPageSize) {
            pageSize = this.maxPageSize;
        }
        if (this.totalCount !== 0) {
            if (pageSize > this.totalCount) {
                pageSize = this.totalCount;
            }

            if (this.pageNumber * pageSize > this.totalCount) {
                pageSize = Math.ceil(this.totalCount / this.pageNumber);
                if (pageSize > this.maxPageSize) {
                    pageSize = this.maxPageSize;
                }
            }
        }
        if (pageSize < this.minPageSize || pageSize === 0) {
            pageSize = this.defaultPageSize;
        }
        if (this.pageNumber === this.pageCount && pageSize > this.pageSizeInternal) {
            pageSize = this.pageSizeInternal;<commit_msg>parseFormatters for pager properties<commit_after>import {Defaults} from './common/defaults';
import {IPager} from './contracts/IPager';
import {filter} from './filterAnnotation';
import {IFilterConfig} from './contracts/IFilterConfig';

export class PagedPager implements IPager {
    private pageSizeInternal = Defaults.pagedListSettings.defaultPageSize;

    @filter({
        defaultValue: 1,
        parameterName: Defaults.pagedListSettings.pageNumberParameterName,
        parseFormatter: function (proposedParam: any): number {
            return isNaN(proposedParam) || !proposedParam ? 1 : proposedParam;
        }
    } as IFilterConfig)
    private pageNumberInternal = 1;

    defaultPageSize = Defaults.pagedListSettings.defaultPageSize;
    maxPageSize = Defaults.pagedListSettings.maxPageSize;
    minPageSize = Defaults.pagedListSettings.minPageSize;
    totalCount: number = 0;
    loadedCount: number = 0;
    displayFrom = 0;
    displayTo = 0;

    get pageCount(): number {
        return Math.ceil(this.totalCount / this.pageSizeInternal);
    }
    get pageNumber(): number {
        return this.pageNumberInternal;
    }
    set pageNumber(value: number) {
        const valueStr = (value + '').replace(/[^0-9]/g, '');
        let pageNumber = parseInt(valueStr, 10) ? parseInt(valueStr, 10) : 1;
        if (pageNumber > this.pageCount) {
            pageNumber = this.pageCount;
        }
        if (pageNumber < 1) {
            pageNumber = 1;
        }
        this.pageNumberInternal = pageNumber;
    }
    @filter({
        defaultValue: function (): number { return this.defaultPageSize; },
        parameterName: Defaults.pagedListSettings.pageSizeParameterName,
        parseFormatter: function (proposedParam: any): number {
            return isNaN(proposedParam) || !proposedParam ? this.defaultPageSize : proposedParam;
        },
        persisted: Defaults.pagedListSettings.persistPageSize
    })
    get pageSize(): number {
        return this.pageSizeInternal;
    }
    set pageSize(value: number) {
        const valueStr = (value + '').replace(/[^0-9]/g, '');
        let pageSize = parseInt(valueStr, 10) ? parseInt(valueStr, 10) : this.defaultPageSize;

        if (pageSize > this.maxPageSize) {
            pageSize = this.maxPageSize;
        }
        if (this.totalCount !== 0) {
            if (pageSize > this.totalCount) {
                pageSize = this.totalCount;
            }

            if (this.pageNumber * pageSize > this.totalCount) {
                pageSize = Math.ceil(this.totalCount / this.pageNumber);
                if (pageSize > this.maxPageSize) {
                    pageSize = this.maxPageSize;
                }
            }
        }
        if (pageSize < this.minPageSize || pageSize === 0) {
            pageSize = this.defaultPageSize;
        }
        if (this.pageNumber === this.pageCount && pageSize > this.pageSizeInternal) {
            pageSize = this.pageSizeInternal;
{'fraction_non_alphanumeric': 0.10905497664390945, 'fraction_numerical': 0.00844412504491556, 'mean_word_length': 2.4427952999381572, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5350285', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1562, 'n_words': 332}