SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 9 JavaScript
2016-04-19 22:17:16 -07:00
define(['./isSymbol'], function(isSymbol) {
2015-01-08 00:37:01 -08:00
2015-12-16 17:49:35 -08:00
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
2015-01-08 00:37:01 -08:00
/** Used as references for the maximum length and index of an array. */
2015-12-16 17:50:42 -08:00
var MAX_ARRAY_LENGTH = 4294967295,
2015-12-16 17:50:05 -08:00
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
2015-01-08 00:37:01 -08:00
2015-12-16 17:53:20 -08:00
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeFloor = Math.floor,
nativeMin = Math.min;
2015-01-08 00:37:01 -08:00
/**
2015-12-16 17:53:20 -08:00
* The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
* which invokes `iteratee` for `value` and each element of `array` to compute
* their sort ranking. The iteratee is invoked with one argument; (value).
2015-01-08 00:37:01 -08:00
*
* @private
* @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate.
2015-12-16 17:53:20 -08:00
* @param {Function} iteratee The iteratee invoked per element.
2015-12-16 17:49:07 -08:00
* @param {boolean} [retHighest] Specify returning the highest qualified index.
2016-03-26 00:00:01 -07:00
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
2015-01-08 00:37:01 -08:00
*/
2015-12-16 17:53:20 -08:00
function baseSortedIndexBy(array, value, iteratee, retHighest) {
2015-01-08 00:37:01 -08:00
var low = 0,
Update lodash-amd to v4.17.21 + edadd45 (#6064) * Fix prototype pollution in _.set and related functions Prevents setting dangerous properties (__proto__, constructor, prototype) that could lead to prototype pollution vulnerabilities. * Fix command injection vulnerability in _.template - Add validation for the variable option to prevent injection attacks - Improve sourceURL whitespace normalization to prevent code injection * Fix cyclic value comparison in _.isEqual Properly checks both directions when comparing cyclic values to ensure correct equality comparisons for circular references. * Improve _.sortBy and _.orderBy performance and array handling - Add early return for empty arrays in sorted index operations - Improve array iteratee handling to support nested property paths - Add missing keysIn import in baseClone * Refactor _.trim, _.trimEnd, and _.trimStart implementations Extract shared trim logic into reusable utilities (_baseTrim, _trimmedEndIndex) for better code organization and consistency. Update related functions (toNumber, parseInt) to use new utilities. Improve comment accuracy. * Add documentation for predicate composition with _.overEvery and _.overSome Enhance documentation to show how _.matches and _.matchesProperty can be combined using _.overEvery and _.overSome for more powerful filtering. Add examples demonstrating shorthand predicate syntax. * Bump to v4.17.21 * Fix prototype pollution in _.unset and _.omit Prevent prototype pollution on baseUnset function by: - Blocking "__proto__" if not an own property - Blocking "constructor.prototype" chains (except when starting at primitive root) - Skipping non-string keys See: https://github.com/lodash/lodash/security/advisories/GHSA-xxjr-mmjv-4gpg * Update JSDoc documentation to align with main branch - Fix sortBy example ages (40 -> 30) for correct sort order demonstration - Fix _setCacheHas return type (number -> boolean)
2025-12-10 17:03:07 -05:00
high = array == null ? 0 : array.length;
if (high === 0) {
return 0;
}
value = iteratee(value);
var valIsNaN = value !== value,
2015-12-16 17:50:42 -08:00
valIsNull = value === null,
2016-04-19 22:17:16 -07:00
valIsSymbol = isSymbol(value),
valIsUndefined = value === undefined;
2015-01-08 00:37:01 -08:00
while (low < high) {
2015-12-16 17:52:15 -08:00
var mid = nativeFloor((low + high) / 2),
2015-01-08 00:37:01 -08:00
computed = iteratee(array[mid]),
2016-04-19 22:17:16 -07:00
othIsDefined = computed !== undefined,
othIsNull = computed === null,
othIsReflexive = computed === computed,
othIsSymbol = isSymbol(computed);
2015-01-08 00:37:01 -08:00
if (valIsNaN) {
2016-04-19 22:17:16 -07:00
var setLow = retHighest || othIsReflexive;
} else if (valIsUndefined) {
setLow = othIsReflexive && (retHighest || othIsDefined);
2015-12-16 17:50:42 -08:00
} else if (valIsNull) {
2016-04-19 22:17:16 -07:00
setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
} else if (valIsSymbol) {
setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
} else if (othIsNull || othIsSymbol) {
2015-12-16 17:50:42 -08:00
setLow = false;
2015-01-08 00:37:01 -08:00
} else {
setLow = retHighest ? (computed <= value) : (computed < value);
}
if (setLow) {
low = mid + 1;
} else {
high = mid;
}
}
return nativeMin(high, MAX_ARRAY_INDEX);
}
2015-12-16 17:53:20 -08:00
return baseSortedIndexBy;
2015-01-08 00:37:01 -08:00
});