UNPKG

@itwin/presentation-common

Version:

Common pieces for iModel.js presentation packages

85 lines 3.23 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Core */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DiagnosticsLogEntry = void 0; exports.combineDiagnosticsSeverities = combineDiagnosticsSeverities; exports.compareDiagnosticsSeverities = compareDiagnosticsSeverities; /** * Returns lower severity of the given two. Examples: * ``` * combineDiagnosticsSeverities("error", "error") === "error" * combineDiagnosticsSeverities("error", "debug") === "debug" * combineDiagnosticsSeverities("debug", "error") === "debug" * ``` * @internal */ function combineDiagnosticsSeverities(lhs, rhs) { if (!lhs && !rhs) { return undefined; } const combinedSeverity = lhs === "trace" || rhs === "trace" ? "trace" : lhs === "debug" || lhs === true || rhs === "debug" || rhs === true ? "debug" : lhs === "info" || rhs === "info" ? "info" : lhs === "warning" || rhs === "warning" ? "warning" : "error"; return combinedSeverity; } /** * Returns 0 if the given severities are equal after normalization, negative if `lhs` is lower, positive if higher. Examples: * ``` * compareDiagnosticsSeverities("error", "error") === 0 * compareDiagnosticsSeverities("error", false) === 0 * compareDiagnosticsSeverities("error", undefined) === 0 * compareDiagnosticsSeverities("debug", true) === 0 * compareDiagnosticsSeverities("debug", "error") < 0 * compareDiagnosticsSeverities("error", "debug") > 0 * ``` * @internal */ function compareDiagnosticsSeverities(lhs, rhs) { const normalizedLhs = lhs === undefined || lhs === false ? "error" : lhs === true ? "debug" : lhs; const normalizedRhs = rhs === undefined || rhs === false ? "error" : rhs === true ? "debug" : rhs; if (normalizedLhs === normalizedRhs) { return 0; } if (normalizedLhs === "error") { return 1; } if (normalizedLhs === "warning") { return normalizedRhs === "error" ? -1 : 1; } if (normalizedLhs === "info") { return normalizedRhs === "warning" || normalizedRhs === "error" ? -1 : 1; } if (normalizedLhs === "debug") { return normalizedRhs === "info" || normalizedRhs === "warning" || normalizedRhs === "error" ? -1 : 1; } return -1; } /** * Functions related to diagnostics log entry. * @public */ // eslint-disable-next-line @typescript-eslint/no-redeclare var DiagnosticsLogEntry; (function (DiagnosticsLogEntry) { function isMessage(entry) { return !!entry.message; } DiagnosticsLogEntry.isMessage = isMessage; function isScope(entry) { return !!entry.scope; } DiagnosticsLogEntry.isScope = isScope; })(DiagnosticsLogEntry || (exports.DiagnosticsLogEntry = DiagnosticsLogEntry = {})); //# sourceMappingURL=Diagnostics.js.map