enigma-bbs/core/misc_util.js

30 lines
778 B
JavaScript
Raw Normal View History

/* jslint node: true */
'use strict';
2014-10-17 02:21:06 +00:00
var paths = require('path');
2014-10-17 02:21:06 +00:00
exports.isProduction = isProduction;
exports.isDevelopment = isDevelopment;
exports.valueWithDefault = valueWithDefault;
exports.resolvePath = resolvePath;
function isProduction() {
var env = process.env.NODE_ENV || 'dev';
return 'production' === env;
}
2014-10-17 02:21:06 +00:00
function isDevelopment() {
return (!(isProduction()));
}
2014-10-17 02:21:06 +00:00
function valueWithDefault(val, defVal) {
return (typeof val !== 'undefined' ? val : defVal);
}
2014-10-17 02:21:06 +00:00
function resolvePath(path) {
if(path.substr(0, 2) === '~/') {
var mswCombined = process.env.HOMEDRIVE + process.env.HOMEPATH;
path = (process.env.HOME || mswCombined || process.env.HOMEPATH || process.env.HOMEDIR || process.cwd()) + path.substr(1);
2014-10-17 02:21:06 +00:00
}
return paths.resolve(path);
}