Skip to content

Commit

Permalink
Better filenames to save to disk.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Sep 14, 2016
1 parent 5b46b4c commit c2126c0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lighthouse-core/lib/asset-saver.js
Expand Up @@ -21,11 +21,15 @@ const log = require('../../lighthouse-core/lib/log.js');
const stringify = require('json-stringify-safe');

function getFilenamePrefix(options) {
const date = options.date || new Date();
const url = options.url;

const hostname = url.match(/^.*?\/\/(.*?)(:?\/|$)/)[1];
const filenamePrefix = hostname + '_' + date.toISOString();

const date = options.date || new Date();
const resolvedLocale = new Intl.DateTimeFormat().resolvedOptions().locale;
const time = date.toLocaleTimeString(resolvedLocale, {hour12: false});
const timeStampStr = date.toISOString().replace(/T.*/, '_' + time);

const filenamePrefix = hostname + '_' + timeStampStr;
// replace characters that are unfriendly to filenames
return (filenamePrefix).replace(/[\/\?<>\\:\*\|":]/g, '-');
}
Expand Down

0 comments on commit c2126c0

Please sign in to comment.