index.js 306 B

1234567891011
  1. 'use strict';
  2. var escapeStringRegexp = require('escape-string-regexp');
  3. module.exports = function (str, sub) {
  4. if (typeof str !== 'string' || typeof sub !== 'string') {
  5. throw new TypeError();
  6. }
  7. sub = escapeStringRegexp(sub);
  8. return str.replace(new RegExp('^' + sub + '|' + sub + '$', 'g'), '');
  9. };