UNPKG

voca

Version:

The ultimate JavaScript string library

43 lines (36 loc) 1.23 kB
import { i as isNil } from './internal/is_nil.js'; import './is_string.js'; import { c as coerceToString } from './internal/coerce_to_string.js'; import { t as toString } from './internal/to_string.js'; import { c as clipNumber, t as toInteger } from './internal/to_integer.js'; /** * Checks whether `subject` includes `search` starting from `position`. * * @function includes * @static * @since 1.0.0 * @memberOf Query * @param {string} [subject=''] The string where to search. * @param {string} search The string to search. * @param {number} [position=0] The position to start searching. * @return {boolean} Returns `true` if `subject` includes `search` or `false` otherwise. * @example * v.includes('starship', 'star'); * // => true * * v.includes('galaxy', 'g', 1); * // => false */ function includes(subject, search, position) { var subjectString = coerceToString(subject); var searchString = toString(search); if (searchString === null) { return false; } if (searchString === '') { return true; } position = isNil(position) ? 0 : clipNumber(toInteger(position), 0, subjectString.length); return subjectString.indexOf(searchString, position) !== -1; } export default includes;