cacheIndexOf.js 586 B

12345678910111213141516171819
  1. var isObject = require('../lang/isObject');
  2. /**
  3. * Checks if `value` is in `cache` mimicking the return signature of
  4. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  5. *
  6. * @private
  7. * @param {Object} cache The cache to search.
  8. * @param {*} value The value to search for.
  9. * @returns {number} Returns `0` if `value` is found, else `-1`.
  10. */
  11. function cacheIndexOf(cache, value) {
  12. var data = cache.data,
  13. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  14. return result ? 0 : -1;
  15. }
  16. module.exports = cacheIndexOf;