import * as url from 'url' ; import { HostingEnvironment } from '../auth/HostingEnvironment' ; export class UrlHelper { public static removeTrailingSlash ( url ) { return url . replace ( /(\/$)|(\\$)/ , '' ) ; } public static removeLeadingSlash ( url ) { return url . replace ( /(^\/)|(^\\)/ , '' ) ; } public static trimSlashes ( url ) { return url . replace ( /(^\/)|(^\\)|(\/$)|(\\$)/g , '' ) ; } public static ResolveHostingEnvironment ( siteUrl ) { const host = ( url . parse ( siteUrl ) ) . host ; if ( host . indexOf ( '.sharepoint.com' ) !== - 1 ) { return HostingEnvironment . Production ; } else if ( host . indexOf ( '.sharepoint.cn' ) !== - 1 ) { return HostingEnvironment . China ; } else if ( host . indexOf ( '.sharepoint.de' ) !== - 1 ) { return HostingEnvironment . German ; } else if ( host . indexOf ( '.sharepoint-mil.us' ) !== - 1 ) { return HostingEnvironment . USDefence ; } else if ( host . indexOf ( '.sharepoint.us' ) !== - 1 ) { return HostingEnvironment . USGovernment ; } return HostingEnvironment . Production ; } }