UNPKG

@eclipse-emfcloud/model-validation

Version:

Generic model validation framework.

61 lines 2.01 kB
"use strict"; // ***************************************************************************** // Copyright (C) 2023-2024 STMicroelectronics. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: MIT License which is // available at https://opensource.org/licenses/MIT. // // SPDX-License-Identifier: EPL-2.0 OR MIT // ***************************************************************************** Object.defineProperty(exports, "__esModule", { value: true }); exports.severityComparator = exports.severityToNumber = void 0; /** * Obtain a numeric encoding of a `severity`. * * @param severity a severity * @returns a numeric analogue of the `severity` */ const severityToNumber = (severity) => { switch (severity) { case 'ok': return 0; case 'info': return 1; case 'warn': return 2; default: // Assume the worst for any other input return 4; } }; exports.severityToNumber = severityToNumber; /** * A comparator function for {@link Severity} values to order them * from least severe (being `'ok'`) to most severe (being `'error'`). */ const severityComparator = (a, b) => { return Math.sign((0, exports.severityToNumber)(a) - (0, exports.severityToNumber)(b)); }; exports.severityComparator = severityComparator; /** * A severity maximum function. * * @param a a severity * @param b another severity * @returns the maximum of `a` and `b` */ exports.severityComparator.max = (a, b) => { switch ((0, exports.severityComparator)(a, b)) { case -1: return b; default: return a; } }; //# sourceMappingURL=severity.js.map