1// CMS-324013 - patching lodash to behave like underscore for _.contains 2// this should be removed as soon as we can! 3require(["lodash"], function (_) { 4 // Underscore-compatible lodash shims (lodash v4 removed contains / where). 5 // _.contains â https://github.com/jashkenas/underscore/blob/master/modules/contains.js 6 // and inlined helpers: _isArrayLike, _getLength, _createSizePropertyCheck (_setup), 7 // values, keys, isObject, indexOf via createIndexFinder (NaN path uses findIndex slice). 8 const MAX_ARRAY_INDEX = Math.pow(2, 53) - 1; 9 10 function getLength(collection) { 11 return collection == null ? void 0 : collection.length; 12 } 13 14 function isArrayLike(collection) { 15 const length = getLength(collection); 16 return typeof length === 'number' && length >= 0 && length <= MAX_ARRAY_INDEX; 17 } 18 19 function isObject(obj) { 20 const type = typeof obj; 21 return type === 'function' || (type === 'object' && !!obj); 22 } 23 24 function keys(obj) { 25 if (!isObject(obj)) return []; 26 return Object.keys(obj); 27 } 28 29 function values(obj) { 30 const _keys = keys(obj); 31 const length = _keys.length; 32 const vals = new Array(length); 33 for (let i = 0; i < length; i++) { 34 vals[i] = obj[_keys[i]]; 35 } 36 return vals; 37 } 38 39 function isUnderscoreNaN(obj) { 40 return typeof obj === 'number' && obj !== obj; 41 } 42 43 function findIndexNaN(array) { 44 for (let j = 0, l = array.length; j < l; j++) { 45 if (isUnderscoreNaN(array[j])) return j; 46 } 47 return -1; 48 } 49 50 function indexOf(array, item, idx) { 51 let i = 0; 52 const length = getLength(array); 53 if (typeof idx === 'number') { 54 i = idx >= 0 ? idx : Math.max(idx + length, i); 55 } 56 if (item !== item) { 57 let found = findIndexNaN(Array.prototype.slice.call(array, i, length)); 58 return found >= 0 ? found + i : -1; 59 } 60 for (let n = i; n < length; n++) { 61 if (array[n] === item) return n; 62 } 63 return -1; 64 } 65 66 _.contains = function (obj, item, fromIndex, guard) { 67 if (!isArrayLike(obj)) obj = values(obj); 68 if (typeof fromIndex !== 'number' || guard) fromIndex = 0; 69 return indexOf(obj, item, fromIndex) >= 0; 70 }; 71 72 // _.where â https://github.com/jashkenas/underscore/blob/master/modules/where.js 73 // (filter + matcher(attrs); matcher copies attrs via extendOwn â use assign for same snapshot) 74 _.where = function (obj, attrs) { 75 return _.filter(obj, _.matches(Object.assign({}, attrs))); 76 }; 77 78 // ai recreated version 79 _.unique = function(array, isSorted, iteratee, context) { 80 if (!array || !array.length) return []; 81 82 if (typeof isSorted !== 'boolean') { 83 context = iteratee; 84 iteratee = isSorted; 85 isSorted = false; 86 } 87 88 // Normalize iteratee (minimal, compatible) 89 if (iteratee != null) { 90 if (typeof iteratee === 'function') { 91 if (context) { 92 let fn = iteratee; 93 iteratee = function (value, index, list) { 94 return fn.call(context, value, index, list); 95 }; 96 } 97 } else if (typeof iteratee === 'object') { 98 let attrs = iteratee; 99 iteratee = function (obj) { 100 for (let key in attrs) { 101 if (attrs[key] !== obj[key]) return false; 102 } 103 return true; 104 }; 105 } else { 106 let prop = iteratee; 107 iteratee = function (obj) { 108 return obj[prop]; 109 }; 110 } 111 } 112 113 let result = []; 114 let seen; 115 let value, computed; 116 117 for (let i = 0, length = array.length; i < length; i++) { 118 value = array[i]; 119 computed = iteratee ? iteratee(value, i, array) : value; 120 121 if (isSorted) { 122 if (!i || seen !== computed) { 123 result.push(value); 124 } 125 seen = computed; 126 } else if (iteratee) { 127 if (!seen) seen = []; 128 if (!_.contains(seen, computed)) { 129 seen.push(computed); 130 result.push(value); 131 } 132 } else { 133 if (!_.contains(result, value)) { 134 result.push(value); 135 } 136 } 137 } 138 139 return result; 140 } 141 142});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.