Skip to content

Commit caa2b74

Browse files
authored
Merge pull request #22 from naethiel/fix-single-digit-timecodes
Fix support for single-digit timecodes
2 parents f21cd41 + 7e51fe1 commit caa2b74

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class Parser {
9797
private tryComma(data: string) {
9898
data = data.replace(/\r/g, "");
9999
var regex =
100-
/(\d+)\n(\d{1,2}:\d{2}:\d{2},\d{1,3}) --> (\d{1,2}:\d{2}:\d{2},\d{1,3})/g;
100+
/(\d+)\n(\d{1,2}:\d{1,2}:\d{1,2},\d{1,3}) --> (\d{1,2}:\d{1,2}:\d{1,2},\d{1,3})/g;
101101
let data_array = data.split(regex);
102102
data_array.shift(); // remove first '' in array
103103
return data_array;
@@ -106,7 +106,7 @@ class Parser {
106106
private tryDot(data: string) {
107107
data = data.replace(/\r/g, "");
108108
var regex =
109-
/(\d+)\n(\d{1,2}:\d{2}:\d{2}\.\d{1,3}) --> (\d{1,2}:\d{2}:\d{2}\.\d{1,3})/g;
109+
/(\d+)\n(\d{1,2}:\d{1,2}:\d{1,2}\.\d{1,3}) --> (\d{1,2}:\d{1,2}:\d{1,2}\.\d{1,3})/g;
110110
let data_array = data.split(regex);
111111
data_array.shift(); // remove first '' in array
112112
this.seperator = ".";
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
1
2+
0:0:7,560 --> 0:0:9,700
3+
- [Adam] Hello, my name is Adam Wilbert,
4+
5+
2
6+
0:0:9,700 --> 0:0:10,520
7+
and I'd like to welcome you
8+
9+
3
10+
0:0:10,840 --> 0:0:12,530
11+
to Learning Relational Databases.
12+
13+
4
14+
0:0:12,530 --> 0:0:14,570
15+
In this course, I'm going
16+
to give you an overview
17+
18+
5
19+
0:0:15,250 --> 0:0:18,540
20+
of the planning steps that
21+
you should move through
22+
23+
6
24+
0:0:18,570 --> 0:0:21,350
25+
before you start development
26+
in order to ensure
27+
28+
7
29+
0:0:21,360 --> 0:0:22,620
30+
that your system works as expected.
31+
32+
8
33+
0:0:22,620 --> 0:0:24,830
34+
I'll start with an
35+
overview of what exactly
36+
37+
9
38+
0:0:24,830 --> 0:0:27,490
39+
a relational database is and
40+
how its structure differs
41+
42+
10
43+
0:0:27,530 --> 0:0:28,340
44+
from the spreadsheets

test/4. wrong-format.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,36 @@ describe("Test wrong format: single digit hour", function () {
6868
parser_instance.toSrt(result);
6969
});
7070
});
71+
72+
describe("Test wrong format: single digit timecodes", function () {
73+
var srt = fs.readFileSync("./test-file/single-digit-timecodes.srt", {
74+
encoding: "utf-8",
75+
});
76+
77+
chai.should();
78+
var result: Line[];
79+
var parser_instance = new parser();
80+
81+
it("parser.fromSrt() should execute without crashes", function () {
82+
result = parser_instance.fromSrt(srt);
83+
});
84+
85+
it("parser.fromSrt() should return array", function () {
86+
chai.expect(result).to.be.a("array");
87+
chai.expect(result).to.have.lengthOf(10);
88+
});
89+
90+
it("parser.fromSrt() should contain valid subtitle objects", function () {
91+
for (var i in result) {
92+
var s = result[i];
93+
chai.expect(s).to.have.property("id");
94+
chai.expect(s).to.have.property("startTime");
95+
chai.expect(s).to.have.property("endTime");
96+
chai.expect(s).to.have.property("text");
97+
}
98+
});
99+
100+
it("parser.toSrt() should execute without crashes", function () {
101+
parser_instance.toSrt(result);
102+
});
103+
});

0 commit comments

Comments
 (0)