Skip to content

Instantly share code, notes, and snippets.

@Siilwyn
Last active April 26, 2024 08:05
Show Gist options
  • Save Siilwyn/4c15a2831defcde948557195d8018865 to your computer and use it in GitHub Desktop.
Save Siilwyn/4c15a2831defcde948557195d8018865 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