-
Notifications
You must be signed in to change notification settings - Fork 2
/
paths.js
50 lines (40 loc) · 1.14 KB
/
paths.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var path = require('path');
var apiPath = __dirname;
var sourceDataPath = path.resolve(apiPath, 'source-data');
var titlesPath = path.resolve(apiPath, 'titles');
module.exports = {
titleByMonthFile,
titleByIssueFile,
titleIndexFile,
sourceDataFile,
sourceDataDirectory,
dateFromSourceFilename
};
function titleDirectory(titleId) {
return path.resolve(titlesPath, titleId);
}
function titleByMonthFile(titleId) {
return path.resolve(titleDirectory(titleId), 'by-month.json');
}
function titleByIssueFile(titleId) {
return path.resolve(titleDirectory(titleId), 'by-issue.json');
}
function titleIndexFile() {
return path.resolve(apiPath, 'titles.json');
}
function sourceDataFile(month, year) {
var paddedMonth = zeroPadMonth(month);
return path.resolve(sourceDataPath, `${year}-${paddedMonth}.json`);
}
function sourceDataDirectory() {
return sourceDataPath;
}
function zeroPadMonth(month) {
var string = month.toString();
return string.length == 1 ? '0' + string : string;
}
function dateFromSourceFilename(sourceFilename) {
return sourceFilename.match(/(\d{4})-(\d{2})\.json/)
.slice(1, 3)
.map(g => parseInt(g, 10));
}