<commit_before>import AmpCollection from './AmpCollection.js';

class PaginatedCollection extends AmpCollection {
    constructor(data, size) {
        super(data);

        size = size || false;
        this.pages = {};

        if(size) {
            this.paginate(size);
        }
    }

    paginate(size) {
        let sets = [];

        let chunks = this._data.length / size;

        for(let i = 0, c = 0; i < chunks; i++, c += size) {
            sets[i] = this._data.slice(c, c + size);
        }

        this._processed = sets;

        return this;
    }

    page(page) {
        page = page || 1;

        this._processed = this._data[0][page-1];

        return this;
    }
}

export default PaginatedCollection;
<commit_msg>Page references object<commit_after>import AmpCollection from './AmpCollection.js';

class PaginatedCollection extends AmpCollection {
    constructor(data, size) {
        super(data);

        size = size || false;
        this.pages = {};

        if(size) {
            this.paginate(size);
        }
    }

    paginate(size) {
        let sets = [];

        let chunks = this.data.length / size;

        for(let i = 0, c = 0; i < chunks; i++, c += size) {
            sets[i] = this.data.slice(c, c + size);
        }

        this.pages = {
            current: 1,
            next: 2,
            previous: 1,
            last: sets.length,
            chunks: size
        };

        this._processed = sets;

        return this;
    }

    page(page) {
        page = page || 1;

        let pageReference = page-1;
        let nextPage = page+1;
        let previousPage = page-1;

        if(pageReference > this.pages.last) {
            nextPage = this.pages.last;
        }

        if(pageReference < 0) {
            previousPage = 0;
        }

        this.pages.current = page;
        this.pages.next = nextPage;
        this.pages.previous = previousPage;

        this._processed = this._data[page-1];

        return this;
    }
}

export default PaginatedCollection;

{'fraction_non_alphanumeric': 0.12082514734774066, 'fraction_numerical': 0.008349705304518664, 'mean_word_length': 1.575221238938053, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, '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': '6784710', 'n_tokens_mistral': 642, 'n_tokens_neox': 596, 'n_words': 142}