UNPKG

@qudtlib/core

Version:

Data model for QUDTLib

58 lines (57 loc) 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Namespace = void 0; class Namespace { constructor(baseIri, abbreviationPrefix) { this.abbreviationPrefix = abbreviationPrefix; this.baseIri = baseIri; Object.freeze(this); } /** * Returns an abbreviated IRI if the specified iri starts with the baseIri; the unchanged input * String otherwise; * * @param iri * @return */ abbreviate(iri) { if (this.isFullNamespaceIri(iri)) { return this.abbreviationPrefix + ":" + iri.substring(this.baseIri.length); } return iri; } getLocalnameIfFullNamespaceIri(iri) { if (this.isFullNamespaceIri(iri)) { return iri.substring(this.baseIri.length); } return iri; } expand(abbreviatedIri) { if (this.isAbbreviatedNamespaceIri(abbreviatedIri)) { return (this.baseIri + abbreviatedIri.substring(this.abbreviationPrefix.length + 1)); } return abbreviatedIri; } /** * Returns true if the specified abbreviatedIri starts with the namespace's abbreviation prefix. */ isAbbreviatedNamespaceIri(abbreviatedIri) { return abbreviatedIri.startsWith(this.abbreviationPrefix + ":"); } /** Returns true if the specified iri starts with the namespace's baseIri. */ isFullNamespaceIri(iri) { return iri.startsWith(this.baseIri); } /** * Prepends the namespace's baseIri to the specified localName. * * @param localName * @return */ makeIriInNamespace(localName) { return this.baseIri + localName; } } exports.Namespace = Namespace; //# sourceMappingURL=namespace.js.map