endsWith.js 442 B

12345678910111213
  1. var makeString = require('./helper/makeString');
  2. var toPositive = require('./helper/toPositive');
  3. module.exports = function endsWith(str, ends, position) {
  4. str = makeString(str);
  5. ends = '' + ends;
  6. if (typeof position == 'undefined') {
  7. position = str.length - ends.length;
  8. } else {
  9. position = Math.min(toPositive(position), str.length) - ends.length;
  10. }
  11. return position >= 0 && str.indexOf(ends, position) === position;
  12. };