blob: cb67a697fa9d2b77f571a39dcd5e7256b29d58e1 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2var escapeStringRegexp = require('escape-string-regexp');
3
4module.exports = function (str, target) {
5 if (typeof str !== 'string' || typeof target !== 'string') {
6 throw new TypeError('Expected a string');
7 }
8
9 return str.replace(new RegExp('(?:' + escapeStringRegexp(target) + '){2,}', 'g'), target);
10};