UNPKG

@anot/http-response-builder

Version:

A robust and type-safe library for constructing HTTP responses with optional paging and metadata. Designed for TypeScript and JavaScript, it ensures correct typing while simplifying the creation of various HTTP response types.

47 lines (46 loc) 1.04 kB
export class Paging { page; size; total; constructor(page, size, total) { this.setPage(page); this.setSize(size); this.setTotal(total); } setPage(page) { if (page !== undefined) { if (page < 0) { throw new TypeError('Page number cannot be negative'); } this.page = page; } return this; } setSize(size) { if (size !== undefined) { if (size <= 0) { throw new TypeError('Page size must be greater than 0'); } this.size = size; } return this; } setTotal(total) { if (total !== undefined) { if (total < 0) { throw new TypeError('Total count cannot be negative'); } this.total = total; } return this; } getPage() { return this.page; } getSize() { return this.size; } getTotal() { return this.total; } }