UNPKG

2.45 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2023 Ericsson and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.Prioritizeable = void 0;
19var Prioritizeable;
20(function (Prioritizeable) {
21 async function toPrioritizeable(rawValue, getPriority) {
22 if (rawValue instanceof Array) {
23 return Promise.all(rawValue.map(v => toPrioritizeable(v, getPriority)));
24 }
25 const value = await rawValue;
26 const priority = await getPriority(value);
27 return { priority, value };
28 }
29 Prioritizeable.toPrioritizeable = toPrioritizeable;
30 function toPrioritizeableSync(rawValue, getPriority) {
31 return rawValue.map(v => ({
32 value: v,
33 priority: getPriority(v)
34 }));
35 }
36 Prioritizeable.toPrioritizeableSync = toPrioritizeableSync;
37 function prioritizeAllSync(values, getPriority) {
38 const prioritizeable = toPrioritizeableSync(values, getPriority);
39 return prioritizeable.filter(isValid).sort(compare);
40 }
41 Prioritizeable.prioritizeAllSync = prioritizeAllSync;
42 async function prioritizeAll(values, getPriority) {
43 const prioritizeable = await toPrioritizeable(values, getPriority);
44 return prioritizeable.filter(isValid).sort(compare);
45 }
46 Prioritizeable.prioritizeAll = prioritizeAll;
47 function isValid(p) {
48 return p.priority > 0;
49 }
50 Prioritizeable.isValid = isValid;
51 function compare(p, p2) {
52 return p2.priority - p.priority;
53 }
54 Prioritizeable.compare = compare;
55})(Prioritizeable = exports.Prioritizeable || (exports.Prioritizeable = {}));
56//# sourceMappingURL=prioritizeable.js.map
\No newline at end of file