endsWith.js 524 B

1234567891011121314151617
  1. var toValueString = require('./toValueString')
  2. /**
  3. * 判断字符串是否在源字符串的尾部
  4. *
  5. * @param {String} str 字符串
  6. * @param {String/Number} val 值
  7. * @param {Number} startIndex 开始索引
  8. * @return {String}
  9. */
  10. function endsWith (str, val, startIndex) {
  11. var rest = toValueString(str)
  12. var argsLen = arguments.length
  13. return argsLen > 1 && (argsLen > 2 ? rest.substring(0, startIndex).indexOf(val) === startIndex - 1 : rest.indexOf(val) === rest.length - 1)
  14. }
  15. module.exports = endsWith