UNPKG

@chix/config

Version:

Configuration File Handler

47 lines 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var os = require("os"); var path = require("path"); function darwin(name) { if (process.env.HOME) { return path.join(process.env.HOME, 'Library', 'Application Support', name); } throw Error('HOME directory is not set.'); } exports.darwin = darwin; function linux(name) { if (process.env.XDG_CONFIG_HOME) { return path.join(process.env.XDG_CONFIG_HOME, name); } if (process.env.HOME) { return path.join(process.env.HOME, '.config', name); } throw Error('HOME directory is not set.'); } exports.linux = linux; function win32(name) { if (process.env.LOCALAPPDATA) { return path.join(process.env.LOCALAPPDATA, name); } if (process.env.USERPROFILE) { return path.join(process.env.USERPROFILE, 'Local Settings', 'Application Data', name); } throw Error('Neither LOCALAPPDATA or USERPROFILE are set.'); } exports.win32 = win32; function configPath(name) { if (typeof name !== 'string') { throw new TypeError('`name` must be string'); } switch (os.platform()) { case 'darwin': return darwin(name); case 'linux': return linux(name); case 'win32': return win32(name); } throw new Error('Platform not supported'); } exports.configPath = configPath; //# sourceMappingURL=configPath.js.map