Skip to content

Commit

Permalink
fix: href property issue in gatsby build
Browse files Browse the repository at this point in the history
  • Loading branch information
Syed-Ali-Abbas-Zaidi committed Oct 13, 2023
1 parent a5917c2 commit 38ab823
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,13 @@ export function convertKeyNames(object, nameMap) {
* @returns {Object}
*/
export function parseURL(url) {
const parser = document?.createElement('a');
parser.href = url;
return parser;
if (typeof document !== 'undefined') {
const parser = document?.createElement('a');
parser.href = url;
return parser;
}

return null;

Check warning on line 147 in src/utils.js

View check run for this annotation

Codecov / codecov/patch

src/utils.js#L147

Added line #L147 was not covered by tests
}

/**
Expand All @@ -151,7 +155,7 @@ export function parseURL(url) {
* @returns {string}
*/
export function getPath(url) {
return parseURL(url).pathname;
return parseURL(url)?.pathname;
}

/**
Expand Down

0 comments on commit 38ab823

Please sign in to comment.