index.js 320 B

12345678910
  1. 'use strict';
  2. var escapeStringRegexp = require('escape-string-regexp');
  3. module.exports = function (str, target) {
  4. if (typeof str !== 'string' || typeof target !== 'string') {
  5. throw new TypeError('Expected a string');
  6. }
  7. return str.replace(new RegExp('(?:' + escapeStringRegexp(target) + '){2,}', 'g'), target);
  8. };