voca
Version:
The ultimate JavaScript string library
30 lines (26 loc) • 788 B
JavaScript
import './internal/is_nil.js';
import './is_string.js';
import { c as coerceToString } from './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 = coerceToString(subject);
return subjectString.indexOf(search, fromIndex);
}
export default indexOf;