mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-23 00:45:16 +00:00
24 lines
725 B
JavaScript
24 lines
725 B
JavaScript
/**
|
|
* Prettify a filename from error stacks into the desired format.
|
|
* @param {string} filename The filename to be formatted.
|
|
* @returns {string} The formatted filename.
|
|
*/
|
|
function formatFilename(filename) {
|
|
// Strip away protocol and domain for compiled files
|
|
const htmlMatch = /^https?:\/\/(.*)\/(.*)/.exec(filename);
|
|
if (htmlMatch && htmlMatch[1] && htmlMatch[2]) {
|
|
return htmlMatch[2];
|
|
}
|
|
|
|
// Strip everything before the first directory for source files
|
|
const sourceMatch = /\/.*?([^./]+[/|\\].*)$/.exec(filename);
|
|
if (sourceMatch && sourceMatch[1]) {
|
|
return sourceMatch[1].replace(/\?$/, '');
|
|
}
|
|
|
|
// Unknown filename type, use it as is
|
|
return filename;
|
|
}
|
|
|
|
module.exports = formatFilename;
|