UNPKG

dotenv-extended

Version:

A module for loading .env files and optionally loading defaults and a schema for validating all values are present.

49 lines (39 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = exports.parseCommand = void 0; var _autoParse = _interopRequireDefault(require("auto-parse")); var _camelcase = _interopRequireDefault(require("camelcase")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } /** * Created by Keith Morris on 4/26/17. */ var dotEnvFlagRegex = /^--(.+)=(.+)/; /** * First parses config variables for dotenv-extended then selects the next item as the command and everything after that * are considered arguments for the command * * @param args * @returns {[Object,String,Array]} */ var parseCommand = function parseCommand(args) { var config = {}; var command = null; var commandArgs = []; for (var i = 0; i < args.length; i++) { var match = dotEnvFlagRegex.exec(args[i]); if (match) { config[(0, _camelcase["default"])(match[1])] = (0, _autoParse["default"])(match[2]); } else { // No more env setters, the rest of the line must be the command and args command = args[i]; commandArgs = args.slice(i + 1); break; } } return [config, command, commandArgs]; }; exports.parseCommand = parseCommand; var _default = parseCommand; exports["default"] = _default;