rtrim.js 632 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = rtrim;
  6. var _assertString = require('./util/assertString');
  7. var _assertString2 = _interopRequireDefault(_assertString);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function rtrim(str, chars) {
  10. (0, _assertString2.default)(str);
  11. var pattern = chars ? new RegExp('[' + chars + ']') : /\s/;
  12. var idx = str.length - 1;
  13. while (idx >= 0 && pattern.test(str[idx])) {
  14. idx--;
  15. }
  16. return idx < str.length ? str.substr(0, idx + 1) : str;
  17. }
  18. module.exports = exports['default'];