core.js 112 KB

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