-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathisSPO.js
More file actions
22 lines (22 loc) · 932 Bytes
/
isSPO.js
File metadata and controls
22 lines (22 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* @name isSPO
* @category utils
* @function
* @description Return TRUE if the SharePoint is SharePoint Online
* @param {Object} settings
* @param {String} [settings.url=current] To check another URL
* @return {Boolean} Return TRUE if it's SPO or FALSE if not, or NULL is not able to determine it
*
* @note You can force an URL to be seen as SPO by defining the global variable _SP_ISSPO['url to check']=true
*/
export default function isSPO(settings) {
settings = settings||{};
let url=(settings.url || this.url || window.location.href).split("/").slice(0,3).join("/");
// check global variable
if (typeof global._SP_ISSPO[url] === "boolean") return global._SP_ISSPO[url];
// check .sharepoint.com in URL
if (url.endsWith('.sharepoint.com')) return true;
// check _spPageContextInfo
if (typeof global._spPageContextInfo === "object") return global._spPageContextInfo.isSPO || false;
return null;
}