summaryrefslogtreecommitdiff
path: root/node_modules/trim-repeated/index.js
blob: cb67a697fa9d2b77f571a39dcd5e7256b29d58e1 (plain)
1
2
3
4
5
6
7
8
9
10
'use strict';
var escapeStringRegexp = require('escape-string-regexp');

module.exports = function (str, target) {
	if (typeof str !== 'string' || typeof target !== 'string') {
		throw new TypeError('Expected a string');
	}

	return str.replace(new RegExp('(?:' + escapeStringRegexp(target) + '){2,}', 'g'), target);
};