2.0.0 • Published 2 years ago

@caruuto/api-metadata v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Metadata

Generates pagination metadata for API result sets.

{
  "page": 2,
  "limit": 20,
  "offset": 0,
  "totalCount": 200,
  "totalPages": 10,
  "nextPage": 3,
  "prevPage": 1
}

Installation

$ npm i api-metadata

Usage

The metadata function accepts two arguments:

argumentdescription
optionsthe options that were used to generate the data set
options.pagethe page number requested
options.limitthe number of records requested
options.skipthe number of records skipped
countthe total number of records in the original data set, before options were applied
const apiMetadata = require('api-metadata')

const options = {
  page: 2,
  limit: 20
}

const metadata = apiMetadata(options, 200)