UNPKG

@kit-data-manager/pid-component

Version:

The PID-Component is a web component that can be used to evaluate and display FAIR Digital Objects, PIDs, ORCiDs, and possibly other identifiers in a user-friendly way. It is easily extensible to support other identifier types.

53 lines (52 loc) 1.86 kB
/*! * * Copyright 2024 Karlsruhe Institute of Technology. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import { renderers } from "./utils"; export class Parser { static getEstimatedPriority(value) { let priority = 0; for (let i = 0; i < renderers.length; i++) { const obj = new renderers[i].constructor(value); if (obj.hasCorrectFormat()) { priority = i; break; } } return priority; } static async getBestFit(value, settings) { var _a; let bestFit = new renderers[renderers.length - 1].constructor(value); for (let i = renderers.length - 1; i >= 0; i--) { const obj = new renderers[i].constructor(value); if (obj.hasCorrectFormat()) bestFit = obj; } try { const settingsKey = bestFit.getSettingsKey(); const settingsValues = (_a = settings.find(value => value.type === settingsKey)) === null || _a === void 0 ? void 0 : _a.values; if (settingsValues) bestFit.settings = settingsValues; } catch (e) { console.warn('Error while adding settings to object:', e); } await bestFit.init(); return bestFit; } } //# sourceMappingURL=Parser.js.map