import { parse } from 'url' ; import { filter } from 'lodash' ; const isBogusUrl = ( url ) => { const { host , protocol , port } = parse ( url , false , true ) ; return host !== null || protocol !== null || port !== null ; } ; export const validateUrls = ( urls ) : void => { if ( ! Array . isArray ( urls ) ) { throw new Error ( 'Invalid relativeUrls. String[] is expected.' ) ; } urls . forEach ( ( url ) => { if ( typeof url !== 'string' ) { throw new Error ( 'Invalid Relative URL in relativeUrls. String is expected.' ) ; } } ) ; const badUrls = filter ( urls , ( url ) => isBogusUrl ( url ) ) ; if ( badUrls . length ) { throw new Error ( `Found invalid URL(s), all URLs must be relative: ${ badUrls . join ( ' ' ) }` ) ; } } ;