UNPKG

lincd

Version:

LINCD is a JavaScript library for building user interfaces with linked data (also known as 'structured data', or RDF)

77 lines 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Prefix = void 0; /* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ const CoreMap_1 = require("../collections/CoreMap"); class Prefix { static getUriToPrefixMap() { return this.uriToPrefix; } static getPrefixToUriMap() { return this.prefixToUri; } static add(prefix, fullURI) { this.uriToPrefix.set(fullURI, prefix); this.prefixToUri.set(prefix, fullURI); } static delete(prefix) { if (this.prefixToUri.has(prefix)) { let fullURI = this.getFullURI(prefix); this.uriToPrefix.delete(fullURI); this.prefixToUri.delete(prefix); } } static clear() { this.uriToPrefix = new CoreMap_1.CoreMap(); this.prefixToUri = new CoreMap_1.CoreMap(); } static getPrefix(fullURI) { if (this.uriToPrefix.has(fullURI)) { return this.uriToPrefix.get(fullURI); } let match = this.findMatch(fullURI); if (match.length > 0) return match[1]; } static getFullURI(prefix) { return this.prefixToUri.get(prefix); } static findMatch(fullURI) { for (let [ontologyURI, prefix] of this.uriToPrefix.entries()) { if (fullURI.substring(0, ontologyURI.length) == ontologyURI) { return [ontologyURI, prefix, fullURI.substring(ontologyURI.length)]; } } return []; } static toPrefixed(fullURI) { let match = this.findMatch(fullURI); if (match.length > 0) { return match[1] + ':' + fullURI.substr(match[0].length); } } static toPrefixedIfPossible(fullURI) { return this.toPrefixed(fullURI) || fullURI; } /** * Converts a prefixed URI back to its full URI * Will return the prefixed URI if no prefix was found * @param uri */ static toFull(uri) { let [prefix, rest] = uri.split(':'); let ontologyURI = this.getFullURI(prefix); if (ontologyURI) { return ontologyURI + rest; } throw new Error('Unknown prefix ' + prefix + '. Could not convert ' + uri + ' to a full URI'); } } exports.Prefix = Prefix; Prefix.uriToPrefix = new CoreMap_1.CoreMap(); Prefix.prefixToUri = new CoreMap_1.CoreMap(); //# sourceMappingURL=Prefix.js.map