lodash.core.js 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806
  1. /**
  2. * @license
  3. * lodash (Custom Build) <https://lodash.com/>
  4. * Build: `lodash core -o ./dist/lodash.core.js`
  5. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  6. * Released under MIT license <https://lodash.com/license>
  7. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  8. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9. */
  10. ;(function() {
  11. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  12. var undefined;
  13. /** Used as the semantic version number. */
  14. var VERSION = '4.15.0';
  15. /** Used as the `TypeError` message for "Functions" methods. */
  16. var FUNC_ERROR_TEXT = 'Expected a function';
  17. /** Used to compose bitmasks for function metadata. */
  18. var BIND_FLAG = 1,
  19. PARTIAL_FLAG = 32;
  20. /** Used to compose bitmasks for comparison styles. */
  21. var UNORDERED_COMPARE_FLAG = 1,
  22. PARTIAL_COMPARE_FLAG = 2;
  23. /** Used as references for various `Number` constants. */
  24. var INFINITY = 1 / 0,
  25. MAX_SAFE_INTEGER = 9007199254740991;
  26. /** `Object#toString` result references. */
  27. var argsTag = '[object Arguments]',
  28. arrayTag = '[object Array]',
  29. boolTag = '[object Boolean]',
  30. dateTag = '[object Date]',
  31. errorTag = '[object Error]',
  32. funcTag = '[object Function]',
  33. genTag = '[object GeneratorFunction]',
  34. numberTag = '[object Number]',
  35. objectTag = '[object Object]',
  36. regexpTag = '[object RegExp]',
  37. stringTag = '[object String]';
  38. /** Used to match HTML entities and HTML characters. */
  39. var reUnescapedHtml = /[&<>"'`]/g,
  40. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  41. /** Used to map characters to HTML entities. */
  42. var htmlEscapes = {
  43. '&': '&amp;',
  44. '<': '&lt;',
  45. '>': '&gt;',
  46. '"': '&quot;',
  47. "'": '&#39;',
  48. '`': '&#96;'
  49. };
  50. /** Detect free variable `global` from Node.js. */
  51. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  52. /** Detect free variable `self`. */
  53. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  54. /** Used as a reference to the global object. */
  55. var root = freeGlobal || freeSelf || Function('return this')();
  56. /** Detect free variable `exports`. */
  57. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  58. /** Detect free variable `module`. */
  59. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  60. /*--------------------------------------------------------------------------*/
  61. /**
  62. * Appends the elements of `values` to `array`.
  63. *
  64. * @private
  65. * @param {Array} array The array to modify.
  66. * @param {Array} values The values to append.
  67. * @returns {Array} Returns `array`.
  68. */
  69. function arrayPush(array, values) {
  70. array.push.apply(array, values);
  71. return array;
  72. }
  73. /**
  74. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  75. * support for iteratee shorthands.
  76. *
  77. * @private
  78. * @param {Array} array The array to inspect.
  79. * @param {Function} predicate The function invoked per iteration.
  80. * @param {number} fromIndex The index to search from.
  81. * @param {boolean} [fromRight] Specify iterating from right to left.
  82. * @returns {number} Returns the index of the matched value, else `-1`.
  83. */
  84. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  85. var length = array.length,
  86. index = fromIndex + (fromRight ? 1 : -1);
  87. while ((fromRight ? index-- : ++index < length)) {
  88. if (predicate(array[index], index, array)) {
  89. return index;
  90. }
  91. }
  92. return -1;
  93. }
  94. /**
  95. * The base implementation of `_.property` without support for deep paths.
  96. *
  97. * @private
  98. * @param {string} key The key of the property to get.
  99. * @returns {Function} Returns the new accessor function.
  100. */
  101. function baseProperty(key) {
  102. return function(object) {
  103. return object == null ? undefined : object[key];
  104. };
  105. }
  106. /**
  107. * The base implementation of `_.propertyOf` without support for deep paths.
  108. *
  109. * @private
  110. * @param {Object} object The object to query.
  111. * @returns {Function} Returns the new accessor function.
  112. */
  113. function basePropertyOf(object) {
  114. return function(key) {
  115. return object == null ? undefined : object[key];
  116. };
  117. }
  118. /**
  119. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  120. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  121. *
  122. * @private
  123. * @param {Array|Object} collection The collection to iterate over.
  124. * @param {Function} iteratee The function invoked per iteration.
  125. * @param {*} accumulator The initial value.
  126. * @param {boolean} initAccum Specify using the first or last element of
  127. * `collection` as the initial value.
  128. * @param {Function} eachFunc The function to iterate over `collection`.
  129. * @returns {*} Returns the accumulated value.
  130. */
  131. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  132. eachFunc(collection, function(value, index, collection) {
  133. accumulator = initAccum
  134. ? (initAccum = false, value)
  135. : iteratee(accumulator, value, index, collection);
  136. });
  137. return accumulator;
  138. }
  139. /**
  140. * The base implementation of `_.values` and `_.valuesIn` which creates an
  141. * array of `object` property values corresponding to the property names
  142. * of `props`.
  143. *
  144. * @private
  145. * @param {Object} object The object to query.
  146. * @param {Array} props The property names to get values for.
  147. * @returns {Object} Returns the array of property values.
  148. */
  149. function baseValues(object, props) {
  150. return baseMap(props, function(key) {
  151. return object[key];
  152. });
  153. }
  154. /**
  155. * Used by `_.escape` to convert characters to HTML entities.
  156. *
  157. * @private
  158. * @param {string} chr The matched character to escape.
  159. * @returns {string} Returns the escaped character.
  160. */
  161. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  162. /**
  163. * Checks if `value` is a host object in IE < 9.
  164. *
  165. * @private
  166. * @param {*} value The value to check.
  167. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  168. */
  169. function isHostObject() {
  170. return false;
  171. }
  172. /**
  173. * Creates a unary function that invokes `func` with its argument transformed.
  174. *
  175. * @private
  176. * @param {Function} func The function to wrap.
  177. * @param {Function} transform The argument transform.
  178. * @returns {Function} Returns the new function.
  179. */
  180. function overArg(func, transform) {
  181. return function(arg) {
  182. return func(transform(arg));
  183. };
  184. }
  185. /*--------------------------------------------------------------------------*/
  186. /** Used for built-in method references. */
  187. var arrayProto = Array.prototype,
  188. objectProto = Object.prototype;
  189. /** Used to check objects for own properties. */
  190. var hasOwnProperty = objectProto.hasOwnProperty;
  191. /** Used to generate unique IDs. */
  192. var idCounter = 0;
  193. /**
  194. * Used to resolve the
  195. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  196. * of values.
  197. */
  198. var objectToString = objectProto.toString;
  199. /** Used to restore the original `_` reference in `_.noConflict`. */
  200. var oldDash = root._;
  201. /** Built-in value references. */
  202. var objectCreate = Object.create,
  203. propertyIsEnumerable = objectProto.propertyIsEnumerable;
  204. /* Built-in method references for those with the same name as other `lodash` methods. */
  205. var nativeIsFinite = root.isFinite,
  206. nativeKeys = overArg(Object.keys, Object),
  207. nativeMax = Math.max;
  208. /*------------------------------------------------------------------------*/
  209. /**
  210. * Creates a `lodash` object which wraps `value` to enable implicit method
  211. * chain sequences. Methods that operate on and return arrays, collections,
  212. * and functions can be chained together. Methods that retrieve a single value
  213. * or may return a primitive value will automatically end the chain sequence
  214. * and return the unwrapped value. Otherwise, the value must be unwrapped
  215. * with `_#value`.
  216. *
  217. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  218. * enabled using `_.chain`.
  219. *
  220. * The execution of chained methods is lazy, that is, it's deferred until
  221. * `_#value` is implicitly or explicitly called.
  222. *
  223. * Lazy evaluation allows several methods to support shortcut fusion.
  224. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  225. * the creation of intermediate arrays and can greatly reduce the number of
  226. * iteratee executions. Sections of a chain sequence qualify for shortcut
  227. * fusion if the section is applied to an array of at least `200` elements
  228. * and any iteratees accept only one argument. The heuristic for whether a
  229. * section qualifies for shortcut fusion is subject to change.
  230. *
  231. * Chaining is supported in custom builds as long as the `_#value` method is
  232. * directly or indirectly included in the build.
  233. *
  234. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  235. *
  236. * The wrapper `Array` methods are:
  237. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  238. *
  239. * The wrapper `String` methods are:
  240. * `replace` and `split`
  241. *
  242. * The wrapper methods that support shortcut fusion are:
  243. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  244. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  245. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  246. *
  247. * The chainable wrapper methods are:
  248. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  249. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  250. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  251. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  252. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  253. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  254. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  255. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  256. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  257. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  258. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  259. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  260. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  261. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  262. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  263. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  264. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  265. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  266. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  267. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  268. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  269. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  270. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  271. * `zipObject`, `zipObjectDeep`, and `zipWith`
  272. *
  273. * The wrapper methods that are **not** chainable by default are:
  274. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  275. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  276. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  277. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  278. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  279. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  280. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  281. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  282. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  283. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  284. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  285. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  286. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  287. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  288. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  289. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  290. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  291. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  292. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  293. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  294. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  295. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  296. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  297. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  298. * `upperFirst`, `value`, and `words`
  299. *
  300. * @name _
  301. * @constructor
  302. * @category Seq
  303. * @param {*} value The value to wrap in a `lodash` instance.
  304. * @returns {Object} Returns the new `lodash` wrapper instance.
  305. * @example
  306. *
  307. * function square(n) {
  308. * return n * n;
  309. * }
  310. *
  311. * var wrapped = _([1, 2, 3]);
  312. *
  313. * // Returns an unwrapped value.
  314. * wrapped.reduce(_.add);
  315. * // => 6
  316. *
  317. * // Returns a wrapped value.
  318. * var squares = wrapped.map(square);
  319. *
  320. * _.isArray(squares);
  321. * // => false
  322. *
  323. * _.isArray(squares.value());
  324. * // => true
  325. */
  326. function lodash(value) {
  327. return value instanceof LodashWrapper
  328. ? value
  329. : new LodashWrapper(value);
  330. }
  331. /**
  332. * The base constructor for creating `lodash` wrapper objects.
  333. *
  334. * @private
  335. * @param {*} value The value to wrap.
  336. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  337. */
  338. function LodashWrapper(value, chainAll) {
  339. this.__wrapped__ = value;
  340. this.__actions__ = [];
  341. this.__chain__ = !!chainAll;
  342. }
  343. LodashWrapper.prototype = baseCreate(lodash.prototype);
  344. LodashWrapper.prototype.constructor = LodashWrapper;
  345. /*------------------------------------------------------------------------*/
  346. /**
  347. * Used by `_.defaults` to customize its `_.assignIn` use.
  348. *
  349. * @private
  350. * @param {*} objValue The destination value.
  351. * @param {*} srcValue The source value.
  352. * @param {string} key The key of the property to assign.
  353. * @param {Object} object The parent object of `objValue`.
  354. * @returns {*} Returns the value to assign.
  355. */
  356. function assignInDefaults(objValue, srcValue, key, object) {
  357. if (objValue === undefined ||
  358. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  359. return srcValue;
  360. }
  361. return objValue;
  362. }
  363. /**
  364. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  365. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  366. * for equality comparisons.
  367. *
  368. * @private
  369. * @param {Object} object The object to modify.
  370. * @param {string} key The key of the property to assign.
  371. * @param {*} value The value to assign.
  372. */
  373. function assignValue(object, key, value) {
  374. var objValue = object[key];
  375. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  376. (value === undefined && !(key in object))) {
  377. object[key] = value;
  378. }
  379. }
  380. /**
  381. * The base implementation of `_.create` without support for assigning
  382. * properties to the created object.
  383. *
  384. * @private
  385. * @param {Object} prototype The object to inherit from.
  386. * @returns {Object} Returns the new object.
  387. */
  388. function baseCreate(proto) {
  389. return isObject(proto) ? objectCreate(proto) : {};
  390. }
  391. /**
  392. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  393. * to provide to `func`.
  394. *
  395. * @private
  396. * @param {Function} func The function to delay.
  397. * @param {number} wait The number of milliseconds to delay invocation.
  398. * @param {Array} args The arguments to provide to `func`.
  399. * @returns {number|Object} Returns the timer id or timeout object.
  400. */
  401. function baseDelay(func, wait, args) {
  402. if (typeof func != 'function') {
  403. throw new TypeError(FUNC_ERROR_TEXT);
  404. }
  405. return setTimeout(function() { func.apply(undefined, args); }, wait);
  406. }
  407. /**
  408. * The base implementation of `_.forEach` without support for iteratee shorthands.
  409. *
  410. * @private
  411. * @param {Array|Object} collection The collection to iterate over.
  412. * @param {Function} iteratee The function invoked per iteration.
  413. * @returns {Array|Object} Returns `collection`.
  414. */
  415. var baseEach = createBaseEach(baseForOwn);
  416. /**
  417. * The base implementation of `_.every` without support for iteratee shorthands.
  418. *
  419. * @private
  420. * @param {Array|Object} collection The collection to iterate over.
  421. * @param {Function} predicate The function invoked per iteration.
  422. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  423. * else `false`
  424. */
  425. function baseEvery(collection, predicate) {
  426. var result = true;
  427. baseEach(collection, function(value, index, collection) {
  428. result = !!predicate(value, index, collection);
  429. return result;
  430. });
  431. return result;
  432. }
  433. /**
  434. * The base implementation of methods like `_.max` and `_.min` which accepts a
  435. * `comparator` to determine the extremum value.
  436. *
  437. * @private
  438. * @param {Array} array The array to iterate over.
  439. * @param {Function} iteratee The iteratee invoked per iteration.
  440. * @param {Function} comparator The comparator used to compare values.
  441. * @returns {*} Returns the extremum value.
  442. */
  443. function baseExtremum(array, iteratee, comparator) {
  444. var index = -1,
  445. length = array.length;
  446. while (++index < length) {
  447. var value = array[index],
  448. current = iteratee(value);
  449. if (current != null && (computed === undefined
  450. ? (current === current && !false)
  451. : comparator(current, computed)
  452. )) {
  453. var computed = current,
  454. result = value;
  455. }
  456. }
  457. return result;
  458. }
  459. /**
  460. * The base implementation of `_.filter` without support for iteratee shorthands.
  461. *
  462. * @private
  463. * @param {Array|Object} collection The collection to iterate over.
  464. * @param {Function} predicate The function invoked per iteration.
  465. * @returns {Array} Returns the new filtered array.
  466. */
  467. function baseFilter(collection, predicate) {
  468. var result = [];
  469. baseEach(collection, function(value, index, collection) {
  470. if (predicate(value, index, collection)) {
  471. result.push(value);
  472. }
  473. });
  474. return result;
  475. }
  476. /**
  477. * The base implementation of `_.flatten` with support for restricting flattening.
  478. *
  479. * @private
  480. * @param {Array} array The array to flatten.
  481. * @param {number} depth The maximum recursion depth.
  482. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  483. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  484. * @param {Array} [result=[]] The initial result value.
  485. * @returns {Array} Returns the new flattened array.
  486. */
  487. function baseFlatten(array, depth, predicate, isStrict, result) {
  488. var index = -1,
  489. length = array.length;
  490. predicate || (predicate = isFlattenable);
  491. result || (result = []);
  492. while (++index < length) {
  493. var value = array[index];
  494. if (depth > 0 && predicate(value)) {
  495. if (depth > 1) {
  496. // Recursively flatten arrays (susceptible to call stack limits).
  497. baseFlatten(value, depth - 1, predicate, isStrict, result);
  498. } else {
  499. arrayPush(result, value);
  500. }
  501. } else if (!isStrict) {
  502. result[result.length] = value;
  503. }
  504. }
  505. return result;
  506. }
  507. /**
  508. * The base implementation of `baseForOwn` which iterates over `object`
  509. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  510. * Iteratee functions may exit iteration early by explicitly returning `false`.
  511. *
  512. * @private
  513. * @param {Object} object The object to iterate over.
  514. * @param {Function} iteratee The function invoked per iteration.
  515. * @param {Function} keysFunc The function to get the keys of `object`.
  516. * @returns {Object} Returns `object`.
  517. */
  518. var baseFor = createBaseFor();
  519. /**
  520. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  521. *
  522. * @private
  523. * @param {Object} object The object to iterate over.
  524. * @param {Function} iteratee The function invoked per iteration.
  525. * @returns {Object} Returns `object`.
  526. */
  527. function baseForOwn(object, iteratee) {
  528. return object && baseFor(object, iteratee, keys);
  529. }
  530. /**
  531. * The base implementation of `_.functions` which creates an array of
  532. * `object` function property names filtered from `props`.
  533. *
  534. * @private
  535. * @param {Object} object The object to inspect.
  536. * @param {Array} props The property names to filter.
  537. * @returns {Array} Returns the function names.
  538. */
  539. function baseFunctions(object, props) {
  540. return baseFilter(props, function(key) {
  541. return isFunction(object[key]);
  542. });
  543. }
  544. /**
  545. * The base implementation of `_.gt` which doesn't coerce arguments.
  546. *
  547. * @private
  548. * @param {*} value The value to compare.
  549. * @param {*} other The other value to compare.
  550. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  551. * else `false`.
  552. */
  553. function baseGt(value, other) {
  554. return value > other;
  555. }
  556. /**
  557. * The base implementation of `_.isDate` without Node.js optimizations.
  558. *
  559. * @private
  560. * @param {*} value The value to check.
  561. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  562. */
  563. function baseIsDate(value) {
  564. return isObjectLike(value) && objectToString.call(value) == dateTag;
  565. }
  566. /**
  567. * The base implementation of `_.isEqual` which supports partial comparisons
  568. * and tracks traversed objects.
  569. *
  570. * @private
  571. * @param {*} value The value to compare.
  572. * @param {*} other The other value to compare.
  573. * @param {Function} [customizer] The function to customize comparisons.
  574. * @param {boolean} [bitmask] The bitmask of comparison flags.
  575. * The bitmask may be composed of the following flags:
  576. * 1 - Unordered comparison
  577. * 2 - Partial comparison
  578. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  579. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  580. */
  581. function baseIsEqual(value, other, customizer, bitmask, stack) {
  582. if (value === other) {
  583. return true;
  584. }
  585. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  586. return value !== value && other !== other;
  587. }
  588. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  589. }
  590. /**
  591. * A specialized version of `baseIsEqual` for arrays and objects which performs
  592. * deep comparisons and tracks traversed objects enabling objects with circular
  593. * references to be compared.
  594. *
  595. * @private
  596. * @param {Object} object The object to compare.
  597. * @param {Object} other The other object to compare.
  598. * @param {Function} equalFunc The function to determine equivalents of values.
  599. * @param {Function} [customizer] The function to customize comparisons.
  600. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  601. * for more details.
  602. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  603. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  604. */
  605. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  606. var objIsArr = isArray(object),
  607. othIsArr = isArray(other),
  608. objTag = arrayTag,
  609. othTag = arrayTag;
  610. if (!objIsArr) {
  611. objTag = objectToString.call(object);
  612. objTag = objTag == argsTag ? objectTag : objTag;
  613. }
  614. if (!othIsArr) {
  615. othTag = objectToString.call(other);
  616. othTag = othTag == argsTag ? objectTag : othTag;
  617. }
  618. var objIsObj = objTag == objectTag && !isHostObject(object),
  619. othIsObj = othTag == objectTag && !isHostObject(other),
  620. isSameTag = objTag == othTag;
  621. stack || (stack = []);
  622. var objStack = find(stack, function(entry) {
  623. return entry[0] == object;
  624. });
  625. var othStack = find(stack, function(entry) {
  626. return entry[0] == other;
  627. });
  628. if (objStack && othStack) {
  629. return objStack[1] == other;
  630. }
  631. stack.push([object, other]);
  632. stack.push([other, object]);
  633. if (isSameTag && !objIsObj) {
  634. var result = (objIsArr)
  635. ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
  636. : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  637. stack.pop();
  638. return result;
  639. }
  640. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  641. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  642. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  643. if (objIsWrapped || othIsWrapped) {
  644. var objUnwrapped = objIsWrapped ? object.value() : object,
  645. othUnwrapped = othIsWrapped ? other.value() : other;
  646. var result = equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  647. stack.pop();
  648. return result;
  649. }
  650. }
  651. if (!isSameTag) {
  652. return false;
  653. }
  654. var result = equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  655. stack.pop();
  656. return result;
  657. }
  658. /**
  659. * The base implementation of `_.isRegExp` without Node.js optimizations.
  660. *
  661. * @private
  662. * @param {*} value The value to check.
  663. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  664. */
  665. function baseIsRegExp(value) {
  666. return isObject(value) && objectToString.call(value) == regexpTag;
  667. }
  668. /**
  669. * The base implementation of `_.iteratee`.
  670. *
  671. * @private
  672. * @param {*} [value=_.identity] The value to convert to an iteratee.
  673. * @returns {Function} Returns the iteratee.
  674. */
  675. function baseIteratee(func) {
  676. if (typeof func == 'function') {
  677. return func;
  678. }
  679. if (func == null) {
  680. return identity;
  681. }
  682. return (typeof func == 'object' ? baseMatches : baseProperty)(func);
  683. }
  684. /**
  685. * The base implementation of `_.lt` which doesn't coerce arguments.
  686. *
  687. * @private
  688. * @param {*} value The value to compare.
  689. * @param {*} other The other value to compare.
  690. * @returns {boolean} Returns `true` if `value` is less than `other`,
  691. * else `false`.
  692. */
  693. function baseLt(value, other) {
  694. return value < other;
  695. }
  696. /**
  697. * The base implementation of `_.map` without support for iteratee shorthands.
  698. *
  699. * @private
  700. * @param {Array|Object} collection The collection to iterate over.
  701. * @param {Function} iteratee The function invoked per iteration.
  702. * @returns {Array} Returns the new mapped array.
  703. */
  704. function baseMap(collection, iteratee) {
  705. var index = -1,
  706. result = isArrayLike(collection) ? Array(collection.length) : [];
  707. baseEach(collection, function(value, key, collection) {
  708. result[++index] = iteratee(value, key, collection);
  709. });
  710. return result;
  711. }
  712. /**
  713. * The base implementation of `_.matches` which doesn't clone `source`.
  714. *
  715. * @private
  716. * @param {Object} source The object of property values to match.
  717. * @returns {Function} Returns the new spec function.
  718. */
  719. function baseMatches(source) {
  720. var props = nativeKeys(source);
  721. return function(object) {
  722. var length = props.length;
  723. if (object == null) {
  724. return !length;
  725. }
  726. object = Object(object);
  727. while (length--) {
  728. var key = props[length];
  729. if (!(key in object &&
  730. baseIsEqual(source[key], object[key], undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG)
  731. )) {
  732. return false;
  733. }
  734. }
  735. return true;
  736. };
  737. }
  738. /**
  739. * The base implementation of `_.pick` without support for individual
  740. * property identifiers.
  741. *
  742. * @private
  743. * @param {Object} object The source object.
  744. * @param {string[]} props The property identifiers to pick.
  745. * @returns {Object} Returns the new object.
  746. */
  747. function basePick(object, props) {
  748. object = Object(object);
  749. return reduce(props, function(result, key) {
  750. if (key in object) {
  751. result[key] = object[key];
  752. }
  753. return result;
  754. }, {});
  755. }
  756. /**
  757. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  758. *
  759. * @private
  760. * @param {Function} func The function to apply a rest parameter to.
  761. * @param {number} [start=func.length-1] The start position of the rest parameter.
  762. * @returns {Function} Returns the new function.
  763. */
  764. function baseRest(func, start) {
  765. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  766. return function() {
  767. var args = arguments,
  768. index = -1,
  769. length = nativeMax(args.length - start, 0),
  770. array = Array(length);
  771. while (++index < length) {
  772. array[index] = args[start + index];
  773. }
  774. index = -1;
  775. var otherArgs = Array(start + 1);
  776. while (++index < start) {
  777. otherArgs[index] = args[index];
  778. }
  779. otherArgs[start] = array;
  780. return func.apply(this, otherArgs);
  781. };
  782. }
  783. /**
  784. * The base implementation of `_.slice` without an iteratee call guard.
  785. *
  786. * @private
  787. * @param {Array} array The array to slice.
  788. * @param {number} [start=0] The start position.
  789. * @param {number} [end=array.length] The end position.
  790. * @returns {Array} Returns the slice of `array`.
  791. */
  792. function baseSlice(array, start, end) {
  793. var index = -1,
  794. length = array.length;
  795. if (start < 0) {
  796. start = -start > length ? 0 : (length + start);
  797. }
  798. end = end > length ? length : end;
  799. if (end < 0) {
  800. end += length;
  801. }
  802. length = start > end ? 0 : ((end - start) >>> 0);
  803. start >>>= 0;
  804. var result = Array(length);
  805. while (++index < length) {
  806. result[index] = array[index + start];
  807. }
  808. return result;
  809. }
  810. /**
  811. * Copies the values of `source` to `array`.
  812. *
  813. * @private
  814. * @param {Array} source The array to copy values from.
  815. * @param {Array} [array=[]] The array to copy values to.
  816. * @returns {Array} Returns `array`.
  817. */
  818. function copyArray(source) {
  819. return baseSlice(source, 0, source.length);
  820. }
  821. /**
  822. * The base implementation of `_.some` without support for iteratee shorthands.
  823. *
  824. * @private
  825. * @param {Array|Object} collection The collection to iterate over.
  826. * @param {Function} predicate The function invoked per iteration.
  827. * @returns {boolean} Returns `true` if any element passes the predicate check,
  828. * else `false`.
  829. */
  830. function baseSome(collection, predicate) {
  831. var result;
  832. baseEach(collection, function(value, index, collection) {
  833. result = predicate(value, index, collection);
  834. return !result;
  835. });
  836. return !!result;
  837. }
  838. /**
  839. * The base implementation of `wrapperValue` which returns the result of
  840. * performing a sequence of actions on the unwrapped `value`, where each
  841. * successive action is supplied the return value of the previous.
  842. *
  843. * @private
  844. * @param {*} value The unwrapped value.
  845. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  846. * @returns {*} Returns the resolved value.
  847. */
  848. function baseWrapperValue(value, actions) {
  849. var result = value;
  850. return reduce(actions, function(result, action) {
  851. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  852. }, result);
  853. }
  854. /**
  855. * Compares values to sort them in ascending order.
  856. *
  857. * @private
  858. * @param {*} value The value to compare.
  859. * @param {*} other The other value to compare.
  860. * @returns {number} Returns the sort order indicator for `value`.
  861. */
  862. function compareAscending(value, other) {
  863. if (value !== other) {
  864. var valIsDefined = value !== undefined,
  865. valIsNull = value === null,
  866. valIsReflexive = value === value,
  867. valIsSymbol = false;
  868. var othIsDefined = other !== undefined,
  869. othIsNull = other === null,
  870. othIsReflexive = other === other,
  871. othIsSymbol = false;
  872. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  873. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  874. (valIsNull && othIsDefined && othIsReflexive) ||
  875. (!valIsDefined && othIsReflexive) ||
  876. !valIsReflexive) {
  877. return 1;
  878. }
  879. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  880. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  881. (othIsNull && valIsDefined && valIsReflexive) ||
  882. (!othIsDefined && valIsReflexive) ||
  883. !othIsReflexive) {
  884. return -1;
  885. }
  886. }
  887. return 0;
  888. }
  889. /**
  890. * Copies properties of `source` to `object`.
  891. *
  892. * @private
  893. * @param {Object} source The object to copy properties from.
  894. * @param {Array} props The property identifiers to copy.
  895. * @param {Object} [object={}] The object to copy properties to.
  896. * @param {Function} [customizer] The function to customize copied values.
  897. * @returns {Object} Returns `object`.
  898. */
  899. function copyObject(source, props, object, customizer) {
  900. object || (object = {});
  901. var index = -1,
  902. length = props.length;
  903. while (++index < length) {
  904. var key = props[index];
  905. var newValue = customizer
  906. ? customizer(object[key], source[key], key, object, source)
  907. : undefined;
  908. assignValue(object, key, newValue === undefined ? source[key] : newValue);
  909. }
  910. return object;
  911. }
  912. /**
  913. * Creates a function like `_.assign`.
  914. *
  915. * @private
  916. * @param {Function} assigner The function to assign values.
  917. * @returns {Function} Returns the new assigner function.
  918. */
  919. function createAssigner(assigner) {
  920. return baseRest(function(object, sources) {
  921. var index = -1,
  922. length = sources.length,
  923. customizer = length > 1 ? sources[length - 1] : undefined;
  924. customizer = (assigner.length > 3 && typeof customizer == 'function')
  925. ? (length--, customizer)
  926. : undefined;
  927. object = Object(object);
  928. while (++index < length) {
  929. var source = sources[index];
  930. if (source) {
  931. assigner(object, source, index, customizer);
  932. }
  933. }
  934. return object;
  935. });
  936. }
  937. /**
  938. * Creates a `baseEach` or `baseEachRight` function.
  939. *
  940. * @private
  941. * @param {Function} eachFunc The function to iterate over a collection.
  942. * @param {boolean} [fromRight] Specify iterating from right to left.
  943. * @returns {Function} Returns the new base function.
  944. */
  945. function createBaseEach(eachFunc, fromRight) {
  946. return function(collection, iteratee) {
  947. if (collection == null) {
  948. return collection;
  949. }
  950. if (!isArrayLike(collection)) {
  951. return eachFunc(collection, iteratee);
  952. }
  953. var length = collection.length,
  954. index = fromRight ? length : -1,
  955. iterable = Object(collection);
  956. while ((fromRight ? index-- : ++index < length)) {
  957. if (iteratee(iterable[index], index, iterable) === false) {
  958. break;
  959. }
  960. }
  961. return collection;
  962. };
  963. }
  964. /**
  965. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  966. *
  967. * @private
  968. * @param {boolean} [fromRight] Specify iterating from right to left.
  969. * @returns {Function} Returns the new base function.
  970. */
  971. function createBaseFor(fromRight) {
  972. return function(object, iteratee, keysFunc) {
  973. var index = -1,
  974. iterable = Object(object),
  975. props = keysFunc(object),
  976. length = props.length;
  977. while (length--) {
  978. var key = props[fromRight ? length : ++index];
  979. if (iteratee(iterable[key], key, iterable) === false) {
  980. break;
  981. }
  982. }
  983. return object;
  984. };
  985. }
  986. /**
  987. * Creates a function that produces an instance of `Ctor` regardless of
  988. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  989. *
  990. * @private
  991. * @param {Function} Ctor The constructor to wrap.
  992. * @returns {Function} Returns the new wrapped function.
  993. */
  994. function createCtor(Ctor) {
  995. return function() {
  996. // Use a `switch` statement to work with class constructors. See
  997. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  998. // for more details.
  999. var args = arguments;
  1000. var thisBinding = baseCreate(Ctor.prototype),
  1001. result = Ctor.apply(thisBinding, args);
  1002. // Mimic the constructor's `return` behavior.
  1003. // See https://es5.github.io/#x13.2.2 for more details.
  1004. return isObject(result) ? result : thisBinding;
  1005. };
  1006. }
  1007. /**
  1008. * Creates a `_.find` or `_.findLast` function.
  1009. *
  1010. * @private
  1011. * @param {Function} findIndexFunc The function to find the collection index.
  1012. * @returns {Function} Returns the new find function.
  1013. */
  1014. function createFind(findIndexFunc) {
  1015. return function(collection, predicate, fromIndex) {
  1016. var iterable = Object(collection);
  1017. if (!isArrayLike(collection)) {
  1018. var iteratee = baseIteratee(predicate, 3);
  1019. collection = keys(collection);
  1020. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  1021. }
  1022. var index = findIndexFunc(collection, predicate, fromIndex);
  1023. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  1024. };
  1025. }
  1026. /**
  1027. * Creates a function that wraps `func` to invoke it with the `this` binding
  1028. * of `thisArg` and `partials` prepended to the arguments it receives.
  1029. *
  1030. * @private
  1031. * @param {Function} func The function to wrap.
  1032. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  1033. * @param {*} thisArg The `this` binding of `func`.
  1034. * @param {Array} partials The arguments to prepend to those provided to
  1035. * the new function.
  1036. * @returns {Function} Returns the new wrapped function.
  1037. */
  1038. function createPartial(func, bitmask, thisArg, partials) {
  1039. if (typeof func != 'function') {
  1040. throw new TypeError(FUNC_ERROR_TEXT);
  1041. }
  1042. var isBind = bitmask & BIND_FLAG,
  1043. Ctor = createCtor(func);
  1044. function wrapper() {
  1045. var argsIndex = -1,
  1046. argsLength = arguments.length,
  1047. leftIndex = -1,
  1048. leftLength = partials.length,
  1049. args = Array(leftLength + argsLength),
  1050. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  1051. while (++leftIndex < leftLength) {
  1052. args[leftIndex] = partials[leftIndex];
  1053. }
  1054. while (argsLength--) {
  1055. args[leftIndex++] = arguments[++argsIndex];
  1056. }
  1057. return fn.apply(isBind ? thisArg : this, args);
  1058. }
  1059. return wrapper;
  1060. }
  1061. /**
  1062. * A specialized version of `baseIsEqualDeep` for arrays with support for
  1063. * partial deep comparisons.
  1064. *
  1065. * @private
  1066. * @param {Array} array The array to compare.
  1067. * @param {Array} other The other array to compare.
  1068. * @param {Function} equalFunc The function to determine equivalents of values.
  1069. * @param {Function} customizer The function to customize comparisons.
  1070. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  1071. * for more details.
  1072. * @param {Object} stack Tracks traversed `array` and `other` objects.
  1073. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  1074. */
  1075. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  1076. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  1077. arrLength = array.length,
  1078. othLength = other.length;
  1079. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  1080. return false;
  1081. }
  1082. var index = -1,
  1083. result = true,
  1084. seen = (bitmask & UNORDERED_COMPARE_FLAG) ? [] : undefined;
  1085. // Ignore non-index properties.
  1086. while (++index < arrLength) {
  1087. var arrValue = array[index],
  1088. othValue = other[index];
  1089. var compared;
  1090. if (compared !== undefined) {
  1091. if (compared) {
  1092. continue;
  1093. }
  1094. result = false;
  1095. break;
  1096. }
  1097. // Recursively compare arrays (susceptible to call stack limits).
  1098. if (seen) {
  1099. if (!baseSome(other, function(othValue, othIndex) {
  1100. if (!indexOf(seen, othIndex) &&
  1101. (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  1102. return seen.push(othIndex);
  1103. }
  1104. })) {
  1105. result = false;
  1106. break;
  1107. }
  1108. } else if (!(
  1109. arrValue === othValue ||
  1110. equalFunc(arrValue, othValue, customizer, bitmask, stack)
  1111. )) {
  1112. result = false;
  1113. break;
  1114. }
  1115. }
  1116. return result;
  1117. }
  1118. /**
  1119. * A specialized version of `baseIsEqualDeep` for comparing objects of
  1120. * the same `toStringTag`.
  1121. *
  1122. * **Note:** This function only supports comparing values with tags of
  1123. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  1124. *
  1125. * @private
  1126. * @param {Object} object The object to compare.
  1127. * @param {Object} other The other object to compare.
  1128. * @param {string} tag The `toStringTag` of the objects to compare.
  1129. * @param {Function} equalFunc The function to determine equivalents of values.
  1130. * @param {Function} customizer The function to customize comparisons.
  1131. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  1132. * for more details.
  1133. * @param {Object} stack Tracks traversed `object` and `other` objects.
  1134. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  1135. */
  1136. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  1137. switch (tag) {
  1138. case boolTag:
  1139. case dateTag:
  1140. case numberTag:
  1141. // Coerce booleans to `1` or `0` and dates to milliseconds.
  1142. // Invalid dates are coerced to `NaN`.
  1143. return eq(+object, +other);
  1144. case errorTag:
  1145. return object.name == other.name && object.message == other.message;
  1146. case regexpTag:
  1147. case stringTag:
  1148. // Coerce regexes to strings and treat strings, primitives and objects,
  1149. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  1150. // for more details.
  1151. return object == (other + '');
  1152. }
  1153. return false;
  1154. }
  1155. /**
  1156. * A specialized version of `baseIsEqualDeep` for objects with support for
  1157. * partial deep comparisons.
  1158. *
  1159. * @private
  1160. * @param {Object} object The object to compare.
  1161. * @param {Object} other The other object to compare.
  1162. * @param {Function} equalFunc The function to determine equivalents of values.
  1163. * @param {Function} customizer The function to customize comparisons.
  1164. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  1165. * for more details.
  1166. * @param {Object} stack Tracks traversed `object` and `other` objects.
  1167. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  1168. */
  1169. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  1170. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  1171. objProps = keys(object),
  1172. objLength = objProps.length,
  1173. othProps = keys(other),
  1174. othLength = othProps.length;
  1175. if (objLength != othLength && !isPartial) {
  1176. return false;
  1177. }
  1178. var index = objLength;
  1179. while (index--) {
  1180. var key = objProps[index];
  1181. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  1182. return false;
  1183. }
  1184. }
  1185. var result = true;
  1186. var skipCtor = isPartial;
  1187. while (++index < objLength) {
  1188. key = objProps[index];
  1189. var objValue = object[key],
  1190. othValue = other[key];
  1191. var compared;
  1192. // Recursively compare objects (susceptible to call stack limits).
  1193. if (!(compared === undefined
  1194. ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
  1195. : compared
  1196. )) {
  1197. result = false;
  1198. break;
  1199. }
  1200. skipCtor || (skipCtor = key == 'constructor');
  1201. }
  1202. if (result && !skipCtor) {
  1203. var objCtor = object.constructor,
  1204. othCtor = other.constructor;
  1205. // Non `Object` object instances with different constructors are not equal.
  1206. if (objCtor != othCtor &&
  1207. ('constructor' in object && 'constructor' in other) &&
  1208. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  1209. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  1210. result = false;
  1211. }
  1212. }
  1213. return result;
  1214. }
  1215. /**
  1216. * Checks if `value` is a flattenable `arguments` object or array.
  1217. *
  1218. * @private
  1219. * @param {*} value The value to check.
  1220. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  1221. */
  1222. function isFlattenable(value) {
  1223. return isArray(value) || isArguments(value);
  1224. }
  1225. /**
  1226. * This function is like
  1227. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  1228. * except that it includes inherited enumerable properties.
  1229. *
  1230. * @private
  1231. * @param {Object} object The object to query.
  1232. * @returns {Array} Returns the array of property names.
  1233. */
  1234. function nativeKeysIn(object) {
  1235. var result = [];
  1236. if (object != null) {
  1237. for (var key in Object(object)) {
  1238. result.push(key);
  1239. }
  1240. }
  1241. return result;
  1242. }
  1243. /**
  1244. * Converts `value` to a string key if it's not a string or symbol.
  1245. *
  1246. * @private
  1247. * @param {*} value The value to inspect.
  1248. * @returns {string|symbol} Returns the key.
  1249. */
  1250. var toKey = String;
  1251. /*------------------------------------------------------------------------*/
  1252. /**
  1253. * Creates an array with all falsey values removed. The values `false`, `null`,
  1254. * `0`, `""`, `undefined`, and `NaN` are falsey.
  1255. *
  1256. * @static
  1257. * @memberOf _
  1258. * @since 0.1.0
  1259. * @category Array
  1260. * @param {Array} array The array to compact.
  1261. * @returns {Array} Returns the new array of filtered values.
  1262. * @example
  1263. *
  1264. * _.compact([0, 1, false, 2, '', 3]);
  1265. * // => [1, 2, 3]
  1266. */
  1267. function compact(array) {
  1268. return baseFilter(array, Boolean);
  1269. }
  1270. /**
  1271. * Creates a new array concatenating `array` with any additional arrays
  1272. * and/or values.
  1273. *
  1274. * @static
  1275. * @memberOf _
  1276. * @since 4.0.0
  1277. * @category Array
  1278. * @param {Array} array The array to concatenate.
  1279. * @param {...*} [values] The values to concatenate.
  1280. * @returns {Array} Returns the new concatenated array.
  1281. * @example
  1282. *
  1283. * var array = [1];
  1284. * var other = _.concat(array, 2, [3], [[4]]);
  1285. *
  1286. * console.log(other);
  1287. * // => [1, 2, 3, [4]]
  1288. *
  1289. * console.log(array);
  1290. * // => [1]
  1291. */
  1292. function concat() {
  1293. var length = arguments.length,
  1294. args = Array(length ? length - 1 : 0),
  1295. array = arguments[0],
  1296. index = length;
  1297. while (index--) {
  1298. args[index - 1] = arguments[index];
  1299. }
  1300. return length
  1301. ? arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1))
  1302. : [];
  1303. }
  1304. /**
  1305. * This method is like `_.find` except that it returns the index of the first
  1306. * element `predicate` returns truthy for instead of the element itself.
  1307. *
  1308. * @static
  1309. * @memberOf _
  1310. * @since 1.1.0
  1311. * @category Array
  1312. * @param {Array} array The array to inspect.
  1313. * @param {Function} [predicate=_.identity]
  1314. * The function invoked per iteration.
  1315. * @param {number} [fromIndex=0] The index to search from.
  1316. * @returns {number} Returns the index of the found element, else `-1`.
  1317. * @example
  1318. *
  1319. * var users = [
  1320. * { 'user': 'barney', 'active': false },
  1321. * { 'user': 'fred', 'active': false },
  1322. * { 'user': 'pebbles', 'active': true }
  1323. * ];
  1324. *
  1325. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  1326. * // => 0
  1327. *
  1328. * // The `_.matches` iteratee shorthand.
  1329. * _.findIndex(users, { 'user': 'fred', 'active': false });
  1330. * // => 1
  1331. *
  1332. * // The `_.matchesProperty` iteratee shorthand.
  1333. * _.findIndex(users, ['active', false]);
  1334. * // => 0
  1335. *
  1336. * // The `_.property` iteratee shorthand.
  1337. * _.findIndex(users, 'active');
  1338. * // => 2
  1339. */
  1340. function findIndex(array, predicate, fromIndex) {
  1341. var length = array ? array.length : 0;
  1342. if (!length) {
  1343. return -1;
  1344. }
  1345. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  1346. if (index < 0) {
  1347. index = nativeMax(length + index, 0);
  1348. }
  1349. return baseFindIndex(array, baseIteratee(predicate, 3), index);
  1350. }
  1351. /**
  1352. * Flattens `array` a single level deep.
  1353. *
  1354. * @static
  1355. * @memberOf _
  1356. * @since 0.1.0
  1357. * @category Array
  1358. * @param {Array} array The array to flatten.
  1359. * @returns {Array} Returns the new flattened array.
  1360. * @example
  1361. *
  1362. * _.flatten([1, [2, [3, [4]], 5]]);
  1363. * // => [1, 2, [3, [4]], 5]
  1364. */
  1365. function flatten(array) {
  1366. var length = array ? array.length : 0;
  1367. return length ? baseFlatten(array, 1) : [];
  1368. }
  1369. /**
  1370. * Recursively flattens `array`.
  1371. *
  1372. * @static
  1373. * @memberOf _
  1374. * @since 3.0.0
  1375. * @category Array
  1376. * @param {Array} array The array to flatten.
  1377. * @returns {Array} Returns the new flattened array.
  1378. * @example
  1379. *
  1380. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  1381. * // => [1, 2, 3, 4, 5]
  1382. */
  1383. function flattenDeep(array) {
  1384. var length = array ? array.length : 0;
  1385. return length ? baseFlatten(array, INFINITY) : [];
  1386. }
  1387. /**
  1388. * Gets the first element of `array`.
  1389. *
  1390. * @static
  1391. * @memberOf _
  1392. * @since 0.1.0
  1393. * @alias first
  1394. * @category Array
  1395. * @param {Array} array The array to query.
  1396. * @returns {*} Returns the first element of `array`.
  1397. * @example
  1398. *
  1399. * _.head([1, 2, 3]);
  1400. * // => 1
  1401. *
  1402. * _.head([]);
  1403. * // => undefined
  1404. */
  1405. function head(array) {
  1406. return (array && array.length) ? array[0] : undefined;
  1407. }
  1408. /**
  1409. * Gets the index at which the first occurrence of `value` is found in `array`
  1410. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  1411. * for equality comparisons. If `fromIndex` is negative, it's used as the
  1412. * offset from the end of `array`.
  1413. *
  1414. * @static
  1415. * @memberOf _
  1416. * @since 0.1.0
  1417. * @category Array
  1418. * @param {Array} array The array to inspect.
  1419. * @param {*} value The value to search for.
  1420. * @param {number} [fromIndex=0] The index to search from.
  1421. * @returns {number} Returns the index of the matched value, else `-1`.
  1422. * @example
  1423. *
  1424. * _.indexOf([1, 2, 1, 2], 2);
  1425. * // => 1
  1426. *
  1427. * // Search from the `fromIndex`.
  1428. * _.indexOf([1, 2, 1, 2], 2, 2);
  1429. * // => 3
  1430. */
  1431. function indexOf(array, value, fromIndex) {
  1432. var length = array ? array.length : 0;
  1433. if (typeof fromIndex == 'number') {
  1434. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
  1435. } else {
  1436. fromIndex = 0;
  1437. }
  1438. var index = (fromIndex || 0) - 1,
  1439. isReflexive = value === value;
  1440. while (++index < length) {
  1441. var other = array[index];
  1442. if ((isReflexive ? other === value : other !== other)) {
  1443. return index;
  1444. }
  1445. }
  1446. return -1;
  1447. }
  1448. /**
  1449. * Gets the last element of `array`.
  1450. *
  1451. * @static
  1452. * @memberOf _
  1453. * @since 0.1.0
  1454. * @category Array
  1455. * @param {Array} array The array to query.
  1456. * @returns {*} Returns the last element of `array`.
  1457. * @example
  1458. *
  1459. * _.last([1, 2, 3]);
  1460. * // => 3
  1461. */
  1462. function last(array) {
  1463. var length = array ? array.length : 0;
  1464. return length ? array[length - 1] : undefined;
  1465. }
  1466. /**
  1467. * Creates a slice of `array` from `start` up to, but not including, `end`.
  1468. *
  1469. * **Note:** This method is used instead of
  1470. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  1471. * returned.
  1472. *
  1473. * @static
  1474. * @memberOf _
  1475. * @since 3.0.0
  1476. * @category Array
  1477. * @param {Array} array The array to slice.
  1478. * @param {number} [start=0] The start position.
  1479. * @param {number} [end=array.length] The end position.
  1480. * @returns {Array} Returns the slice of `array`.
  1481. */
  1482. function slice(array, start, end) {
  1483. var length = array ? array.length : 0;
  1484. start = start == null ? 0 : +start;
  1485. end = end === undefined ? length : +end;
  1486. return length ? baseSlice(array, start, end) : [];
  1487. }
  1488. /*------------------------------------------------------------------------*/
  1489. /**
  1490. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  1491. * chain sequences enabled. The result of such sequences must be unwrapped
  1492. * with `_#value`.
  1493. *
  1494. * @static
  1495. * @memberOf _
  1496. * @since 1.3.0
  1497. * @category Seq
  1498. * @param {*} value The value to wrap.
  1499. * @returns {Object} Returns the new `lodash` wrapper instance.
  1500. * @example
  1501. *
  1502. * var users = [
  1503. * { 'user': 'barney', 'age': 36 },
  1504. * { 'user': 'fred', 'age': 40 },
  1505. * { 'user': 'pebbles', 'age': 1 }
  1506. * ];
  1507. *
  1508. * var youngest = _
  1509. * .chain(users)
  1510. * .sortBy('age')
  1511. * .map(function(o) {
  1512. * return o.user + ' is ' + o.age;
  1513. * })
  1514. * .head()
  1515. * .value();
  1516. * // => 'pebbles is 1'
  1517. */
  1518. function chain(value) {
  1519. var result = lodash(value);
  1520. result.__chain__ = true;
  1521. return result;
  1522. }
  1523. /**
  1524. * This method invokes `interceptor` and returns `value`. The interceptor
  1525. * is invoked with one argument; (value). The purpose of this method is to
  1526. * "tap into" a method chain sequence in order to modify intermediate results.
  1527. *
  1528. * @static
  1529. * @memberOf _
  1530. * @since 0.1.0
  1531. * @category Seq
  1532. * @param {*} value The value to provide to `interceptor`.
  1533. * @param {Function} interceptor The function to invoke.
  1534. * @returns {*} Returns `value`.
  1535. * @example
  1536. *
  1537. * _([1, 2, 3])
  1538. * .tap(function(array) {
  1539. * // Mutate input array.
  1540. * array.pop();
  1541. * })
  1542. * .reverse()
  1543. * .value();
  1544. * // => [2, 1]
  1545. */
  1546. function tap(value, interceptor) {
  1547. interceptor(value);
  1548. return value;
  1549. }
  1550. /**
  1551. * This method is like `_.tap` except that it returns the result of `interceptor`.
  1552. * The purpose of this method is to "pass thru" values replacing intermediate
  1553. * results in a method chain sequence.
  1554. *
  1555. * @static
  1556. * @memberOf _
  1557. * @since 3.0.0
  1558. * @category Seq
  1559. * @param {*} value The value to provide to `interceptor`.
  1560. * @param {Function} interceptor The function to invoke.
  1561. * @returns {*} Returns the result of `interceptor`.
  1562. * @example
  1563. *
  1564. * _(' abc ')
  1565. * .chain()
  1566. * .trim()
  1567. * .thru(function(value) {
  1568. * return [value];
  1569. * })
  1570. * .value();
  1571. * // => ['abc']
  1572. */
  1573. function thru(value, interceptor) {
  1574. return interceptor(value);
  1575. }
  1576. /**
  1577. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  1578. *
  1579. * @name chain
  1580. * @memberOf _
  1581. * @since 0.1.0
  1582. * @category Seq
  1583. * @returns {Object} Returns the new `lodash` wrapper instance.
  1584. * @example
  1585. *
  1586. * var users = [
  1587. * { 'user': 'barney', 'age': 36 },
  1588. * { 'user': 'fred', 'age': 40 }
  1589. * ];
  1590. *
  1591. * // A sequence without explicit chaining.
  1592. * _(users).head();
  1593. * // => { 'user': 'barney', 'age': 36 }
  1594. *
  1595. * // A sequence with explicit chaining.
  1596. * _(users)
  1597. * .chain()
  1598. * .head()
  1599. * .pick('user')
  1600. * .value();
  1601. * // => { 'user': 'barney' }
  1602. */
  1603. function wrapperChain() {
  1604. return chain(this);
  1605. }
  1606. /**
  1607. * Executes the chain sequence to resolve the unwrapped value.
  1608. *
  1609. * @name value
  1610. * @memberOf _
  1611. * @since 0.1.0
  1612. * @alias toJSON, valueOf
  1613. * @category Seq
  1614. * @returns {*} Returns the resolved unwrapped value.
  1615. * @example
  1616. *
  1617. * _([1, 2, 3]).value();
  1618. * // => [1, 2, 3]
  1619. */
  1620. function wrapperValue() {
  1621. return baseWrapperValue(this.__wrapped__, this.__actions__);
  1622. }
  1623. /*------------------------------------------------------------------------*/
  1624. /**
  1625. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  1626. * Iteration is stopped once `predicate` returns falsey. The predicate is
  1627. * invoked with three arguments: (value, index|key, collection).
  1628. *
  1629. * **Note:** This method returns `true` for
  1630. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  1631. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  1632. * elements of empty collections.
  1633. *
  1634. * @static
  1635. * @memberOf _
  1636. * @since 0.1.0
  1637. * @category Collection
  1638. * @param {Array|Object} collection The collection to iterate over.
  1639. * @param {Function} [predicate=_.identity]
  1640. * The function invoked per iteration.
  1641. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  1642. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1643. * else `false`.
  1644. * @example
  1645. *
  1646. * _.every([true, 1, null, 'yes'], Boolean);
  1647. * // => false
  1648. *
  1649. * var users = [
  1650. * { 'user': 'barney', 'age': 36, 'active': false },
  1651. * { 'user': 'fred', 'age': 40, 'active': false }
  1652. * ];
  1653. *
  1654. * // The `_.matches` iteratee shorthand.
  1655. * _.every(users, { 'user': 'barney', 'active': false });
  1656. * // => false
  1657. *
  1658. * // The `_.matchesProperty` iteratee shorthand.
  1659. * _.every(users, ['active', false]);
  1660. * // => true
  1661. *
  1662. * // The `_.property` iteratee shorthand.
  1663. * _.every(users, 'active');
  1664. * // => false
  1665. */
  1666. function every(collection, predicate, guard) {
  1667. predicate = guard ? undefined : predicate;
  1668. return baseEvery(collection, baseIteratee(predicate));
  1669. }
  1670. /**
  1671. * Iterates over elements of `collection`, returning an array of all elements
  1672. * `predicate` returns truthy for. The predicate is invoked with three
  1673. * arguments: (value, index|key, collection).
  1674. *
  1675. * **Note:** Unlike `_.remove`, this method returns a new array.
  1676. *
  1677. * @static
  1678. * @memberOf _
  1679. * @since 0.1.0
  1680. * @category Collection
  1681. * @param {Array|Object} collection The collection to iterate over.
  1682. * @param {Function} [predicate=_.identity]
  1683. * The function invoked per iteration.
  1684. * @returns {Array} Returns the new filtered array.
  1685. * @see _.reject
  1686. * @example
  1687. *
  1688. * var users = [
  1689. * { 'user': 'barney', 'age': 36, 'active': true },
  1690. * { 'user': 'fred', 'age': 40, 'active': false }
  1691. * ];
  1692. *
  1693. * _.filter(users, function(o) { return !o.active; });
  1694. * // => objects for ['fred']
  1695. *
  1696. * // The `_.matches` iteratee shorthand.
  1697. * _.filter(users, { 'age': 36, 'active': true });
  1698. * // => objects for ['barney']
  1699. *
  1700. * // The `_.matchesProperty` iteratee shorthand.
  1701. * _.filter(users, ['active', false]);
  1702. * // => objects for ['fred']
  1703. *
  1704. * // The `_.property` iteratee shorthand.
  1705. * _.filter(users, 'active');
  1706. * // => objects for ['barney']
  1707. */
  1708. function filter(collection, predicate) {
  1709. return baseFilter(collection, baseIteratee(predicate));
  1710. }
  1711. /**
  1712. * Iterates over elements of `collection`, returning the first element
  1713. * `predicate` returns truthy for. The predicate is invoked with three
  1714. * arguments: (value, index|key, collection).
  1715. *
  1716. * @static
  1717. * @memberOf _
  1718. * @since 0.1.0
  1719. * @category Collection
  1720. * @param {Array|Object} collection The collection to inspect.
  1721. * @param {Function} [predicate=_.identity]
  1722. * The function invoked per iteration.
  1723. * @param {number} [fromIndex=0] The index to search from.
  1724. * @returns {*} Returns the matched element, else `undefined`.
  1725. * @example
  1726. *
  1727. * var users = [
  1728. * { 'user': 'barney', 'age': 36, 'active': true },
  1729. * { 'user': 'fred', 'age': 40, 'active': false },
  1730. * { 'user': 'pebbles', 'age': 1, 'active': true }
  1731. * ];
  1732. *
  1733. * _.find(users, function(o) { return o.age < 40; });
  1734. * // => object for 'barney'
  1735. *
  1736. * // The `_.matches` iteratee shorthand.
  1737. * _.find(users, { 'age': 1, 'active': true });
  1738. * // => object for 'pebbles'
  1739. *
  1740. * // The `_.matchesProperty` iteratee shorthand.
  1741. * _.find(users, ['active', false]);
  1742. * // => object for 'fred'
  1743. *
  1744. * // The `_.property` iteratee shorthand.
  1745. * _.find(users, 'active');
  1746. * // => object for 'barney'
  1747. */
  1748. var find = createFind(findIndex);
  1749. /**
  1750. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  1751. * The iteratee is invoked with three arguments: (value, index|key, collection).
  1752. * Iteratee functions may exit iteration early by explicitly returning `false`.
  1753. *
  1754. * **Note:** As with other "Collections" methods, objects with a "length"
  1755. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  1756. * or `_.forOwn` for object iteration.
  1757. *
  1758. * @static
  1759. * @memberOf _
  1760. * @since 0.1.0
  1761. * @alias each
  1762. * @category Collection
  1763. * @param {Array|Object} collection The collection to iterate over.
  1764. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  1765. * @returns {Array|Object} Returns `collection`.
  1766. * @see _.forEachRight
  1767. * @example
  1768. *
  1769. * _([1, 2]).forEach(function(value) {
  1770. * console.log(value);
  1771. * });
  1772. * // => Logs `1` then `2`.
  1773. *
  1774. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  1775. * console.log(key);
  1776. * });
  1777. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  1778. */
  1779. function forEach(collection, iteratee) {
  1780. return baseEach(collection, baseIteratee(iteratee));
  1781. }
  1782. /**
  1783. * Creates an array of values by running each element in `collection` thru
  1784. * `iteratee`. The iteratee is invoked with three arguments:
  1785. * (value, index|key, collection).
  1786. *
  1787. * Many lodash methods are guarded to work as iteratees for methods like
  1788. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  1789. *
  1790. * The guarded methods are:
  1791. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  1792. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  1793. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  1794. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  1795. *
  1796. * @static
  1797. * @memberOf _
  1798. * @since 0.1.0
  1799. * @category Collection
  1800. * @param {Array|Object} collection The collection to iterate over.
  1801. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  1802. * @returns {Array} Returns the new mapped array.
  1803. * @example
  1804. *
  1805. * function square(n) {
  1806. * return n * n;
  1807. * }
  1808. *
  1809. * _.map([4, 8], square);
  1810. * // => [16, 64]
  1811. *
  1812. * _.map({ 'a': 4, 'b': 8 }, square);
  1813. * // => [16, 64] (iteration order is not guaranteed)
  1814. *
  1815. * var users = [
  1816. * { 'user': 'barney' },
  1817. * { 'user': 'fred' }
  1818. * ];
  1819. *
  1820. * // The `_.property` iteratee shorthand.
  1821. * _.map(users, 'user');
  1822. * // => ['barney', 'fred']
  1823. */
  1824. function map(collection, iteratee) {
  1825. return baseMap(collection, baseIteratee(iteratee));
  1826. }
  1827. /**
  1828. * Reduces `collection` to a value which is the accumulated result of running
  1829. * each element in `collection` thru `iteratee`, where each successive
  1830. * invocation is supplied the return value of the previous. If `accumulator`
  1831. * is not given, the first element of `collection` is used as the initial
  1832. * value. The iteratee is invoked with four arguments:
  1833. * (accumulator, value, index|key, collection).
  1834. *
  1835. * Many lodash methods are guarded to work as iteratees for methods like
  1836. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  1837. *
  1838. * The guarded methods are:
  1839. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  1840. * and `sortBy`
  1841. *
  1842. * @static
  1843. * @memberOf _
  1844. * @since 0.1.0
  1845. * @category Collection
  1846. * @param {Array|Object} collection The collection to iterate over.
  1847. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  1848. * @param {*} [accumulator] The initial value.
  1849. * @returns {*} Returns the accumulated value.
  1850. * @see _.reduceRight
  1851. * @example
  1852. *
  1853. * _.reduce([1, 2], function(sum, n) {
  1854. * return sum + n;
  1855. * }, 0);
  1856. * // => 3
  1857. *
  1858. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  1859. * (result[value] || (result[value] = [])).push(key);
  1860. * return result;
  1861. * }, {});
  1862. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  1863. */
  1864. function reduce(collection, iteratee, accumulator) {
  1865. return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
  1866. }
  1867. /**
  1868. * Gets the size of `collection` by returning its length for array-like
  1869. * values or the number of own enumerable string keyed properties for objects.
  1870. *
  1871. * @static
  1872. * @memberOf _
  1873. * @since 0.1.0
  1874. * @category Collection
  1875. * @param {Array|Object|string} collection The collection to inspect.
  1876. * @returns {number} Returns the collection size.
  1877. * @example
  1878. *
  1879. * _.size([1, 2, 3]);
  1880. * // => 3
  1881. *
  1882. * _.size({ 'a': 1, 'b': 2 });
  1883. * // => 2
  1884. *
  1885. * _.size('pebbles');
  1886. * // => 7
  1887. */
  1888. function size(collection) {
  1889. if (collection == null) {
  1890. return 0;
  1891. }
  1892. collection = isArrayLike(collection) ? collection : nativeKeys(collection);
  1893. return collection.length;
  1894. }
  1895. /**
  1896. * Checks if `predicate` returns truthy for **any** element of `collection`.
  1897. * Iteration is stopped once `predicate` returns truthy. The predicate is
  1898. * invoked with three arguments: (value, index|key, collection).
  1899. *
  1900. * @static
  1901. * @memberOf _
  1902. * @since 0.1.0
  1903. * @category Collection
  1904. * @param {Array|Object} collection The collection to iterate over.
  1905. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  1906. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  1907. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1908. * else `false`.
  1909. * @example
  1910. *
  1911. * _.some([null, 0, 'yes', false], Boolean);
  1912. * // => true
  1913. *
  1914. * var users = [
  1915. * { 'user': 'barney', 'active': true },
  1916. * { 'user': 'fred', 'active': false }
  1917. * ];
  1918. *
  1919. * // The `_.matches` iteratee shorthand.
  1920. * _.some(users, { 'user': 'barney', 'active': false });
  1921. * // => false
  1922. *
  1923. * // The `_.matchesProperty` iteratee shorthand.
  1924. * _.some(users, ['active', false]);
  1925. * // => true
  1926. *
  1927. * // The `_.property` iteratee shorthand.
  1928. * _.some(users, 'active');
  1929. * // => true
  1930. */
  1931. function some(collection, predicate, guard) {
  1932. predicate = guard ? undefined : predicate;
  1933. return baseSome(collection, baseIteratee(predicate));
  1934. }
  1935. /**
  1936. * Creates an array of elements, sorted in ascending order by the results of
  1937. * running each element in a collection thru each iteratee. This method
  1938. * performs a stable sort, that is, it preserves the original sort order of
  1939. * equal elements. The iteratees are invoked with one argument: (value).
  1940. *
  1941. * @static
  1942. * @memberOf _
  1943. * @since 0.1.0
  1944. * @category Collection
  1945. * @param {Array|Object} collection The collection to iterate over.
  1946. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  1947. * The iteratees to sort by.
  1948. * @returns {Array} Returns the new sorted array.
  1949. * @example
  1950. *
  1951. * var users = [
  1952. * { 'user': 'fred', 'age': 48 },
  1953. * { 'user': 'barney', 'age': 36 },
  1954. * { 'user': 'fred', 'age': 40 },
  1955. * { 'user': 'barney', 'age': 34 }
  1956. * ];
  1957. *
  1958. * _.sortBy(users, function(o) { return o.user; });
  1959. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  1960. *
  1961. * _.sortBy(users, ['user', 'age']);
  1962. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  1963. *
  1964. * _.sortBy(users, 'user', function(o) {
  1965. * return Math.floor(o.age / 10);
  1966. * });
  1967. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  1968. */
  1969. function sortBy(collection, iteratee) {
  1970. var index = 0;
  1971. iteratee = baseIteratee(iteratee);
  1972. return baseMap(baseMap(collection, function(value, key, collection) {
  1973. return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
  1974. }).sort(function(object, other) {
  1975. return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
  1976. }), baseProperty('value'));
  1977. }
  1978. /*------------------------------------------------------------------------*/
  1979. /**
  1980. * Creates a function that invokes `func`, with the `this` binding and arguments
  1981. * of the created function, while it's called less than `n` times. Subsequent
  1982. * calls to the created function return the result of the last `func` invocation.
  1983. *
  1984. * @static
  1985. * @memberOf _
  1986. * @since 3.0.0
  1987. * @category Function
  1988. * @param {number} n The number of calls at which `func` is no longer invoked.
  1989. * @param {Function} func The function to restrict.
  1990. * @returns {Function} Returns the new restricted function.
  1991. * @example
  1992. *
  1993. * jQuery(element).on('click', _.before(5, addContactToList));
  1994. * // => Allows adding up to 4 contacts to the list.
  1995. */
  1996. function before(n, func) {
  1997. var result;
  1998. if (typeof func != 'function') {
  1999. throw new TypeError(FUNC_ERROR_TEXT);
  2000. }
  2001. n = toInteger(n);
  2002. return function() {
  2003. if (--n > 0) {
  2004. result = func.apply(this, arguments);
  2005. }
  2006. if (n <= 1) {
  2007. func = undefined;
  2008. }
  2009. return result;
  2010. };
  2011. }
  2012. /**
  2013. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  2014. * and `partials` prepended to the arguments it receives.
  2015. *
  2016. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  2017. * may be used as a placeholder for partially applied arguments.
  2018. *
  2019. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  2020. * property of bound functions.
  2021. *
  2022. * @static
  2023. * @memberOf _
  2024. * @since 0.1.0
  2025. * @category Function
  2026. * @param {Function} func The function to bind.
  2027. * @param {*} thisArg The `this` binding of `func`.
  2028. * @param {...*} [partials] The arguments to be partially applied.
  2029. * @returns {Function} Returns the new bound function.
  2030. * @example
  2031. *
  2032. * function greet(greeting, punctuation) {
  2033. * return greeting + ' ' + this.user + punctuation;
  2034. * }
  2035. *
  2036. * var object = { 'user': 'fred' };
  2037. *
  2038. * var bound = _.bind(greet, object, 'hi');
  2039. * bound('!');
  2040. * // => 'hi fred!'
  2041. *
  2042. * // Bound with placeholders.
  2043. * var bound = _.bind(greet, object, _, '!');
  2044. * bound('hi');
  2045. * // => 'hi fred!'
  2046. */
  2047. var bind = baseRest(function(func, thisArg, partials) {
  2048. return createPartial(func, BIND_FLAG | PARTIAL_FLAG, thisArg, partials);
  2049. });
  2050. /**
  2051. * Defers invoking the `func` until the current call stack has cleared. Any
  2052. * additional arguments are provided to `func` when it's invoked.
  2053. *
  2054. * @static
  2055. * @memberOf _
  2056. * @since 0.1.0
  2057. * @category Function
  2058. * @param {Function} func The function to defer.
  2059. * @param {...*} [args] The arguments to invoke `func` with.
  2060. * @returns {number} Returns the timer id.
  2061. * @example
  2062. *
  2063. * _.defer(function(text) {
  2064. * console.log(text);
  2065. * }, 'deferred');
  2066. * // => Logs 'deferred' after one or more milliseconds.
  2067. */
  2068. var defer = baseRest(function(func, args) {
  2069. return baseDelay(func, 1, args);
  2070. });
  2071. /**
  2072. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  2073. * provided to `func` when it's invoked.
  2074. *
  2075. * @static
  2076. * @memberOf _
  2077. * @since 0.1.0
  2078. * @category Function
  2079. * @param {Function} func The function to delay.
  2080. * @param {number} wait The number of milliseconds to delay invocation.
  2081. * @param {...*} [args] The arguments to invoke `func` with.
  2082. * @returns {number} Returns the timer id.
  2083. * @example
  2084. *
  2085. * _.delay(function(text) {
  2086. * console.log(text);
  2087. * }, 1000, 'later');
  2088. * // => Logs 'later' after one second.
  2089. */
  2090. var delay = baseRest(function(func, wait, args) {
  2091. return baseDelay(func, toNumber(wait) || 0, args);
  2092. });
  2093. /**
  2094. * Creates a function that negates the result of the predicate `func`. The
  2095. * `func` predicate is invoked with the `this` binding and arguments of the
  2096. * created function.
  2097. *
  2098. * @static
  2099. * @memberOf _
  2100. * @since 3.0.0
  2101. * @category Function
  2102. * @param {Function} predicate The predicate to negate.
  2103. * @returns {Function} Returns the new negated function.
  2104. * @example
  2105. *
  2106. * function isEven(n) {
  2107. * return n % 2 == 0;
  2108. * }
  2109. *
  2110. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  2111. * // => [1, 3, 5]
  2112. */
  2113. function negate(predicate) {
  2114. if (typeof predicate != 'function') {
  2115. throw new TypeError(FUNC_ERROR_TEXT);
  2116. }
  2117. return function() {
  2118. var args = arguments;
  2119. return !predicate.apply(this, args);
  2120. };
  2121. }
  2122. /**
  2123. * Creates a function that is restricted to invoking `func` once. Repeat calls
  2124. * to the function return the value of the first invocation. The `func` is
  2125. * invoked with the `this` binding and arguments of the created function.
  2126. *
  2127. * @static
  2128. * @memberOf _
  2129. * @since 0.1.0
  2130. * @category Function
  2131. * @param {Function} func The function to restrict.
  2132. * @returns {Function} Returns the new restricted function.
  2133. * @example
  2134. *
  2135. * var initialize = _.once(createApplication);
  2136. * initialize();
  2137. * initialize();
  2138. * // => `createApplication` is invoked once
  2139. */
  2140. function once(func) {
  2141. return before(2, func);
  2142. }
  2143. /*------------------------------------------------------------------------*/
  2144. /**
  2145. * Creates a shallow clone of `value`.
  2146. *
  2147. * **Note:** This method is loosely based on the
  2148. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  2149. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  2150. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  2151. * arrays. The own enumerable properties of `arguments` objects are cloned
  2152. * as plain objects. An empty object is returned for uncloneable values such
  2153. * as error objects, functions, DOM nodes, and WeakMaps.
  2154. *
  2155. * @static
  2156. * @memberOf _
  2157. * @since 0.1.0
  2158. * @category Lang
  2159. * @param {*} value The value to clone.
  2160. * @returns {*} Returns the cloned value.
  2161. * @see _.cloneDeep
  2162. * @example
  2163. *
  2164. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  2165. *
  2166. * var shallow = _.clone(objects);
  2167. * console.log(shallow[0] === objects[0]);
  2168. * // => true
  2169. */
  2170. function clone(value) {
  2171. if (!isObject(value)) {
  2172. return value;
  2173. }
  2174. return isArray(value) ? copyArray(value) : copyObject(value, nativeKeys(value));
  2175. }
  2176. /**
  2177. * Performs a
  2178. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2179. * comparison between two values to determine if they are equivalent.
  2180. *
  2181. * @static
  2182. * @memberOf _
  2183. * @since 4.0.0
  2184. * @category Lang
  2185. * @param {*} value The value to compare.
  2186. * @param {*} other The other value to compare.
  2187. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2188. * @example
  2189. *
  2190. * var object = { 'a': 1 };
  2191. * var other = { 'a': 1 };
  2192. *
  2193. * _.eq(object, object);
  2194. * // => true
  2195. *
  2196. * _.eq(object, other);
  2197. * // => false
  2198. *
  2199. * _.eq('a', 'a');
  2200. * // => true
  2201. *
  2202. * _.eq('a', Object('a'));
  2203. * // => false
  2204. *
  2205. * _.eq(NaN, NaN);
  2206. * // => true
  2207. */
  2208. function eq(value, other) {
  2209. return value === other || (value !== value && other !== other);
  2210. }
  2211. /**
  2212. * Checks if `value` is likely an `arguments` object.
  2213. *
  2214. * @static
  2215. * @memberOf _
  2216. * @since 0.1.0
  2217. * @category Lang
  2218. * @param {*} value The value to check.
  2219. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2220. * else `false`.
  2221. * @example
  2222. *
  2223. * _.isArguments(function() { return arguments; }());
  2224. * // => true
  2225. *
  2226. * _.isArguments([1, 2, 3]);
  2227. * // => false
  2228. */
  2229. function isArguments(value) {
  2230. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  2231. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  2232. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  2233. }
  2234. /**
  2235. * Checks if `value` is classified as an `Array` object.
  2236. *
  2237. * @static
  2238. * @memberOf _
  2239. * @since 0.1.0
  2240. * @category Lang
  2241. * @param {*} value The value to check.
  2242. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  2243. * @example
  2244. *
  2245. * _.isArray([1, 2, 3]);
  2246. * // => true
  2247. *
  2248. * _.isArray(document.body.children);
  2249. * // => false
  2250. *
  2251. * _.isArray('abc');
  2252. * // => false
  2253. *
  2254. * _.isArray(_.noop);
  2255. * // => false
  2256. */
  2257. var isArray = Array.isArray;
  2258. /**
  2259. * Checks if `value` is array-like. A value is considered array-like if it's
  2260. * not a function and has a `value.length` that's an integer greater than or
  2261. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  2262. *
  2263. * @static
  2264. * @memberOf _
  2265. * @since 4.0.0
  2266. * @category Lang
  2267. * @param {*} value The value to check.
  2268. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  2269. * @example
  2270. *
  2271. * _.isArrayLike([1, 2, 3]);
  2272. * // => true
  2273. *
  2274. * _.isArrayLike(document.body.children);
  2275. * // => true
  2276. *
  2277. * _.isArrayLike('abc');
  2278. * // => true
  2279. *
  2280. * _.isArrayLike(_.noop);
  2281. * // => false
  2282. */
  2283. function isArrayLike(value) {
  2284. return value != null && isLength(value.length) && !isFunction(value);
  2285. }
  2286. /**
  2287. * This method is like `_.isArrayLike` except that it also checks if `value`
  2288. * is an object.
  2289. *
  2290. * @static
  2291. * @memberOf _
  2292. * @since 4.0.0
  2293. * @category Lang
  2294. * @param {*} value The value to check.
  2295. * @returns {boolean} Returns `true` if `value` is an array-like object,
  2296. * else `false`.
  2297. * @example
  2298. *
  2299. * _.isArrayLikeObject([1, 2, 3]);
  2300. * // => true
  2301. *
  2302. * _.isArrayLikeObject(document.body.children);
  2303. * // => true
  2304. *
  2305. * _.isArrayLikeObject('abc');
  2306. * // => false
  2307. *
  2308. * _.isArrayLikeObject(_.noop);
  2309. * // => false
  2310. */
  2311. function isArrayLikeObject(value) {
  2312. return isObjectLike(value) && isArrayLike(value);
  2313. }
  2314. /**
  2315. * Checks if `value` is classified as a boolean primitive or object.
  2316. *
  2317. * @static
  2318. * @memberOf _
  2319. * @since 0.1.0
  2320. * @category Lang
  2321. * @param {*} value The value to check.
  2322. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  2323. * @example
  2324. *
  2325. * _.isBoolean(false);
  2326. * // => true
  2327. *
  2328. * _.isBoolean(null);
  2329. * // => false
  2330. */
  2331. function isBoolean(value) {
  2332. return value === true || value === false ||
  2333. (isObjectLike(value) && objectToString.call(value) == boolTag);
  2334. }
  2335. /**
  2336. * Checks if `value` is classified as a `Date` object.
  2337. *
  2338. * @static
  2339. * @memberOf _
  2340. * @since 0.1.0
  2341. * @category Lang
  2342. * @param {*} value The value to check.
  2343. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2344. * @example
  2345. *
  2346. * _.isDate(new Date);
  2347. * // => true
  2348. *
  2349. * _.isDate('Mon April 23 2012');
  2350. * // => false
  2351. */
  2352. var isDate = baseIsDate;
  2353. /**
  2354. * Checks if `value` is an empty object, collection, map, or set.
  2355. *
  2356. * Objects are considered empty if they have no own enumerable string keyed
  2357. * properties.
  2358. *
  2359. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  2360. * jQuery-like collections are considered empty if they have a `length` of `0`.
  2361. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  2362. *
  2363. * @static
  2364. * @memberOf _
  2365. * @since 0.1.0
  2366. * @category Lang
  2367. * @param {*} value The value to check.
  2368. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  2369. * @example
  2370. *
  2371. * _.isEmpty(null);
  2372. * // => true
  2373. *
  2374. * _.isEmpty(true);
  2375. * // => true
  2376. *
  2377. * _.isEmpty(1);
  2378. * // => true
  2379. *
  2380. * _.isEmpty([1, 2, 3]);
  2381. * // => false
  2382. *
  2383. * _.isEmpty({ 'a': 1 });
  2384. * // => false
  2385. */
  2386. function isEmpty(value) {
  2387. if (isArrayLike(value) &&
  2388. (isArray(value) || isString(value) ||
  2389. isFunction(value.splice) || isArguments(value))) {
  2390. return !value.length;
  2391. }
  2392. return !nativeKeys(value).length;
  2393. }
  2394. /**
  2395. * Performs a deep comparison between two values to determine if they are
  2396. * equivalent.
  2397. *
  2398. * **Note:** This method supports comparing arrays, array buffers, booleans,
  2399. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  2400. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  2401. * by their own, not inherited, enumerable properties. Functions and DOM
  2402. * nodes are **not** supported.
  2403. *
  2404. * @static
  2405. * @memberOf _
  2406. * @since 0.1.0
  2407. * @category Lang
  2408. * @param {*} value The value to compare.
  2409. * @param {*} other The other value to compare.
  2410. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2411. * @example
  2412. *
  2413. * var object = { 'a': 1 };
  2414. * var other = { 'a': 1 };
  2415. *
  2416. * _.isEqual(object, other);
  2417. * // => true
  2418. *
  2419. * object === other;
  2420. * // => false
  2421. */
  2422. function isEqual(value, other) {
  2423. return baseIsEqual(value, other);
  2424. }
  2425. /**
  2426. * Checks if `value` is a finite primitive number.
  2427. *
  2428. * **Note:** This method is based on
  2429. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  2430. *
  2431. * @static
  2432. * @memberOf _
  2433. * @since 0.1.0
  2434. * @category Lang
  2435. * @param {*} value The value to check.
  2436. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  2437. * @example
  2438. *
  2439. * _.isFinite(3);
  2440. * // => true
  2441. *
  2442. * _.isFinite(Number.MIN_VALUE);
  2443. * // => true
  2444. *
  2445. * _.isFinite(Infinity);
  2446. * // => false
  2447. *
  2448. * _.isFinite('3');
  2449. * // => false
  2450. */
  2451. function isFinite(value) {
  2452. return typeof value == 'number' && nativeIsFinite(value);
  2453. }
  2454. /**
  2455. * Checks if `value` is classified as a `Function` object.
  2456. *
  2457. * @static
  2458. * @memberOf _
  2459. * @since 0.1.0
  2460. * @category Lang
  2461. * @param {*} value The value to check.
  2462. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  2463. * @example
  2464. *
  2465. * _.isFunction(_);
  2466. * // => true
  2467. *
  2468. * _.isFunction(/abc/);
  2469. * // => false
  2470. */
  2471. function isFunction(value) {
  2472. // The use of `Object#toString` avoids issues with the `typeof` operator
  2473. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  2474. var tag = isObject(value) ? objectToString.call(value) : '';
  2475. return tag == funcTag || tag == genTag;
  2476. }
  2477. /**
  2478. * Checks if `value` is a valid array-like length.
  2479. *
  2480. * **Note:** This method is loosely based on
  2481. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  2482. *
  2483. * @static
  2484. * @memberOf _
  2485. * @since 4.0.0
  2486. * @category Lang
  2487. * @param {*} value The value to check.
  2488. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  2489. * @example
  2490. *
  2491. * _.isLength(3);
  2492. * // => true
  2493. *
  2494. * _.isLength(Number.MIN_VALUE);
  2495. * // => false
  2496. *
  2497. * _.isLength(Infinity);
  2498. * // => false
  2499. *
  2500. * _.isLength('3');
  2501. * // => false
  2502. */
  2503. function isLength(value) {
  2504. return typeof value == 'number' &&
  2505. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  2506. }
  2507. /**
  2508. * Checks if `value` is the
  2509. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  2510. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  2511. *
  2512. * @static
  2513. * @memberOf _
  2514. * @since 0.1.0
  2515. * @category Lang
  2516. * @param {*} value The value to check.
  2517. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  2518. * @example
  2519. *
  2520. * _.isObject({});
  2521. * // => true
  2522. *
  2523. * _.isObject([1, 2, 3]);
  2524. * // => true
  2525. *
  2526. * _.isObject(_.noop);
  2527. * // => true
  2528. *
  2529. * _.isObject(null);
  2530. * // => false
  2531. */
  2532. function isObject(value) {
  2533. var type = typeof value;
  2534. return !!value && (type == 'object' || type == 'function');
  2535. }
  2536. /**
  2537. * Checks if `value` is object-like. A value is object-like if it's not `null`
  2538. * and has a `typeof` result of "object".
  2539. *
  2540. * @static
  2541. * @memberOf _
  2542. * @since 4.0.0
  2543. * @category Lang
  2544. * @param {*} value The value to check.
  2545. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  2546. * @example
  2547. *
  2548. * _.isObjectLike({});
  2549. * // => true
  2550. *
  2551. * _.isObjectLike([1, 2, 3]);
  2552. * // => true
  2553. *
  2554. * _.isObjectLike(_.noop);
  2555. * // => false
  2556. *
  2557. * _.isObjectLike(null);
  2558. * // => false
  2559. */
  2560. function isObjectLike(value) {
  2561. return !!value && typeof value == 'object';
  2562. }
  2563. /**
  2564. * Checks if `value` is `NaN`.
  2565. *
  2566. * **Note:** This method is based on
  2567. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  2568. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  2569. * `undefined` and other non-number values.
  2570. *
  2571. * @static
  2572. * @memberOf _
  2573. * @since 0.1.0
  2574. * @category Lang
  2575. * @param {*} value The value to check.
  2576. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  2577. * @example
  2578. *
  2579. * _.isNaN(NaN);
  2580. * // => true
  2581. *
  2582. * _.isNaN(new Number(NaN));
  2583. * // => true
  2584. *
  2585. * isNaN(undefined);
  2586. * // => true
  2587. *
  2588. * _.isNaN(undefined);
  2589. * // => false
  2590. */
  2591. function isNaN(value) {
  2592. // An `NaN` primitive is the only value that is not equal to itself.
  2593. // Perform the `toStringTag` check first to avoid errors with some
  2594. // ActiveX objects in IE.
  2595. return isNumber(value) && value != +value;
  2596. }
  2597. /**
  2598. * Checks if `value` is `null`.
  2599. *
  2600. * @static
  2601. * @memberOf _
  2602. * @since 0.1.0
  2603. * @category Lang
  2604. * @param {*} value The value to check.
  2605. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  2606. * @example
  2607. *
  2608. * _.isNull(null);
  2609. * // => true
  2610. *
  2611. * _.isNull(void 0);
  2612. * // => false
  2613. */
  2614. function isNull(value) {
  2615. return value === null;
  2616. }
  2617. /**
  2618. * Checks if `value` is classified as a `Number` primitive or object.
  2619. *
  2620. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  2621. * classified as numbers, use the `_.isFinite` method.
  2622. *
  2623. * @static
  2624. * @memberOf _
  2625. * @since 0.1.0
  2626. * @category Lang
  2627. * @param {*} value The value to check.
  2628. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  2629. * @example
  2630. *
  2631. * _.isNumber(3);
  2632. * // => true
  2633. *
  2634. * _.isNumber(Number.MIN_VALUE);
  2635. * // => true
  2636. *
  2637. * _.isNumber(Infinity);
  2638. * // => true
  2639. *
  2640. * _.isNumber('3');
  2641. * // => false
  2642. */
  2643. function isNumber(value) {
  2644. return typeof value == 'number' ||
  2645. (isObjectLike(value) && objectToString.call(value) == numberTag);
  2646. }
  2647. /**
  2648. * Checks if `value` is classified as a `RegExp` object.
  2649. *
  2650. * @static
  2651. * @memberOf _
  2652. * @since 0.1.0
  2653. * @category Lang
  2654. * @param {*} value The value to check.
  2655. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  2656. * @example
  2657. *
  2658. * _.isRegExp(/abc/);
  2659. * // => true
  2660. *
  2661. * _.isRegExp('/abc/');
  2662. * // => false
  2663. */
  2664. var isRegExp = baseIsRegExp;
  2665. /**
  2666. * Checks if `value` is classified as a `String` primitive or object.
  2667. *
  2668. * @static
  2669. * @since 0.1.0
  2670. * @memberOf _
  2671. * @category Lang
  2672. * @param {*} value The value to check.
  2673. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  2674. * @example
  2675. *
  2676. * _.isString('abc');
  2677. * // => true
  2678. *
  2679. * _.isString(1);
  2680. * // => false
  2681. */
  2682. function isString(value) {
  2683. return typeof value == 'string' ||
  2684. (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
  2685. }
  2686. /**
  2687. * Checks if `value` is `undefined`.
  2688. *
  2689. * @static
  2690. * @since 0.1.0
  2691. * @memberOf _
  2692. * @category Lang
  2693. * @param {*} value The value to check.
  2694. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  2695. * @example
  2696. *
  2697. * _.isUndefined(void 0);
  2698. * // => true
  2699. *
  2700. * _.isUndefined(null);
  2701. * // => false
  2702. */
  2703. function isUndefined(value) {
  2704. return value === undefined;
  2705. }
  2706. /**
  2707. * Converts `value` to an array.
  2708. *
  2709. * @static
  2710. * @since 0.1.0
  2711. * @memberOf _
  2712. * @category Lang
  2713. * @param {*} value The value to convert.
  2714. * @returns {Array} Returns the converted array.
  2715. * @example
  2716. *
  2717. * _.toArray({ 'a': 1, 'b': 2 });
  2718. * // => [1, 2]
  2719. *
  2720. * _.toArray('abc');
  2721. * // => ['a', 'b', 'c']
  2722. *
  2723. * _.toArray(1);
  2724. * // => []
  2725. *
  2726. * _.toArray(null);
  2727. * // => []
  2728. */
  2729. function toArray(value) {
  2730. if (!isArrayLike(value)) {
  2731. return values(value);
  2732. }
  2733. return value.length ? copyArray(value) : [];
  2734. }
  2735. /**
  2736. * Converts `value` to an integer.
  2737. *
  2738. * **Note:** This method is loosely based on
  2739. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  2740. *
  2741. * @static
  2742. * @memberOf _
  2743. * @since 4.0.0
  2744. * @category Lang
  2745. * @param {*} value The value to convert.
  2746. * @returns {number} Returns the converted integer.
  2747. * @example
  2748. *
  2749. * _.toInteger(3.2);
  2750. * // => 3
  2751. *
  2752. * _.toInteger(Number.MIN_VALUE);
  2753. * // => 0
  2754. *
  2755. * _.toInteger(Infinity);
  2756. * // => 1.7976931348623157e+308
  2757. *
  2758. * _.toInteger('3.2');
  2759. * // => 3
  2760. */
  2761. var toInteger = Number;
  2762. /**
  2763. * Converts `value` to a number.
  2764. *
  2765. * @static
  2766. * @memberOf _
  2767. * @since 4.0.0
  2768. * @category Lang
  2769. * @param {*} value The value to process.
  2770. * @returns {number} Returns the number.
  2771. * @example
  2772. *
  2773. * _.toNumber(3.2);
  2774. * // => 3.2
  2775. *
  2776. * _.toNumber(Number.MIN_VALUE);
  2777. * // => 5e-324
  2778. *
  2779. * _.toNumber(Infinity);
  2780. * // => Infinity
  2781. *
  2782. * _.toNumber('3.2');
  2783. * // => 3.2
  2784. */
  2785. var toNumber = Number;
  2786. /**
  2787. * Converts `value` to a string. An empty string is returned for `null`
  2788. * and `undefined` values. The sign of `-0` is preserved.
  2789. *
  2790. * @static
  2791. * @memberOf _
  2792. * @since 4.0.0
  2793. * @category Lang
  2794. * @param {*} value The value to process.
  2795. * @returns {string} Returns the string.
  2796. * @example
  2797. *
  2798. * _.toString(null);
  2799. * // => ''
  2800. *
  2801. * _.toString(-0);
  2802. * // => '-0'
  2803. *
  2804. * _.toString([1, 2, 3]);
  2805. * // => '1,2,3'
  2806. */
  2807. function toString(value) {
  2808. if (typeof value == 'string') {
  2809. return value;
  2810. }
  2811. return value == null ? '' : (value + '');
  2812. }
  2813. /*------------------------------------------------------------------------*/
  2814. /**
  2815. * Assigns own enumerable string keyed properties of source objects to the
  2816. * destination object. Source objects are applied from left to right.
  2817. * Subsequent sources overwrite property assignments of previous sources.
  2818. *
  2819. * **Note:** This method mutates `object` and is loosely based on
  2820. * [`Object.assign`](https://mdn.io/Object/assign).
  2821. *
  2822. * @static
  2823. * @memberOf _
  2824. * @since 0.10.0
  2825. * @category Object
  2826. * @param {Object} object The destination object.
  2827. * @param {...Object} [sources] The source objects.
  2828. * @returns {Object} Returns `object`.
  2829. * @see _.assignIn
  2830. * @example
  2831. *
  2832. * function Foo() {
  2833. * this.a = 1;
  2834. * }
  2835. *
  2836. * function Bar() {
  2837. * this.c = 3;
  2838. * }
  2839. *
  2840. * Foo.prototype.b = 2;
  2841. * Bar.prototype.d = 4;
  2842. *
  2843. * _.assign({ 'a': 0 }, new Foo, new Bar);
  2844. * // => { 'a': 1, 'c': 3 }
  2845. */
  2846. var assign = createAssigner(function(object, source) {
  2847. copyObject(source, nativeKeys(source), object);
  2848. });
  2849. /**
  2850. * This method is like `_.assign` except that it iterates over own and
  2851. * inherited source properties.
  2852. *
  2853. * **Note:** This method mutates `object`.
  2854. *
  2855. * @static
  2856. * @memberOf _
  2857. * @since 4.0.0
  2858. * @alias extend
  2859. * @category Object
  2860. * @param {Object} object The destination object.
  2861. * @param {...Object} [sources] The source objects.
  2862. * @returns {Object} Returns `object`.
  2863. * @see _.assign
  2864. * @example
  2865. *
  2866. * function Foo() {
  2867. * this.a = 1;
  2868. * }
  2869. *
  2870. * function Bar() {
  2871. * this.c = 3;
  2872. * }
  2873. *
  2874. * Foo.prototype.b = 2;
  2875. * Bar.prototype.d = 4;
  2876. *
  2877. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  2878. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  2879. */
  2880. var assignIn = createAssigner(function(object, source) {
  2881. copyObject(source, nativeKeysIn(source), object);
  2882. });
  2883. /**
  2884. * This method is like `_.assignIn` except that it accepts `customizer`
  2885. * which is invoked to produce the assigned values. If `customizer` returns
  2886. * `undefined`, assignment is handled by the method instead. The `customizer`
  2887. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  2888. *
  2889. * **Note:** This method mutates `object`.
  2890. *
  2891. * @static
  2892. * @memberOf _
  2893. * @since 4.0.0
  2894. * @alias extendWith
  2895. * @category Object
  2896. * @param {Object} object The destination object.
  2897. * @param {...Object} sources The source objects.
  2898. * @param {Function} [customizer] The function to customize assigned values.
  2899. * @returns {Object} Returns `object`.
  2900. * @see _.assignWith
  2901. * @example
  2902. *
  2903. * function customizer(objValue, srcValue) {
  2904. * return _.isUndefined(objValue) ? srcValue : objValue;
  2905. * }
  2906. *
  2907. * var defaults = _.partialRight(_.assignInWith, customizer);
  2908. *
  2909. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  2910. * // => { 'a': 1, 'b': 2 }
  2911. */
  2912. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  2913. copyObject(source, keysIn(source), object, customizer);
  2914. });
  2915. /**
  2916. * Creates an object that inherits from the `prototype` object. If a
  2917. * `properties` object is given, its own enumerable string keyed properties
  2918. * are assigned to the created object.
  2919. *
  2920. * @static
  2921. * @memberOf _
  2922. * @since 2.3.0
  2923. * @category Object
  2924. * @param {Object} prototype The object to inherit from.
  2925. * @param {Object} [properties] The properties to assign to the object.
  2926. * @returns {Object} Returns the new object.
  2927. * @example
  2928. *
  2929. * function Shape() {
  2930. * this.x = 0;
  2931. * this.y = 0;
  2932. * }
  2933. *
  2934. * function Circle() {
  2935. * Shape.call(this);
  2936. * }
  2937. *
  2938. * Circle.prototype = _.create(Shape.prototype, {
  2939. * 'constructor': Circle
  2940. * });
  2941. *
  2942. * var circle = new Circle;
  2943. * circle instanceof Circle;
  2944. * // => true
  2945. *
  2946. * circle instanceof Shape;
  2947. * // => true
  2948. */
  2949. function create(prototype, properties) {
  2950. var result = baseCreate(prototype);
  2951. return properties ? assign(result, properties) : result;
  2952. }
  2953. /**
  2954. * Assigns own and inherited enumerable string keyed properties of source
  2955. * objects to the destination object for all destination properties that
  2956. * resolve to `undefined`. Source objects are applied from left to right.
  2957. * Once a property is set, additional values of the same property are ignored.
  2958. *
  2959. * **Note:** This method mutates `object`.
  2960. *
  2961. * @static
  2962. * @since 0.1.0
  2963. * @memberOf _
  2964. * @category Object
  2965. * @param {Object} object The destination object.
  2966. * @param {...Object} [sources] The source objects.
  2967. * @returns {Object} Returns `object`.
  2968. * @see _.defaultsDeep
  2969. * @example
  2970. *
  2971. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  2972. * // => { 'a': 1, 'b': 2 }
  2973. */
  2974. var defaults = baseRest(function(args) {
  2975. args.push(undefined, assignInDefaults);
  2976. return assignInWith.apply(undefined, args);
  2977. });
  2978. /**
  2979. * Checks if `path` is a direct property of `object`.
  2980. *
  2981. * @static
  2982. * @since 0.1.0
  2983. * @memberOf _
  2984. * @category Object
  2985. * @param {Object} object The object to query.
  2986. * @param {Array|string} path The path to check.
  2987. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  2988. * @example
  2989. *
  2990. * var object = { 'a': { 'b': 2 } };
  2991. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  2992. *
  2993. * _.has(object, 'a');
  2994. * // => true
  2995. *
  2996. * _.has(object, 'a.b');
  2997. * // => true
  2998. *
  2999. * _.has(object, ['a', 'b']);
  3000. * // => true
  3001. *
  3002. * _.has(other, 'a');
  3003. * // => false
  3004. */
  3005. function has(object, path) {
  3006. return object != null && hasOwnProperty.call(object, path);
  3007. }
  3008. /**
  3009. * Creates an array of the own enumerable property names of `object`.
  3010. *
  3011. * **Note:** Non-object values are coerced to objects. See the
  3012. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  3013. * for more details.
  3014. *
  3015. * @static
  3016. * @since 0.1.0
  3017. * @memberOf _
  3018. * @category Object
  3019. * @param {Object} object The object to query.
  3020. * @returns {Array} Returns the array of property names.
  3021. * @example
  3022. *
  3023. * function Foo() {
  3024. * this.a = 1;
  3025. * this.b = 2;
  3026. * }
  3027. *
  3028. * Foo.prototype.c = 3;
  3029. *
  3030. * _.keys(new Foo);
  3031. * // => ['a', 'b'] (iteration order is not guaranteed)
  3032. *
  3033. * _.keys('hi');
  3034. * // => ['0', '1']
  3035. */
  3036. var keys = nativeKeys;
  3037. /**
  3038. * Creates an array of the own and inherited enumerable property names of `object`.
  3039. *
  3040. * **Note:** Non-object values are coerced to objects.
  3041. *
  3042. * @static
  3043. * @memberOf _
  3044. * @since 3.0.0
  3045. * @category Object
  3046. * @param {Object} object The object to query.
  3047. * @returns {Array} Returns the array of property names.
  3048. * @example
  3049. *
  3050. * function Foo() {
  3051. * this.a = 1;
  3052. * this.b = 2;
  3053. * }
  3054. *
  3055. * Foo.prototype.c = 3;
  3056. *
  3057. * _.keysIn(new Foo);
  3058. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  3059. */
  3060. var keysIn = nativeKeysIn;
  3061. /**
  3062. * Creates an object composed of the picked `object` properties.
  3063. *
  3064. * @static
  3065. * @since 0.1.0
  3066. * @memberOf _
  3067. * @category Object
  3068. * @param {Object} object The source object.
  3069. * @param {...(string|string[])} [props] The property identifiers to pick.
  3070. * @returns {Object} Returns the new object.
  3071. * @example
  3072. *
  3073. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  3074. *
  3075. * _.pick(object, ['a', 'c']);
  3076. * // => { 'a': 1, 'c': 3 }
  3077. */
  3078. var pick = baseRest(function(object, props) {
  3079. return object == null ? {} : basePick(object, baseMap(baseFlatten(props, 1), toKey));
  3080. });
  3081. /**
  3082. * This method is like `_.get` except that if the resolved value is a
  3083. * function it's invoked with the `this` binding of its parent object and
  3084. * its result is returned.
  3085. *
  3086. * @static
  3087. * @since 0.1.0
  3088. * @memberOf _
  3089. * @category Object
  3090. * @param {Object} object The object to query.
  3091. * @param {Array|string} path The path of the property to resolve.
  3092. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  3093. * @returns {*} Returns the resolved value.
  3094. * @example
  3095. *
  3096. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  3097. *
  3098. * _.result(object, 'a[0].b.c1');
  3099. * // => 3
  3100. *
  3101. * _.result(object, 'a[0].b.c2');
  3102. * // => 4
  3103. *
  3104. * _.result(object, 'a[0].b.c3', 'default');
  3105. * // => 'default'
  3106. *
  3107. * _.result(object, 'a[0].b.c3', _.constant('default'));
  3108. * // => 'default'
  3109. */
  3110. function result(object, path, defaultValue) {
  3111. var value = object == null ? undefined : object[path];
  3112. if (value === undefined) {
  3113. value = defaultValue;
  3114. }
  3115. return isFunction(value) ? value.call(object) : value;
  3116. }
  3117. /**
  3118. * Creates an array of the own enumerable string keyed property values of `object`.
  3119. *
  3120. * **Note:** Non-object values are coerced to objects.
  3121. *
  3122. * @static
  3123. * @since 0.1.0
  3124. * @memberOf _
  3125. * @category Object
  3126. * @param {Object} object The object to query.
  3127. * @returns {Array} Returns the array of property values.
  3128. * @example
  3129. *
  3130. * function Foo() {
  3131. * this.a = 1;
  3132. * this.b = 2;
  3133. * }
  3134. *
  3135. * Foo.prototype.c = 3;
  3136. *
  3137. * _.values(new Foo);
  3138. * // => [1, 2] (iteration order is not guaranteed)
  3139. *
  3140. * _.values('hi');
  3141. * // => ['h', 'i']
  3142. */
  3143. function values(object) {
  3144. return object ? baseValues(object, keys(object)) : [];
  3145. }
  3146. /*------------------------------------------------------------------------*/
  3147. /**
  3148. * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
  3149. * their corresponding HTML entities.
  3150. *
  3151. * **Note:** No other characters are escaped. To escape additional
  3152. * characters use a third-party library like [_he_](https://mths.be/he).
  3153. *
  3154. * Though the ">" character is escaped for symmetry, characters like
  3155. * ">" and "/" don't need escaping in HTML and have no special meaning
  3156. * unless they're part of a tag or unquoted attribute value. See
  3157. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  3158. * (under "semi-related fun fact") for more details.
  3159. *
  3160. * Backticks are escaped because in IE < 9, they can break out of
  3161. * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
  3162. * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
  3163. * [#133](https://html5sec.org/#133) of the
  3164. * [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
  3165. *
  3166. * When working with HTML you should always
  3167. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  3168. * XSS vectors.
  3169. *
  3170. * @static
  3171. * @since 0.1.0
  3172. * @memberOf _
  3173. * @category String
  3174. * @param {string} [string=''] The string to escape.
  3175. * @returns {string} Returns the escaped string.
  3176. * @example
  3177. *
  3178. * _.escape('fred, barney, & pebbles');
  3179. * // => 'fred, barney, &amp; pebbles'
  3180. */
  3181. function escape(string) {
  3182. string = toString(string);
  3183. return (string && reHasUnescapedHtml.test(string))
  3184. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  3185. : string;
  3186. }
  3187. /*------------------------------------------------------------------------*/
  3188. /**
  3189. * This method returns the first argument it receives.
  3190. *
  3191. * @static
  3192. * @since 0.1.0
  3193. * @memberOf _
  3194. * @category Util
  3195. * @param {*} value Any value.
  3196. * @returns {*} Returns `value`.
  3197. * @example
  3198. *
  3199. * var object = { 'a': 1 };
  3200. *
  3201. * console.log(_.identity(object) === object);
  3202. * // => true
  3203. */
  3204. function identity(value) {
  3205. return value;
  3206. }
  3207. /**
  3208. * Creates a function that invokes `func` with the arguments of the created
  3209. * function. If `func` is a property name, the created function returns the
  3210. * property value for a given element. If `func` is an array or object, the
  3211. * created function returns `true` for elements that contain the equivalent
  3212. * source properties, otherwise it returns `false`.
  3213. *
  3214. * @static
  3215. * @since 4.0.0
  3216. * @memberOf _
  3217. * @category Util
  3218. * @param {*} [func=_.identity] The value to convert to a callback.
  3219. * @returns {Function} Returns the callback.
  3220. * @example
  3221. *
  3222. * var users = [
  3223. * { 'user': 'barney', 'age': 36, 'active': true },
  3224. * { 'user': 'fred', 'age': 40, 'active': false }
  3225. * ];
  3226. *
  3227. * // The `_.matches` iteratee shorthand.
  3228. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  3229. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  3230. *
  3231. * // The `_.matchesProperty` iteratee shorthand.
  3232. * _.filter(users, _.iteratee(['user', 'fred']));
  3233. * // => [{ 'user': 'fred', 'age': 40 }]
  3234. *
  3235. * // The `_.property` iteratee shorthand.
  3236. * _.map(users, _.iteratee('user'));
  3237. * // => ['barney', 'fred']
  3238. *
  3239. * // Create custom iteratee shorthands.
  3240. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  3241. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  3242. * return func.test(string);
  3243. * };
  3244. * });
  3245. *
  3246. * _.filter(['abc', 'def'], /ef/);
  3247. * // => ['def']
  3248. */
  3249. var iteratee = baseIteratee;
  3250. /**
  3251. * Creates a function that performs a partial deep comparison between a given
  3252. * object and `source`, returning `true` if the given object has equivalent
  3253. * property values, else `false`.
  3254. *
  3255. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  3256. * partially applied.
  3257. *
  3258. * Partial comparisons will match empty array and empty object `source`
  3259. * values against any array or object value, respectively. See `_.isEqual`
  3260. * for a list of supported value comparisons.
  3261. *
  3262. * @static
  3263. * @memberOf _
  3264. * @since 3.0.0
  3265. * @category Util
  3266. * @param {Object} source The object of property values to match.
  3267. * @returns {Function} Returns the new spec function.
  3268. * @example
  3269. *
  3270. * var objects = [
  3271. * { 'a': 1, 'b': 2, 'c': 3 },
  3272. * { 'a': 4, 'b': 5, 'c': 6 }
  3273. * ];
  3274. *
  3275. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  3276. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  3277. */
  3278. function matches(source) {
  3279. return baseMatches(assign({}, source));
  3280. }
  3281. /**
  3282. * Adds all own enumerable string keyed function properties of a source
  3283. * object to the destination object. If `object` is a function, then methods
  3284. * are added to its prototype as well.
  3285. *
  3286. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  3287. * avoid conflicts caused by modifying the original.
  3288. *
  3289. * @static
  3290. * @since 0.1.0
  3291. * @memberOf _
  3292. * @category Util
  3293. * @param {Function|Object} [object=lodash] The destination object.
  3294. * @param {Object} source The object of functions to add.
  3295. * @param {Object} [options={}] The options object.
  3296. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  3297. * @returns {Function|Object} Returns `object`.
  3298. * @example
  3299. *
  3300. * function vowels(string) {
  3301. * return _.filter(string, function(v) {
  3302. * return /[aeiou]/i.test(v);
  3303. * });
  3304. * }
  3305. *
  3306. * _.mixin({ 'vowels': vowels });
  3307. * _.vowels('fred');
  3308. * // => ['e']
  3309. *
  3310. * _('fred').vowels().value();
  3311. * // => ['e']
  3312. *
  3313. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  3314. * _('fred').vowels();
  3315. * // => ['e']
  3316. */
  3317. function mixin(object, source, options) {
  3318. var props = keys(source),
  3319. methodNames = baseFunctions(source, props);
  3320. if (options == null &&
  3321. !(isObject(source) && (methodNames.length || !props.length))) {
  3322. options = source;
  3323. source = object;
  3324. object = this;
  3325. methodNames = baseFunctions(source, keys(source));
  3326. }
  3327. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  3328. isFunc = isFunction(object);
  3329. baseEach(methodNames, function(methodName) {
  3330. var func = source[methodName];
  3331. object[methodName] = func;
  3332. if (isFunc) {
  3333. object.prototype[methodName] = function() {
  3334. var chainAll = this.__chain__;
  3335. if (chain || chainAll) {
  3336. var result = object(this.__wrapped__),
  3337. actions = result.__actions__ = copyArray(this.__actions__);
  3338. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  3339. result.__chain__ = chainAll;
  3340. return result;
  3341. }
  3342. return func.apply(object, arrayPush([this.value()], arguments));
  3343. };
  3344. }
  3345. });
  3346. return object;
  3347. }
  3348. /**
  3349. * Reverts the `_` variable to its previous value and returns a reference to
  3350. * the `lodash` function.
  3351. *
  3352. * @static
  3353. * @since 0.1.0
  3354. * @memberOf _
  3355. * @category Util
  3356. * @returns {Function} Returns the `lodash` function.
  3357. * @example
  3358. *
  3359. * var lodash = _.noConflict();
  3360. */
  3361. function noConflict() {
  3362. if (root._ === this) {
  3363. root._ = oldDash;
  3364. }
  3365. return this;
  3366. }
  3367. /**
  3368. * This method returns `undefined`.
  3369. *
  3370. * @static
  3371. * @memberOf _
  3372. * @since 2.3.0
  3373. * @category Util
  3374. * @example
  3375. *
  3376. * _.times(2, _.noop);
  3377. * // => [undefined, undefined]
  3378. */
  3379. function noop() {
  3380. // No operation performed.
  3381. }
  3382. /**
  3383. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  3384. *
  3385. * @static
  3386. * @since 0.1.0
  3387. * @memberOf _
  3388. * @category Util
  3389. * @param {string} [prefix=''] The value to prefix the ID with.
  3390. * @returns {string} Returns the unique ID.
  3391. * @example
  3392. *
  3393. * _.uniqueId('contact_');
  3394. * // => 'contact_104'
  3395. *
  3396. * _.uniqueId();
  3397. * // => '105'
  3398. */
  3399. function uniqueId(prefix) {
  3400. var id = ++idCounter;
  3401. return toString(prefix) + id;
  3402. }
  3403. /*------------------------------------------------------------------------*/
  3404. /**
  3405. * Computes the maximum value of `array`. If `array` is empty or falsey,
  3406. * `undefined` is returned.
  3407. *
  3408. * @static
  3409. * @since 0.1.0
  3410. * @memberOf _
  3411. * @category Math
  3412. * @param {Array} array The array to iterate over.
  3413. * @returns {*} Returns the maximum value.
  3414. * @example
  3415. *
  3416. * _.max([4, 2, 8, 6]);
  3417. * // => 8
  3418. *
  3419. * _.max([]);
  3420. * // => undefined
  3421. */
  3422. function max(array) {
  3423. return (array && array.length)
  3424. ? baseExtremum(array, identity, baseGt)
  3425. : undefined;
  3426. }
  3427. /**
  3428. * Computes the minimum value of `array`. If `array` is empty or falsey,
  3429. * `undefined` is returned.
  3430. *
  3431. * @static
  3432. * @since 0.1.0
  3433. * @memberOf _
  3434. * @category Math
  3435. * @param {Array} array The array to iterate over.
  3436. * @returns {*} Returns the minimum value.
  3437. * @example
  3438. *
  3439. * _.min([4, 2, 8, 6]);
  3440. * // => 2
  3441. *
  3442. * _.min([]);
  3443. * // => undefined
  3444. */
  3445. function min(array) {
  3446. return (array && array.length)
  3447. ? baseExtremum(array, identity, baseLt)
  3448. : undefined;
  3449. }
  3450. /*------------------------------------------------------------------------*/
  3451. // Add methods that return wrapped values in chain sequences.
  3452. lodash.assignIn = assignIn;
  3453. lodash.before = before;
  3454. lodash.bind = bind;
  3455. lodash.chain = chain;
  3456. lodash.compact = compact;
  3457. lodash.concat = concat;
  3458. lodash.create = create;
  3459. lodash.defaults = defaults;
  3460. lodash.defer = defer;
  3461. lodash.delay = delay;
  3462. lodash.filter = filter;
  3463. lodash.flatten = flatten;
  3464. lodash.flattenDeep = flattenDeep;
  3465. lodash.iteratee = iteratee;
  3466. lodash.keys = keys;
  3467. lodash.map = map;
  3468. lodash.matches = matches;
  3469. lodash.mixin = mixin;
  3470. lodash.negate = negate;
  3471. lodash.once = once;
  3472. lodash.pick = pick;
  3473. lodash.slice = slice;
  3474. lodash.sortBy = sortBy;
  3475. lodash.tap = tap;
  3476. lodash.thru = thru;
  3477. lodash.toArray = toArray;
  3478. lodash.values = values;
  3479. // Add aliases.
  3480. lodash.extend = assignIn;
  3481. // Add methods to `lodash.prototype`.
  3482. mixin(lodash, lodash);
  3483. /*------------------------------------------------------------------------*/
  3484. // Add methods that return unwrapped values in chain sequences.
  3485. lodash.clone = clone;
  3486. lodash.escape = escape;
  3487. lodash.every = every;
  3488. lodash.find = find;
  3489. lodash.forEach = forEach;
  3490. lodash.has = has;
  3491. lodash.head = head;
  3492. lodash.identity = identity;
  3493. lodash.indexOf = indexOf;
  3494. lodash.isArguments = isArguments;
  3495. lodash.isArray = isArray;
  3496. lodash.isBoolean = isBoolean;
  3497. lodash.isDate = isDate;
  3498. lodash.isEmpty = isEmpty;
  3499. lodash.isEqual = isEqual;
  3500. lodash.isFinite = isFinite;
  3501. lodash.isFunction = isFunction;
  3502. lodash.isNaN = isNaN;
  3503. lodash.isNull = isNull;
  3504. lodash.isNumber = isNumber;
  3505. lodash.isObject = isObject;
  3506. lodash.isRegExp = isRegExp;
  3507. lodash.isString = isString;
  3508. lodash.isUndefined = isUndefined;
  3509. lodash.last = last;
  3510. lodash.max = max;
  3511. lodash.min = min;
  3512. lodash.noConflict = noConflict;
  3513. lodash.noop = noop;
  3514. lodash.reduce = reduce;
  3515. lodash.result = result;
  3516. lodash.size = size;
  3517. lodash.some = some;
  3518. lodash.uniqueId = uniqueId;
  3519. // Add aliases.
  3520. lodash.each = forEach;
  3521. lodash.first = head;
  3522. mixin(lodash, (function() {
  3523. var source = {};
  3524. baseForOwn(lodash, function(func, methodName) {
  3525. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  3526. source[methodName] = func;
  3527. }
  3528. });
  3529. return source;
  3530. }()), { 'chain': false });
  3531. /*------------------------------------------------------------------------*/
  3532. /**
  3533. * The semantic version number.
  3534. *
  3535. * @static
  3536. * @memberOf _
  3537. * @type {string}
  3538. */
  3539. lodash.VERSION = VERSION;
  3540. // Add `Array` methods to `lodash.prototype`.
  3541. baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  3542. var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
  3543. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  3544. retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
  3545. lodash.prototype[methodName] = function() {
  3546. var args = arguments;
  3547. if (retUnwrapped && !this.__chain__) {
  3548. var value = this.value();
  3549. return func.apply(isArray(value) ? value : [], args);
  3550. }
  3551. return this[chainName](function(value) {
  3552. return func.apply(isArray(value) ? value : [], args);
  3553. });
  3554. };
  3555. });
  3556. // Add chain sequence methods to the `lodash` wrapper.
  3557. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  3558. /*--------------------------------------------------------------------------*/
  3559. // Some AMD build optimizers, like r.js, check for condition patterns like:
  3560. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  3561. // Expose Lodash on the global object to prevent errors when Lodash is
  3562. // loaded by a script tag in the presence of an AMD loader.
  3563. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  3564. // Use `_.noConflict` to remove Lodash from the global object.
  3565. root._ = lodash;
  3566. // Define as an anonymous module so, through path mapping, it can be
  3567. // referenced as the "underscore" module.
  3568. define(function() {
  3569. return lodash;
  3570. });
  3571. }
  3572. // Check for `exports` after `define` in case a build optimizer adds it.
  3573. else if (freeModule) {
  3574. // Export for Node.js.
  3575. (freeModule.exports = lodash)._ = lodash;
  3576. // Export for CommonJS support.
  3577. freeExports._ = lodash;
  3578. }
  3579. else {
  3580. // Export to the global object.
  3581. root._ = lodash;
  3582. }
  3583. }.call(this));