-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
37 lines (31 loc) · 731 Bytes
/
helpers.js
File metadata and controls
37 lines (31 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
function any(promises) {
if(promises.length < 1) {
return Promise.resolve(false);
}
return Promise.all(
promises.map(p =>
p
.catch(err => {
console.log('Underlying promise rejected', err);
return false;
})
.then(result => {
if(result) {
throw new Error('authorized');
}
})
)
)
.then(() => false)
.catch(err => err && err.message === 'authorized');
}
function isGlob(string) {
return string.includes('*');
}
function globToRegex(string) {
return new RegExp(string.replace(/\*/g, '.*'));
}
module.exports.any = any;
module.exports.isGlob = isGlob;
module.exports.globToRegex = globToRegex;