const urlUtils = { getUrl: function getUrl(pathName) { // given a path name starting with '/' return a full URL for this site //log('getUrl: enter'); //log('getUrl: pathName=' + pathName); var baseURL = location.origin; var theUrl = ''; if (baseURL === 'file://') { // if running locally //log('getUrl: site is running locally'); const href = location.href; // get the path to the current page, eg // file:///C:/Data/MM2019/LenseBrowserWeb/lenses.html const where = href.lastIndexOf('/'); // get the zero-based index to the last forward slash in the path baseURL = href.substring(0, where); // truncate the final slash and page name from the base URL theUrl = baseURL + pathName; // append the path } else { // if running in a web server //log('getUrl: site is running on a web server'); theUrl = baseURL + pathName; } //log('getUrl: theUrl=' + theUrl); //log('getUrl: leave'); return theUrl; }, getFilePath: function getFilePath(url) { log('getFilePath: enter'); log('getFilePath: url=' + url); const where = url.lastIndexOf('/'); const filePath = url.substring(where); log('getFilePath: filePath=' + filePath); log('getFilePath: leave'); return filePath; } };