UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

54 lines (49 loc) 2.03 kB
/** * This could be modified to leverage an array of regex * @param url * @param regex1 * @param regex2 * @returns */ export declare function getDomain2Reg(url: string, regex1: RegExp, regex2: RegExp): string; /** * To extract the site collection name from a SharePoint Online site URL, you can use the following JavaScript regular expression. This regex will capture the site collection name from the given URL structure. Here is the JavaScript code: javascript Copy code function getSiteCollectionName(url) { const regex = /https:\/\/[^.]+\.sharepoint\.com\/sites\/([^\/]+)/i; const match = url.match(regex); return match ? match[1] : null; } const url = "https://fuzzypawstech.sharepoint.com/sites/XYZ/MoreStuff"; const siteCollectionName = getSiteCollectionName(url); console.log(siteCollectionName); // Outputs: XYZ Explanation of the regex: https:\/\/ matches the https:// part of the URL. [^.]+ matches one or more characters that are not a dot, capturing the subdomain part (e.g., tenant). \.sharepoint\.com\/sites\/ matches .sharepoint.com/sites/. ([^\/]+) captures one or more characters that are not a forward slash (/), representing the site collection name. i is the case-insensitive flag. This regex will correctly extract the site collection name (e.g., XYZ) from the given SharePoint Online site URL. * @param url */ /** * NOTE: There is a better function for getting full absolute value of current site: getSiteCollectionUrlFromLink * You can also get it directly using the constant: CurrentSiteAbsolute * * url = 'https://tenant.sharepoint.com/sites/XYZ/MoreStuff' * output: XYZ * * @param url * @returns */ export declare function getCollectionUrl(url: string): string; /** * * @param url * @returns */ export declare function getTeamsUrl(url: string): string; //# sourceMappingURL=getSPOUrl.d.ts.map