-
-
Save theskillwithin/ffe7923c6e2ed7aec2b6162a3538d843 to your computer and use it in GitHub Desktop.
Multiple ways to handle the platform: switch vs. if...else vs. object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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