-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
72 lines (66 loc) · 2.2 KB
/
index.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"use strict";
const xre = require("xregexp");
const debug = require("debug")("deb-changelog");
class ChangeLog {
constructor(blob) {
this.blob = blob;
}
parseBody(stanza) {
let bodyRe = xre("\\*\\s(?<body>[^\\*-]*)", "img");
let matches = [];
xre.forEach(stanza, bodyRe, (match, i) => {
debug(i);
return matches.push(match.body.trim());
});
return Promise.all(matches);
}
chunk() {
let bodyRe = xre("[-\+]\\d{4}", "mg");
let matches = [];
let currentIdx = 0;
xre.forEach(this.blob, bodyRe, (match, i) => {
debug("iter: %s", i);
let endIdx = match.index + 6;
matches.push(match.input.slice(currentIdx, endIdx).trim());
currentIdx = endIdx + 1;
});
debug(matches);
return Promise.all(matches);
}
parse(stanza) {
let entryRe = xre("^(?<pkgname>\\w+)" +
"\\s" +
"\\(" +
"(?<version>[0-9\\-\\.\\+]+)" +
"(?<versionExtra>[\\w\\d\\~\\-\\.\\+]+)" +
"\\)" +
"\\s" +
"(?<series>\\w+);\\surgency=(?<priority>\\w+)" +
"\\s[^]*" +
"--\\s(?<firstname>\\w+)" +
"\\s" +
"(?<lastname>\\w+)" +
"\\s" +
"(?<email><.*>)" +
"\\s+" +
"(?<timestamp>.*)", "img");
let match = xre.exec(stanza, entryRe);
let model = {
pkgname: match.pkgname,
version: match.version,
versionExtra: match.versionExtra,
series: match.series,
priority: match.priority,
firstname: match.firstname,
lastname: match.lastname,
email: match.email,
timestamp: match.timestamp
};
this.parseBody(stanza)
.then((res) => {
model.body = res;
});
return Promise.resolve(model);
}
}
module.exports = ChangeLog;