1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.Prioritizeable = void 0;
|
19 | var 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 |
|
\ | No newline at end of file |