@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
78 lines (75 loc) • 4.38 kB
JavaScript
// window.location properties
// host: "tenant.sharepoint.com"
// hostname: "tenant.sharepoint.com"
// href: "https://tenant.sharepoint.com/sites/WebPartDev/SitePages/ECStorage.aspx?debug=true&noredir=true&debugManifestsFile=https%3A%2F%2Flocalhost%3A4321%2Ftemp%2Fmanifests.js&allowOtherSites=true&scenario=dev"
// origin: "https://tenant.sharepoint.com"
// pathname: "/sites/WebPartDev/SitePages/ECStorage.aspx"
// protocol: "https:"
// search: "?debug=true&noredir=true&debugManifestsFile=https%3A%2F%2Flocalhost%3A4321%2Ftemp%2Fmanifests.js&allowOtherSites=true&scenario=dev"
/**
*
* SEE COMMENTS AT BOTTOM OF FILE FOR WHY THIS IS HERE
*
*
*/
import { check4Gulp } from "../../../logic/Links/CheckGulping";
import { getSiteCollectionUrlFromLink } from "../../../logic/Strings/getSiteCollectionUrlFromLink";
// protocol: "https:"
export const CurrentProtocol = `${window.location.protocol}`;
export const CurrentProtocolLC = CurrentProtocol.toLocaleLowerCase();
// tenant: "tenant"
export const CurrentTenant = `${window.location.host.replace(`.sharepoint.com`, '')}`;
export const CurrentTenantLC = `${CurrentTenant.toLocaleLowerCase()}`;
// host: "tenant.sharepoint.com"
export const CurrentHost = `${window.location.host}`;
export const CurrentHostLC = `${CurrentHost.toLocaleLowerCase()}`;
// hostname: "tenant.sharepoint.com"
export const CurrentHostName = `${window.location.hostname}`;
export const CurrentHostNameLC = `${CurrentHostName.toLocaleLowerCase()}`;
// origin: "https://tenant.sharepoint.com"
export const CurrentOrigin = `${window.location.origin}`;
export const CurrentOriginLC = CurrentOrigin.toLocaleLowerCase();
// href: "https://tenant.sharepoint.com/sites/WebPartDev/SitePages/ECStorage.aspx?debug=true&noredir=true&debugManifestsFile=https%3A%2F%2Flocalhost%3A4321%2Ftemp%2Fmanifests.js&allowOtherSites=true&scenario=dev"
export const CurrentHref = `${window.location.href}`;
export const CurrentHrefLC = `${CurrentHref.toLocaleLowerCase()}`;
// origin: "https://tenant.sharepoint.com/[ sites | teams ]/YourCollectionUrl"
export const CurrentSiteAbsolute = `${getSiteCollectionUrlFromLink(CurrentHref)}`;
export const CurrentSiteAbsoluteLC = `${CurrentSiteAbsolute.toLocaleLowerCase()}`;
// pathname: "/sites/WebPartDev/SitePages/ECStorage.aspx"
export const CurrentPathname = `${window.location.pathname}`;
export const CurrentPathnameLC = `${CurrentPathname.toLocaleLowerCase()}`;
// https://github.com/mikezimm/drilldown7/issues/497
export const UrlStringsStartWith = ['http://', 'https://', '/sites/', '/teams/'];
function checkSimulatedTenant() {
// Establish the host to look for
const urlParameters = new URLSearchParams(window.location.search);
let findTenant = urlParameters.get('simulateTenant');
// Added ability to test other tenants
if (!findTenant) {
findTenant = CurrentHostLC.split('.')[0];
}
else {
if (check4Gulp() === true)
console.log('URL Params (while gulping): simulateTenant = ', findTenant);
}
return findTenant;
}
export const SimulatedTenant = checkSimulatedTenant();
export const SimulatedTenantLC = SimulatedTenant.toLocaleLowerCase();
export const SimulatedHostName = `${SimulatedTenant}.sharepoint.com`;
export const SimulatedHostNameLC = SimulatedHostName.toLocaleLowerCase();
/**
* Benefits of Centralizing window.location.XYZ ( Per ChatGPT )
1. Performance Optimization
Accessing window.location.origin involves a DOM interaction each time it's used.
By defining a const, you access a cached value, which is faster than repeatedly querying the DOM.
2. Consistency
If the origin is calculated once and reused across your app, you ensure all modules reference the same value,
preventing discrepancies caused by runtime changes.
3. Minification
During minification, a single const ensures the variable name is shortened across your app (e.g., CurrentOrigin might become a).
If you repeatedly inline window.location.origin, the minifier must keep the full property reference each time (e.g., window.location.origin).
4. Maintainability
Centralizing makes it easier to update the logic if your requirements change (e.g., including a fallback mechanism).
*/
//# sourceMappingURL=WindowLocationConstants.js.map