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,GAIhC,EAAQ,GAAO,EACf,EAAS,KAAM,EAAI,EACrB,GACF,EAOA,EAAO,SAAU,EAAK,GAChB,EAAI,GACF,SACF,QAAQ,MAEV,EAAO,EAAG,KAEV,EAAG,QACH,EAAS,KAAM,GAEnB,EAEA,EAAK,EAAS,gBAAgB,CAC5B,MAAO,QAAQ,MACf,OAAQ,QAAQ,SAGlB,EAAO,EAAG,EACZ,EAEA,QAAQ,IAAM,CAChB,CA9IA","file":"/npm/askr@0.2.7/lib/askr.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/askr@0.2.7/lib/askr.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// Copyright (c) 2014 Romain Francez and other askr contributors.\n//\n// This file is part of askr.\n//\n// askr is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, version 3 of the License.\n//\n// askr is distributed in the hope that it will be useful,\n// but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT\n// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\n// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE. See the GNU General Public License\n// for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with askr. If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.\n\n/**\n * @file Askr\n * @author Romain Francez\n *   {@link https://github.com/romainfrancez|@romainfrancez}\n */\n(function () {\n  'use strict';\n\n  var\n    blackhole = require('blackhole'),\n    mustache = require('mustache'),\n    readline = require('readline'),\n\n    ask,\n    getCaseInsensitiveMatch;\n\n  /**\n   * @param {Array} array the different values to match against\n   * @param {String} value the value to match\n   * @returns {String} the value of array that matches value\n   */\n  getCaseInsensitiveMatch = function (array, value) {\n    var\n      l = array.length,\n      lowerCaseValue = value.toLowerCase();\n\n    while (l) {\n      l -= 1;\n      if (array[l].toLowerCase() === lowerCaseValue) {\n        return array[l];\n      }\n    }\n  };\n\n  /**\n   * Asks questions and call callback on completion\n   * @param {Object} questions questions to ask\n   * @param {Object} answers if some answers are already answered,\n   *   will skip them\n   * @param {Function} callback the function to call on completion\n   */\n  ask = function (questions, answers, callback) {\n    var\n      askOne,\n      keys = Object.keys(questions),\n      l = keys.length,\n      next,\n      rl;\n    \n    if (typeof answers === 'function') {\n      callback = answers;\n      answers = {};\n    }\n\n    callback = callback || blackhole;\n\n    if (l === 0) {\n      return callback(null, answers);\n    }\n\n    /**\n     * Asks a question and processes the answer\n     * @param {Number} i the question number that is asked\n     * @param {Function} [callback] the function to execute after\n     *   the question has been replied\n     */\n    askOne = function (i, callback) {\n      var\n        hasDefault = false,\n        hasOptions = false,\n        key = keys[i],\n        optionsSeparator = '/',\n        question = questions[key],\n        questionDisplay = question.text,\n        vars = {};\n\n      callback = callback || blackhole;\n\n      if (answers[key] !== undefined ||\n          questionDisplay === undefined || questionDisplay === null) {\n        return callback('skip', i + 1);\n      }\n\n      if (question.default !== undefined) {\n        hasDefault = true;\n        vars.default = question.default;\n      }\n      if (question.options !== undefined) {\n        hasOptions = true;\n        vars.options = question.options.join(question.optionsSeparator ||\n          optionsSeparator);\n      }\n\n      if (questionDisplay.indexOf('{{options}}') === -1 && hasOptions) {\n        questionDisplay = questionDisplay.trim() + ' ({{{options}}}) ';\n      }\n      if (questionDisplay.indexOf('{{default}}') === -1 && hasDefault) {\n        questionDisplay = questionDisplay.trim() + ' [{{{default}}}] ';\n      }\n\n      rl.question(mustache.render(questionDisplay, vars), function (answer) {\n        if (answer === undefined || answer.length === 0) {\n          if (hasDefault) {\n            answer = question.default;\n          } else if (question.required) {\n            return callback('required', i);\n          }\n        }\n\n        if (hasOptions) {\n          answer = getCaseInsensitiveMatch(question.options, answer);\n          if (answer === undefined) {\n            return callback('no_match', i);\n          }\n        }\n\n        answers[key] = answer;\n        callback(null, i + 1);\n      });\n    };\n\n    /**\n     * Callback for the next iteration\n     * @param {Object} err\n     * @param {Number} i the index of the next question\n     */\n    next = function (err, i) {\n      if (i < l) {\n        if (err === null || err === undefined) {\n          console.log();\n        }\n        askOne(i, next);\n      } else {\n        rl.close();\n        callback(null, answers);\n      }\n    };\n\n    rl = readline.createInterface({\n      input: process.stdin,\n      output: process.stdout\n    });\n\n    askOne(0, next);\n  };\n\n  exports.ask = ask;\n}());"]}