UNPKG

@qudtlib/core

Version:

Data model for QUDTLib

54 lines (53 loc) 1.65 kB
export 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; } } //# sourceMappingURL=namespace.js.map