Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

core.js 112KB

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