lodash.core.js 112 KB

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