UNPKG

549 BJavaScriptView Raw
1const _ = require('lodash')
2
3/**
4 * @function
5 * @public
6 *
7 * Get Link header value based on pagination links
8 *
9 * @param {Object.<?string>} links The entity/href mapping of pagination links
10 * @returns {string} Parsed Link header value if links available
11 */
12function getLinkHeader (links) {
13 const linkHeader = []
14
15 _.forOwn(links, (link, entity) => {
16 if (entity !== 'self') {
17 linkHeader.push(`<${link.href}>; rel="${entity}"`)
18 }
19 })
20
21 return linkHeader.join(', ') || undefined
22}
23
24module.exports = {
25 getLink: getLinkHeader
26}