Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "hlx-util", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A library to preserve functions commonly used in hlxjs project", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
36
utils.js
@@ -86,19 +86,17 @@ const {URL} = require('url'); | ||
function buildLocalPathFromUrl(url) { | ||
function buildUrlObj(url, base) { | ||
const obj = tryCatch( | ||
() => new URL(url), | ||
() => new URL(url, base), | ||
() => null | ||
); | ||
if (!obj) { | ||
return ''; | ||
if (obj) { | ||
obj.search = ''; | ||
obj.hash = ''; | ||
if (obj.hostname && !obj.pathname.startsWith(obj.hostname, 1)) { | ||
obj.pathname = path.join('/', obj.hostname, obj.pathname); | ||
} | ||
} | ||
obj.search = ''; | ||
obj.hash = ''; | ||
if (obj.protocol === 'file:') { | ||
return obj.pathname; | ||
} | ||
return path.join('/', obj.hostname, obj.pathname); | ||
return obj; | ||
} | ||
@@ -116,2 +114,3 @@ | ||
let localPath; | ||
let obj; | ||
if (path.isAbsolute(uri)) { | ||
@@ -122,11 +121,12 @@ localPath = path.join(outputDir, uri); | ||
} | ||
localPath = buildLocalPathFromUrl(uri); | ||
if (localPath) { | ||
localPath = buildAbsolutePath(localPath, '/', inputDir, outputDir); | ||
obj = buildUrlObj(uri); | ||
if (obj) { | ||
localPath = buildAbsolutePath(obj.pathname, '/', inputDir, outputDir); | ||
print(`\tFrom absolute url to localPath: ${localPath}`); | ||
return localPath; | ||
} | ||
const basePath = buildLocalPathFromUrl(parentUri); | ||
if (basePath) { | ||
localPath = buildAbsolutePath(uri, basePath, inputDir, outputDir); | ||
obj = buildUrlObj(parentUri); | ||
if (obj) { | ||
obj = buildUrlObj(uri, obj.href); | ||
localPath = buildAbsolutePath(obj.pathname, '/', inputDir, outputDir); | ||
print(`\tFrom relative url to localPath: ${localPath}`); | ||
@@ -149,4 +149,4 @@ return localPath; | ||
mkdirP, | ||
buildLocalPathFromUrl, | ||
buildUrlObj, | ||
buildLocalPath | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6275
149