import { Injectable } from '@angular/core' ; /**
 * An utility service for link parsing.
 */ @ Injectable ( { providedIn : 'root' , } ) export class ParseLinks { /**
     * Method to parse the links
     */ parse ( header ) { if ( header . length === 0 ) { throw new Error ( 'input must not be of zero length' ) ; } const parts = header . split ( ',' ) ; const links = { } ; parts . forEach ( p => { const section = p . split ( ';' ) ; if ( section . length !== 2 ) { throw new Error ( 'section could not be split on ";"' ) ; } const url = section [ 0 ] . replace ( /<(.*)>/ , '$1' ) . trim ( ) ; const queryString = { } ; url . replace ( /([^?=&]+)(=([^&]*))?/g , ( $0 , $1 , $2 , $3 ) => { if ( $1 !== undefined ) { queryString [ $1 ] = $3 ; } return $3 ?? '' ; } ) ; if ( queryString . page !== undefined ) { const name = section [ 1 ] . replace ( /rel="(.*)"/ , '$1' ) . trim ( ) ; links [ name ] = parseInt ( queryString . page , 10 ) ; } } ) ; return links ; } }