UNPKG

1.28 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const uriTemplate = require("uri-template");
4const url_1 = require("./utils/url");
5/**
6 * The Link object represents a hyperlink.
7 */
8class Link {
9 constructor(properties) {
10 this.templated = false;
11 this.title = null;
12 this.type = null;
13 for (const key of ['context', 'href', 'name', 'rel', 'templated', 'title', 'type']) {
14 if (properties[key]) {
15 this[key] = properties[key];
16 }
17 }
18 }
19 /**
20 * Returns the absolute link url, based on it's base and relative url.
21 */
22 resolve() {
23 return url_1.resolve(this.context, this.href);
24 }
25 /**
26 * Expands a link template (RFC6570) and resolves the uri
27 *
28 * @param {object} variables - A list of variables to expand the link with.
29 * @returns {string}
30 */
31 expand(variables) {
32 if (!this.templated) {
33 return url_1.resolve(this.context, this.href);
34 }
35 else {
36 const templ = uriTemplate.parse(this.href);
37 const expanded = templ.expand(variables);
38 return url_1.resolve(this.context, expanded);
39 }
40 }
41}
42exports.default = Link;
43//# sourceMappingURL=link.js.map
\No newline at end of file