react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / collection / includes.js
80742 viewsvar baseIndexOf = require('../internal/baseIndexOf'),1getLength = require('../internal/getLength'),2isArray = require('../lang/isArray'),3isIterateeCall = require('../internal/isIterateeCall'),4isLength = require('../internal/isLength'),5isString = require('../lang/isString'),6values = require('../object/values');78/* Native method references for those with the same name as other `lodash` methods. */9var nativeMax = Math.max;1011/**12* Checks if `value` is in `collection` using13* [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero)14* for equality comparisons. If `fromIndex` is negative, it is used as the offset15* from the end of `collection`.16*17* @static18* @memberOf _19* @alias contains, include20* @category Collection21* @param {Array|Object|string} collection The collection to search.22* @param {*} target The value to search for.23* @param {number} [fromIndex=0] The index to search from.24* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.25* @returns {boolean} Returns `true` if a matching element is found, else `false`.26* @example27*28* _.includes([1, 2, 3], 1);29* // => true30*31* _.includes([1, 2, 3], 1, 2);32* // => false33*34* _.includes({ 'user': 'fred', 'age': 40 }, 'fred');35* // => true36*37* _.includes('pebbles', 'eb');38* // => true39*/40function includes(collection, target, fromIndex, guard) {41var length = collection ? getLength(collection) : 0;42if (!isLength(length)) {43collection = values(collection);44length = collection.length;45}46if (!length) {47return false;48}49if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {50fromIndex = 0;51} else {52fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);53}54return (typeof collection == 'string' || !isArray(collection) && isString(collection))55? (fromIndex < length && collection.indexOf(target, fromIndex) > -1)56: (baseIndexOf(collection, target, fromIndex) > -1);57}5859module.exports = includes;606162