source: trip-planner-front/node_modules/streamroller/lib/fileNameFormatter.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 883 bytes
Line 
1const debug = require("debug")("streamroller:fileNameFormatter");
2const path = require("path");
3const FILENAME_SEP = ".";
4const ZIP_EXT = ".gz";
5
6module.exports = ({
7 file,
8 keepFileExt,
9 needsIndex,
10 alwaysIncludeDate,
11 compress
12}) => {
13 const dirAndName = path.join(file.dir, file.name);
14
15 const ext = f => f + file.ext;
16
17 const index = (f, i, d) =>
18 (needsIndex || !d) && i ? f + FILENAME_SEP + i : f;
19
20 const date = (f, i, d) => {
21 return (i > 0 || alwaysIncludeDate) && d ? f + FILENAME_SEP + d : f;
22 };
23
24 const gzip = (f, i) => (i && compress ? f + ZIP_EXT : f);
25
26 const parts = keepFileExt
27 ? [date, index, ext, gzip]
28 : [ext, date, index, gzip];
29
30 return ({ date, index }) => {
31 debug(`_formatFileName: date=${date}, index=${index}`);
32 return parts.reduce(
33 (filename, part) => part(filename, index, date),
34 dirAndName
35 );
36 };
37};
Note: See TracBrowser for help on using the repository browser.