rtrim.js 423 B

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