1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.compare = compare;
|
7 | exports.wait = wait;
|
8 | exports.timeout = timeout;
|
9 | exports.undefault = undefault;
|
10 | const debug = require('debug')('util');
|
11 |
|
12 | function compare(...props) {
|
13 | return (a, b) => {
|
14 | for (let prop of props) {
|
15 | if (a[prop] === undefined) return -1;
|
16 | if (b[prop] === undefined) return 1;
|
17 | if (a[prop] < b[prop]) return -1;
|
18 | if (a[prop] > b[prop]) return 1;
|
19 | }
|
20 | return 0;
|
21 | };
|
22 | }
|
23 |
|
24 | function wait(ms, unref = false) {
|
25 | return new Promise(resolve => {
|
26 | let t = setTimeout(resolve, ms);
|
27 | if (unref) t.unref();
|
28 | });
|
29 | }
|
30 |
|
31 | function timeout(p, ms) {
|
32 | return Promise.race([p, wait(ms, true).then(() => debug('timed out'))]);
|
33 | }
|
34 |
|
35 | function undefault(m) {
|
36 | return m.default ? m.default : m;
|
37 | } |
\ | No newline at end of file |