-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiles.js
52 lines (43 loc) · 1.15 KB
/
profiles.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
var fs = require('fs');
function requireIf(path) {
if (fs.existsSync(path)) {
console.log('🔍 Found ' + path);
return require(path);
}
return null;
}
function notFoundError(profile) {
return new Error('Profile "' + profile + '" not found' );
}
function getHeadersForModheaderProfile(profile) {
return profile.headers || [];
}
function getHeadersForCustomProfile(profile) {
return Object.keys(profile).map(function makeHeaders(key){
return {
name: key,
value: profile[key]
};
});
}
function getHeadersForProfile(profile) {
if (profile && profile.title && profile.headers) {
return getHeadersForModheaderProfile(profile);
} else if (profile) {
return getHeadersForCustomProfile(profile);
}
throw notFoundError(profileTitle);
}
function getHeadersForUser(user) {
var profile = requireIf('./profiles/' + user + '.json');
return getHeadersForProfile(profile);
}
function getHeadersForFilename(filename) {
var profile = requireIf(filename);
return getHeadersForProfile(profile);
}
module.exports = {
getHeadersForUser: getHeadersForUser,
getHeadersForFilename: getHeadersForFilename
}