rtrim.js 362 B

1234567
  1. import assertString from './util/assertString';
  2. export default function rtrim(str, chars) {
  3. assertString(str); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
  4. var pattern = chars ? new RegExp("[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+$"), 'g') : /(\s)+$/g;
  5. return str.replace(pattern, '');
  6. }