UNPKG

@mikezimm/fps-core-v7

Version:

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

77 lines 3.23 kB
// import { CurrentOrigin } from "../Strings/getSiteCollectionUrlFromLink"; import { CurrentOrigin } from "../../components/molecules/source-props/WindowLocationConstants"; import { getDomain } from "./getDomains"; import { getCollectionUrl, getTeamsUrl } from "./getSPOUrl"; // eslint-disable-next-line @typescript-eslint/no-explicit-any export function getAllDomainsFromUrls(urls, noDups, includeSharePoint, includeTenant, includeSites, includeTeams) { const results = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any let showSPO = false; // eslint-disable-next-line @typescript-eslint/no-explicit-any let showTenant = false; // let showSlashSites: any = false; // let showSlashTeams: any = false; const showSites = []; const showTeams = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any urls.map((url) => { let urlStr = ``; if (!url) { // } else if (typeof url === 'string') { urlStr = url; } else if (url.Url) { urlStr = url.Url; } if (urlStr) { if (showTenant === false && includeTenant === true && urlStr.indexOf(CurrentOrigin) > -1) { showTenant = true; } if (includeSites === true) { if (url.indexOf(CurrentOrigin) === 0) { const thisSite = getCollectionUrl(urlStr); if (showSites.indexOf(thisSite) < 0) showSites.push(thisSite); } else if (url.indexOf('/sites/') === 0) { const thisSite = url.replace(`/sites/`, '').split('/')[0]; if (showSites.indexOf(thisSite) < 0) showSites.push(thisSite); } } if (includeTeams === true) { if (url.indexOf(CurrentOrigin) === 0) { const thisSite = getTeamsUrl(urlStr); if (showTeams.indexOf(thisSite) < 0) showTeams.push(thisSite); } else if (url.indexOf('/teams/') === 0) { const thisSite = url.replace(`/teams/`, '').split('/')[0]; if (showTeams.indexOf(thisSite) < 0) showTeams.push(thisSite); } } const domain = getDomain(urlStr); if (showSPO === false && domain === 'sharepoint' && includeSharePoint === true) { showSPO = true; } else if (results.indexOf(domain) < 0) results.push(domain); } }); if (showSites.length > 0) results.unshift(...showSites); if (showSites.length > 0) results.unshift('/sites/'); if (showTeams.length > 0) results.unshift(...showTeams); if (showTeams.length > 0) results.unshift('/teams/'); if (showTenant === true) results.unshift(CurrentOrigin); if (showSPO === true) results.unshift('.sharepoint.'); return results; } //# sourceMappingURL=getAllDomainsFromUrls.js.map