startsWith.js 442 B

12345678910111213141516
  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 startsWith (str, val, startIndex) {
  11. var rest = toValueString(str)
  12. return (arguments.length === 1 ? rest : rest.substring(startIndex)).indexOf(val) === 0
  13. }
  14. module.exports = startsWith