UNPKG

voca

Version:

The ultimate JavaScript string library

32 lines (27 loc) 822 B
'use strict'; require('./internal/is_nil.js'); require('./is_string.js'); var coerce_to_string = require('./internal/coerce_to_string.js'); /** * Returns the first occurrence index of `search` in `subject`. * * @function indexOf * @static * @since 1.0.0 * @memberOf Index * @param {string} [subject=''] The string where to search. * @param {string} search The string to search. * @param {number} [fromIndex=0] The index to start searching. * @return {number} Returns the first occurrence index or `-1` if not found. * @example * v.indexOf('morning', 'n'); * // => 3 * * v.indexOf('evening', 'o'); * // => -1 */ function indexOf(subject, search, fromIndex) { var subjectString = coerce_to_string.coerceToString(subject); return subjectString.indexOf(search, fromIndex); } module.exports = indexOf;