trim.js 433 B

12345678910
  1. var makeString = require('./helper/makeString');
  2. var defaultToWhiteSpace = require('./helper/defaultToWhiteSpace');
  3. var nativeTrim = String.prototype.trim;
  4. module.exports = function trim(str, characters) {
  5. str = makeString(str);
  6. if (!characters && nativeTrim) return nativeTrim.call(str);
  7. characters = defaultToWhiteSpace(characters);
  8. return str.replace(new RegExp('^' + characters + '+|' + characters + '+$', 'g'), '');
  9. };