Skip to content

Instantly share code, notes, and snippets.

@theskillwithin
Forked from Siilwyn/if.js
Created November 15, 2016 21:18
Show Gist options
  • Save theskillwithin/ffe7923c6e2ed7aec2b6162a3538d843 to your computer and use it in GitHub Desktop.
Save theskillwithin/ffe7923c6e2ed7aec2b6162a3538d843 to your computer and use it in GitHub Desktop.
Multiple ways to handle the platform: switch vs. if...else vs. object
var getConfigDirectory = function () {
var platform = process.platform;
if (platform === 'linux') {
return process.env.XDG_CONFIG_HOME || path.join(home(), '.config')
}
else if (platform === 'darwin') {
return path.join(home(), 'Library', 'Preferences');
}
else if (platform === 'win32') {
return path.join(home(), 'AppData', 'Roaming');
}
else {
return home();
}
}
var getConfigDirectory = function () {
var configPaths = {
'linux': process.env.XDG_CONFIG_HOME || path.join(home(), '.config'),
'darwin': path.join(home(), 'Library', 'Preferences'),
'win32': path.join(home(), 'AppData', 'Roaming'),
'default': home()
};
return configPaths[process.platform] || paths.default;
}
var getConfigDirectory = function () {
switch (process.platform) {
case 'linux': return process.env.XDG_CONFIG_HOME || path.join(home(), '.config')
case 'darwin': return path.join(home(), 'Library', 'Preferences');
case 'win32': return path.join(home(), 'AppData', 'Roaming');
default: return home();
}
}
var getConfigDirectory = function () {
switch (process.platform) {
case 'linux':
return process.env.XDG_CONFIG_HOME || path.join(home(), '.config')
case 'darwin':
return path.join(home(), 'Library', 'Preferences');
case 'win32':
return path.join(home(), 'AppData', 'Roaming');
default:
return home();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment