text: /**
   * ranges-apply
   * Take an array of string slice ranges, delete/replace the string according to them
   * Version: 3.1.5
   * Author: Roy Revelt, Codsen Ltd
   * License: MIT
   * Homepage: https://gitlab.com/codsen/codsen/tree/master/packages/ranges-apply
   */
  
  (function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
    typeof define === 'function' && define.amd ? define(factory) :
    (global = global || self, global.rangesApply = factory());
  }(this, (function () { 'use strict';
  
    function _typeof(obj) {
      "@babel/helpers - typeof";
  
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function (obj) {
          return typeof obj;
        };
      } else {
        _typeof = function (obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }
  
      return _typeof(obj);
    }
  
    /**
     * ranges-sort
     * Sort natural number index ranges [ [5, 6], [1, 3] ] => [ [1, 3], [5, 6] ]
     * Version: 3.11.3
     * Author: Roy Revelt, Codsen Ltd
     * License: MIT
     * Homepage: https://gitlab.com/codsen/codsen/tree/master/packages/ranges-sort
     */
    function rangesSort(arrOfRanges, originalOptions) {
      if (!Array.isArray(arrOfRanges)) {
        throw new TypeError(`ranges-sort: [THROW_ID_01] Input must be an array, consisting of range arrays! Currently its type is: ${typeof arrOfRanges}, equal to: ${JSON.stringify(arrOfRanges, null, 4)}`);
      }
  
      if (arrOfRanges.length === 0) {
        return arrOfRanges;
      }
  
      const defaults = {
        strictlyTwoElementsInRangeArrays: false,
        progressFn: null
      };
      const opts = { ...defaults,
        ...originalOptions
      };
      let culpritsIndex;
      let culpritsLen;
  
      if (opts.strictlyTwoElementsInRangeArrays && !arrOfRanges.every((rangeArr, indx) => {
        if (rangeArr.length !== 2) {
          culpritsIndex = indx;
          culpritsLen = rangeArr.length;
          return false;
        }
  
        return true;
      })) {
        throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${culpritsIndex}th range (${JSON.stringify(arrOfRanges[culpritsIndex], null, 4)}) has not two but ${culpritsLen} elements!`);
      }
  
      if (!arrOfRanges.every((rangeArr, indx) => {
        if (!Number.isInteger(rangeArr[0]) || rangeArr[0] < 0 || !Number.isInteger(rangeArr[1]) || rangeArr[1] < 0) {
          culpritsIndex = indx;
          return false;
        }
  
        return true;
      })) {
        throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${culpritsIndex}th range (${JSON.stringify(arrOfRanges[culpritsIndex], null, 4)}) does not consist of only natural numbers!`);
      }
  
      const maxPossibleIterations = arrOfRanges.length * arrOfRanges.length;
      let counter = 0;
      return Array.from(arrOfRanges).sort((range1, range2) => {
        if (opts.progressFn) {
          counter += 1;
          opts.progressFn(Math.floor(counter * 100 / maxPossibleIterations));
        }
  
        if (range1[0] === range2[0]) {
          if (range1[1] < range2[1]) {
            return -1;
          }
  
          if (range1[1] > range2[1]) {
            return 1;
          }
  
          return 0;
        }
  
        if (range1[0] < range2[0]) {
          return -1;
        }
  
        return 1;
      });
    }
  
    /**
     * ranges-merge
     * Merge and sort arrays which mean string slice ranges
     * Version: 4.3.4
     * Author: Roy Revelt, Codsen Ltd
     * License: MIT
     * Homepage: https://gitlab.com/codsen/codsen/tree/master/packages/ranges-merge
     */
  
    function mergeRanges(arrOfRanges, originalOpts) {
      function isStr(something) {
        return typeof something === "string";
      }
  
      function isObj(something) {
        return something && typeof something === "object" && !Array.isArray(something);
      }
  
      if (!Array.isArray(arrOfRanges)) {
        return arrOfRanges;
      }
  
      const defaults = {
        mergeType: 1,
        progressFn: null,
        joinRangesThatTouchEdges: true
      };
      let opts;
  
      if (originalOpts) {
        if (isObj(originalOpts)) {
          opts = { ...defaults,
            ...originalOpts
          };
  
          if (opts.progressFn && isObj(opts.progressFn) && !Object.keys(opts.progressFn).length) {
            opts.progressFn = null;
          } else if (opts.progressFn && typeof opts.progressFn !== "function") {
            throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof opts.progressFn}", equal to ${JSON.stringify(opts.progressFn, null, 4)}`);
          }
  
          if (opts.mergeType && opts.mergeType !== 1 && opts.mergeType !== 2) {
            if (isStr(opts.mergeType) && opts.mergeType.trim() === "1") {
              opts.mergeType = 1;
            } else if (isStr(opts.mergeType) && opts.mergeType.trim() === "2") {
              opts.mergeType = 2;
            } else {
              throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof opts.mergeType}", equal to ${JSON.stringify(opts.mergeType, null, 4)}`);
            }
          }
  
          if (typeof opts.joinRangesThatTouchEdges !== "boolean") {
            throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof opts.joinRangesThatTouchEdges}", equal to ${JSON.stringify(opts.joinRangesThatTouchEdges, null, 4)}`);
          }
        } else {
          throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:\n${JSON.stringify(originalOpts, null, 4)} (type ${typeof originalOpts})`);
        }
      } else {
        opts = { ...defaults
        };
      }
  
      const filtered = arrOfRanges.map(subarr => [...subarr]).filter(rangeArr => rangeArr[2] !== undefined || rangeArr[0] !== rangeArr[1]);
      let sortedRanges;
      let lastPercentageDone;
      let percentageDone;
  
      if (opts.progressFn) {
        sortedRanges = rangesSort(filtered, {
          progressFn: percentage => {
            percentageDone = Math.floor(percentage / 5);
  
            if (percentageDone !== lastPercentageDone) {
              lastPercentageDone = percentageDone;
              opts.progressFn(percentageDone);
            }
          }
        });
      } else {
        sortedRanges = rangesSort(filtered);
      }
  
      const len = sortedRanges.length - 1;
  
      for (let i = len; i > 0; i--) {
        if (opts.progressFn) {
          percentageDone = Math.floor((1 - i / len) * 78) + 21;
  
          if (percentageDone !== lastPercentageDone && percentageDone > lastPercentageDone) {
            lastPercentageDone = percentageDone;
            opts.progressFn(percentageDone);
          }
        }
  
        if (sortedRanges[i][0] <= sortedRanges[i - 1][0] || !opts.joinRangesThatTouchEdges && sortedRanges[i][0] < sortedRanges[i - 1][1] || opts.joinRangesThatTouchEdges && sortedRanges[i][0] <= sortedRanges[i - 1][1]) {
          sortedRanges[i - 1][0] = Math.min(sortedRanges[i][0], sortedRanges[i - 1][0]);
          sortedRanges[i - 1][1] = Math.max(sortedRanges[i][1], sortedRanges[i - 1][1]);
  
          if (sortedRanges[i][2] !== undefined && (sortedRanges[i - 1][0] >= sortedRanges[i][0] || sortedRanges[i - 1][1] <= sortedRanges[i][1])) {
            if (sortedRanges[i - 1][2] !== null) {
              if (sortedRanges[i][2] === null && sortedRanges[i - 1][2] !== null) {
                sortedRanges[i - 1][2] = null;
              } else if (sortedRanges[i - 1][2] !== undefined) {
                if (opts.mergeType === 2 && sortedRanges[i - 1][0] === sortedRanges[i][0]) {
                  sortedRanges[i - 1][2] = sortedRanges[i][2];
                } else {
                  sortedRanges[i - 1][2] += sortedRanges[i][2];
                }
              } else {
                sortedRanges[i - 1][2] = sortedRanges[i][2];
              }
            }
          }
  
          sortedRanges.splice(i, 1);
          i = sortedRanges.length;
        }
      }
  
      return sortedRanges;
    }
  
    function existy(x) {
      return x != null;
    }
  
    function isStr(something) {
      return typeof something === "string";
    }
  
    function rangesApply(str, originalRangesArr, _progressFn) {
      var percentageDone = 0;
      var lastPercentageDone = 0;
  
      if (arguments.length === 0) {
        throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");
      }
  
      if (!isStr(str)) {
        throw new TypeError("ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ".concat(_typeof(str), ", equal to: ").concat(JSON.stringify(str, null, 4)));
      }
  
      if (originalRangesArr === null) {
        return str;
      }
  
      if (!Array.isArray(originalRangesArr)) {
        throw new TypeError("ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ".concat(_typeof(originalRangesArr), ", equal to: ").concat(JSON.stringify(originalRangesArr, null, 4)));
      }
  
      if (_progressFn && typeof _progressFn !== "function") {
        throw new TypeError("ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ".concat(_typeof(_progressFn), ", equal to: ").concat(JSON.stringify(_progressFn, null, 4)));
      }
  
      var rangesArr;
  
      if (Array.isArray(originalRangesArr) && (Number.isInteger(originalRangesArr[0]) && originalRangesArr[0] >= 0 || /^\d*$/.test(originalRangesArr[0])) && (Number.isInteger(originalRangesArr[1]) && originalRangesArr[1] >= 0 || /^\d*$/.test(originalRangesArr[1]))) {
        rangesArr = [Array.from(originalRangesArr)];
      } else {
        rangesArr = Array.from(originalRangesArr);
      } // allocate first 10% of progress to this stage
  
  
      var len = rangesArr.length;
      var counter = 0;
      rangesArr.forEach(function (el, i) {
        if (_progressFn) {
          percentageDone = Math.floor(counter / len * 10);
  
          if (percentageDone !== lastPercentageDone) {
            lastPercentageDone = percentageDone;
  
            _progressFn(percentageDone);
          }
        }
  
        if (!Array.isArray(el)) {
          throw new TypeError("ranges-apply: [THROW_ID_05] ranges array, second input arg., has ".concat(i, "th element not an array: ").concat(JSON.stringify(el, null, 4), ", which is ").concat(_typeof(el)));
        }
  
        if (!Number.isInteger(el[0]) || el[0] < 0) {
          if (/^\d*$/.test(el[0])) {
            rangesArr[i][0] = Number.parseInt(rangesArr[i][0], 10);
          } else {
            throw new TypeError("ranges-apply: [THROW_ID_06] ranges array, second input arg. has ".concat(i, "th element, array [").concat(el[0], ",").concat(el[1], "]. That array has first element not an integer, but ").concat(_typeof(el[0]), ", equal to: ").concat(JSON.stringify(el[0], null, 4), ". Computer doesn't like this."));
          }
        }
  
        if (!Number.isInteger(el[1])) {
          if (/^\d*$/.test(el[1])) {
            rangesArr[i][1] = Number.parseInt(rangesArr[i][1], 10);
          } else {
            throw new TypeError("ranges-apply: [THROW_ID_07] ranges array, second input arg. has ".concat(i, "th element, array [").concat(el[0], ",").concat(el[1], "]. That array has second element not an integer, but ").concat(_typeof(el[1]), ", equal to: ").concat(JSON.stringify(el[1], null, 4), ". Computer doesn't like this."));
          }
        }
  
        counter += 1;
      }); // allocate another 10% of the progress indicator length to the rangesMerge step:
  
      var workingRanges = mergeRanges(rangesArr, {
        progressFn: function progressFn(perc) {
          if (_progressFn) {
            // since "perc" is already from zero to hundred, we just divide by 10 and
            // get the range from zero to ten:
            percentageDone = 10 + Math.floor(perc / 10);
  
            if (percentageDone !== lastPercentageDone) {
              lastPercentageDone = percentageDone;
  
              _progressFn(percentageDone);
            }
          }
        }
      }); // allocate the rest 80% to the actual string assembly:
  
      var len2 = workingRanges.length;
  
      if (len2 > 0) {
        var tails = str.slice(workingRanges[len2 - 1][1]); // eslint-disable-next-line no-param-reassign
  
        str = workingRanges.reduce(function (acc, val, i, arr) {
          if (_progressFn) {
            // since "perc" is already from zero to hundred, we just divide by 10 and
            // get the range from zero to ten:
            percentageDone = 20 + Math.floor(i / len2 * 80);
  
            if (percentageDone !== lastPercentageDone) {
              lastPercentageDone = percentageDone;
  
              _progressFn(percentageDone);
            }
          }
  
          var beginning = i === 0 ? 0 : arr[i - 1][1];
          var ending = arr[i][0];
          return acc + str.slice(beginning, ending) + (existy(arr[i][2]) ? arr[i][2] : "");
        }, ""); // eslint-disable-next-line no-param-reassign
  
        str += tails;
      }
  
      return str;
    }
  
    return rangesApply;
  
  })));
  