forked from tldr-pages/tldr-node-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform.js
39 lines (33 loc) · 857 Bytes
/
platform.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
'use strict';
const os = require('os');
const folders = {
'osx': 'osx',
'darwin': 'osx',
'linux': 'linux',
'sunos': 'sunos',
'windows': 'windows',
'win32': 'windows'
};
// Check if the platform is there in the list of platforms or not
function isSupported(platform) {
return Object.prototype.hasOwnProperty.call(folders, platform);
}
// If the platform given in config is present, return that.
// Else, return the system platform
function getPreferredPlatform(config) {
let platform = config.platform;
if (isSupported(platform)) {
return platform;
}
return os.platform();
}
// Get the folder name for a platform
function getPreferredPlatformFolder(config) {
let platform = getPreferredPlatform(config);
return folders[platform];
}
module.exports = {
isSupported,
getPreferredPlatform,
getPreferredPlatformFolder
};