text: Object.defineProperty(exports, "__esModule", { value: true });
  var config = {
      END_WORD: "$",
      PERMS_MIN_LEN: 2,
  };
  var Trie = (function () {
      function Trie(input) {
          this._trie = Trie._create(input);
      }
      Trie.prototype.getIndex = function () {
          return this._trie;
      };
      Trie.prototype.setIndex = function (trie) {
          this._trie = trie;
      };
      Trie.prototype.addWord = function (word) {
          var reducer = function (previousValue, currentValue, currentIndex, array) {
              return Trie._append(previousValue, currentValue, currentIndex, array);
          };
          var input = word.toLowerCase().split("");
          input.reduce(reducer, this._trie);
          return this;
      };
      Trie.prototype.removeWord = function (word) {
          var _a = Trie._checkPrefix(this._trie, word), prefixFound = _a.prefixFound, prefixNode = _a.prefixNode;
          if (prefixFound) {
              delete prefixNode[config.END_WORD];
          }
          return this;
      };
      Trie.prototype.getWords = function () {
          return Trie._recursePrefix(this._trie, '');
      };
      Trie.prototype.getPrefix = function (strPrefix) {
          strPrefix = strPrefix.toLowerCase();
          if (!this._isPrefix(strPrefix)) {
              return [];
          }
          var prefixNode = Trie._checkPrefix(this._trie, strPrefix).prefixNode;
          return Trie._recursePrefix(prefixNode, strPrefix);
      };
      Trie.prototype._isPrefix = function (prefix) {
          var prefixFound = Trie._checkPrefix(this._trie, prefix).prefixFound;
          return prefixFound;
      };
      Trie._append = function (trie, letter, index, array) {
          trie[letter] = trie[letter] || {};
          trie = trie[letter];
          if (index === array.length - 1) {
              trie[config.END_WORD] = 1;
          }
          return trie;
      };
      Trie._checkPrefix = function (prefixNode, prefix) {
          var input = prefix.toLowerCase().split("");
          var prefixFound = input.every(function (letter, index) {
              if (!prefixNode[letter]) {
                  return false;
              }
              return prefixNode = prefixNode[letter];
          });
          return {
              prefixFound: prefixFound,
              prefixNode: prefixNode,
          };
      };
      Trie._create = function (input) {
          var trie = (input || []).reduce(function (accumulator, item) {
              item
                  .toLowerCase()
                  .split("")
                  .reduce(Trie._append, accumulator);
              return accumulator;
          }, {});
          return trie;
      };
      Trie._recursePrefix = function (node, prefix, prefixes) {
          if (prefixes === void 0) { prefixes = []; }
          var word = prefix;
          for (var branch in node) {
              if (branch === config.END_WORD) {
                  prefixes.push(word);
                  word = "";
              }
              Trie._recursePrefix(node[branch], prefix + branch, prefixes);
          }
          return prefixes.sort();
      };
      return Trie;
  }());
  exports.Trie = Trie;
  