UNPKG

detect-environment

Version:

Detect environments in JavaScript similar to the way Laravel does

90 lines (68 loc) 1.98 kB
'use strict'; var /** * */ createPathsArray = function createPathsArray (options, envName) { // if (!options.baseEnv || typeof options.baseEnv !== 'string') { throw new TypeError('createPathsArray:'); } // if (!options.baseName || typeof options.baseName !== 'string') { throw new TypeError('createPathsArray:'); } // if (options.hidden !== true && options.hidden !== false) { throw new TypeError('createPathsArray:'); } // if (typeof options.extensions === 'string') { options.extensions = [options.extensions]; } // if (!options.extensions) { throw new TypeError('createPathsArray:'); } // if (!Array.isArray(options.extensions)) { throw new TypeError('createPathsArray:'); } // if (options.extensions.length === 0) { throw new TypeError('createPathsArray:'); } // if (!envName || typeof envName !== 'string') { throw new TypeError('createPathsArray:'); } var // pre = (options.hidden ? '.' : '') + options.baseName, // result; // if (envName === options.baseEnv) { envName = ''; // } else { envName = '.' + envName; } // result = options.extensions.map(function (extension) { // if (typeof extension !== 'string') { throw new TypeError('createPathsArray:'); } // if (extension && extension.charAt(0) !== '.') { extension = '.' + extension; } // return pre + envName + extension; }); // return result; }; // Expose to node.js module.exports = createPathsArray;