-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1318 from lindapaiste/fix/guard-window-variable
guard all `window` references
- Loading branch information
Showing
4 changed files
with
29 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
/** | ||
* Check if the provided URL string starts with a hostname, | ||
* such as http://, https://, etc. | ||
* @param {string} str | ||
* @returns {boolean} | ||
*/ | ||
function isAbsoluteURL(str) { | ||
const pattern = new RegExp('^(?:[a-z]+:)?//', 'i'); | ||
return !!pattern.test(str); | ||
return pattern.test(str); | ||
} | ||
|
||
/** | ||
* Accepts a URL that may be a complete URL, or a relative location. | ||
* Returns an absolute URL based on the current window location. | ||
* @param {string} absoluteOrRelativeUrl | ||
* @returns {string} | ||
*/ | ||
function getModelPath(absoluteOrRelativeUrl) { | ||
const modelJsonPath = isAbsoluteURL(absoluteOrRelativeUrl) ? absoluteOrRelativeUrl : window.location.pathname + absoluteOrRelativeUrl | ||
return modelJsonPath; | ||
if (!isAbsoluteURL(absoluteOrRelativeUrl) && typeof window !== 'undefined') { | ||
return window.location.pathname + absoluteOrRelativeUrl; | ||
} | ||
return absoluteOrRelativeUrl; | ||
} | ||
|
||
export default { | ||
isAbsoluteURL, | ||
getModelPath | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters