Link.ts 734 Bytes
Newer Older
Hanadi's avatar
Hanadi committed
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
import {RelationshipLink} from "./RelationshipLink";
import {Type} from "./Type";
import {validateRequiredFields} from "./Helpers";

export class Link {
    title?: string;
    href!: string;
    rel!: RelationshipLink;
    type?: Type;
    hreflang?: string;

    static fromJson(jsonObj: any): Link {
        validateRequiredFields(jsonObj, ["href", "rel"], Link.name);
        let link = new Link();
        link.href = jsonObj["href"];
        link.rel = jsonObj["rel"];
        if ("title" in jsonObj)
            link.title = jsonObj["title"];
        if ("type" in jsonObj)
            link.type = jsonObj["type"];
        if ("hreflang" in jsonObj)
            link.hreflang = jsonObj["hreflang"];
        return link;
    }
}