import { Injectable } from '@angular/core' ; import { Pluralizer } from './pluralizer' ; @ Injectable ( ) export class HttpUrlGenerator { constructor ( private pluralizer ) { } entityResource ( entityName , root ) { root = normalizeRoot ( root ) ; return `${ root }/${ entityName }/` . toLowerCase ( ) ; } collectionResource ( entityName , root ) { root = normalizeRoot ( root ) ; const entitiesName = this . pluralizer . pluralize ( entityName ) ; return `${ root }/${ entitiesName }/` . toLowerCase ( ) ; } } /** Remove leading & trailing spaces or slashes */ export function normalizeRoot ( root ) { return root . replace ( /^[\/\s]+|[\/\s]+$/g , '' ) ; }