All files / publisher/listing/utils addDateToFilename.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8  1x 1x 1x 1x 1x    
export default function addDateToFilename(file: File, date: Date): File {
  const now = Math.round(date.getTime() / 1000);
  const nameParts = file.name.split(".");
  const extension = nameParts.pop();
  const newName = `${nameParts.join(".")}-${now}.${extension}`;
  return new File([file], newName);
}