-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBuilder.ts
53 lines (46 loc) · 1.12 KB
/
Builder.ts
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
enum ImageFormat {
Png = 'png',
Jpeg = 'jpeg'
}
interface IResolution {
width: number;
height: number
}
interface IImageConversion extends IResolution {
format: ImageFormat
}
class ImageBuilder {
private formats: ImageFormat[] = []
private resolutions: IResolution[] = []
addPng() {
if (this.formats.includes(ImageFormat.Png)) {
return this
}
this.formats.push(ImageFormat.Png);
return this
}
addJpeg() {
if (this.formats.includes(ImageFormat.Jpeg)) {
return this
}
this.formats.push(ImageFormat.Jpeg);
return this
}
addResolution(width: number, height: number) {
this.resolutions.push({ width, height})
return this
}
build(): IImageConversion[] {
const res: IImageConversion[] = []
for (const r of this.resolutions) {
for (const f of this.formats) {
res.push({
format: f,
width: r.width,
height: r.height
})
}
}
return res
}
}