-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathImage.js
43 lines (36 loc) · 1.38 KB
/
Image.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
import { DomainError } from '../../../../shared/domain/errors.js';
import { assertNotNullOrUndefined } from '../../../../shared/domain/models/asserts.js';
import { Element } from './Element.js';
class Image extends Element {
static #VALID_PRODUCTION_HOSTNAME = 'assets.pix.org';
/**
* @param{object} params
* @param{string} params.id
* @param{string} params.url
* @param{string} params.alt
* @param{string} params.alternativeText
* @param{string} params.legend
* @param{string} params.licence
* @param{boolean} params.isBeta
*/
constructor({ id, url, alt, alternativeText, legend, licence, isBeta = true }) {
super({ id, type: 'image' });
assertNotNullOrUndefined(url, 'The URL is required for an image');
if (!URL.canParse(url)) {
throw new DomainError('The URL must be a valid URL for an image');
}
assertNotNullOrUndefined(alt, 'The alt text is required for an image');
assertNotNullOrUndefined(alternativeText, 'The alternative text is required for an image');
this.url = url;
this.alt = alt;
this.alternativeText = alternativeText;
this.legend = legend;
this.licence = licence;
if (!isBeta) {
if (URL.parse(url).hostname !== Image.#VALID_PRODUCTION_HOSTNAME) {
throw new DomainError('The image URL must be from "assets.pix.org" when module is production ready');
}
}
}
}
export { Image };