core.js 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878
  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.21';
  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. // Check that cyclic values are equal.
  1084. var arrStacked = stack.get(array);
  1085. var othStacked = stack.get(other);
  1086. if (arrStacked && othStacked) {
  1087. return arrStacked == other && othStacked == array;
  1088. }
  1089. var index = -1,
  1090. result = true,
  1091. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? [] : undefined;
  1092. // Ignore non-index properties.
  1093. while (++index < arrLength) {
  1094. var arrValue = array[index],
  1095. othValue = other[index];
  1096. var compared;
  1097. if (compared !== undefined) {
  1098. if (compared) {
  1099. continue;
  1100. }
  1101. result = false;
  1102. break;
  1103. }
  1104. // Recursively compare arrays (susceptible to call stack limits).
  1105. if (seen) {
  1106. if (!baseSome(other, function(othValue, othIndex) {
  1107. if (!indexOf(seen, othIndex) &&
  1108. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  1109. return seen.push(othIndex);
  1110. }
  1111. })) {
  1112. result = false;
  1113. break;
  1114. }
  1115. } else if (!(
  1116. arrValue === othValue ||
  1117. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  1118. )) {
  1119. result = false;
  1120. break;
  1121. }
  1122. }
  1123. return result;
  1124. }
  1125. /**
  1126. * A specialized version of `baseIsEqualDeep` for comparing objects of
  1127. * the same `toStringTag`.
  1128. *
  1129. * **Note:** This function only supports comparing values with tags of
  1130. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  1131. *
  1132. * @private
  1133. * @param {Object} object The object to compare.
  1134. * @param {Object} other The other object to compare.
  1135. * @param {string} tag The `toStringTag` of the objects to compare.
  1136. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  1137. * @param {Function} customizer The function to customize comparisons.
  1138. * @param {Function} equalFunc The function to determine equivalents of values.
  1139. * @param {Object} stack Tracks traversed `object` and `other` objects.
  1140. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  1141. */
  1142. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  1143. switch (tag) {
  1144. case boolTag:
  1145. case dateTag:
  1146. case numberTag:
  1147. // Coerce booleans to `1` or `0` and dates to milliseconds.
  1148. // Invalid dates are coerced to `NaN`.
  1149. return eq(+object, +other);
  1150. case errorTag:
  1151. return object.name == other.name && object.message == other.message;
  1152. case regexpTag:
  1153. case stringTag:
  1154. // Coerce regexes to strings and treat strings, primitives and objects,
  1155. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  1156. // for more details.
  1157. return object == (other + '');
  1158. }
  1159. return false;
  1160. }
  1161. /**
  1162. * A specialized version of `baseIsEqualDeep` for objects with support for
  1163. * partial deep comparisons.
  1164. *
  1165. * @private
  1166. * @param {Object} object The object to compare.
  1167. * @param {Object} other The other object to compare.
  1168. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  1169. * @param {Function} customizer The function to customize comparisons.
  1170. * @param {Function} equalFunc The function to determine equivalents of values.
  1171. * @param {Object} stack Tracks traversed `object` and `other` objects.
  1172. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  1173. */
  1174. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  1175. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  1176. objProps = keys(object),
  1177. objLength = objProps.length,
  1178. othProps = keys(other),
  1179. othLength = othProps.length;
  1180. if (objLength != othLength && !isPartial) {
  1181. return false;
  1182. }
  1183. var index = objLength;
  1184. while (index--) {
  1185. var key = objProps[index];
  1186. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  1187. return false;
  1188. }
  1189. }
  1190. // Check that cyclic values are equal.
  1191. var objStacked = stack.get(object);
  1192. var othStacked = stack.get(other);
  1193. if (objStacked && othStacked) {
  1194. return objStacked == other && othStacked == object;
  1195. }
  1196. var result = true;
  1197. var skipCtor = isPartial;
  1198. while (++index < objLength) {
  1199. key = objProps[index];
  1200. var objValue = object[key],
  1201. othValue = other[key];
  1202. var compared;
  1203. // Recursively compare objects (susceptible to call stack limits).
  1204. if (!(compared === undefined
  1205. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  1206. : compared
  1207. )) {
  1208. result = false;
  1209. break;
  1210. }
  1211. skipCtor || (skipCtor = key == 'constructor');
  1212. }
  1213. if (result && !skipCtor) {
  1214. var objCtor = object.constructor,
  1215. othCtor = other.constructor;
  1216. // Non `Object` object instances with different constructors are not equal.
  1217. if (objCtor != othCtor &&
  1218. ('constructor' in object && 'constructor' in other) &&
  1219. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  1220. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  1221. result = false;
  1222. }
  1223. }
  1224. return result;
  1225. }
  1226. /**
  1227. * A specialized version of `baseRest` which flattens the rest array.
  1228. *
  1229. * @private
  1230. * @param {Function} func The function to apply a rest parameter to.
  1231. * @returns {Function} Returns the new function.
  1232. */
  1233. function flatRest(func) {
  1234. return setToString(overRest(func, undefined, flatten), func + '');
  1235. }
  1236. /**
  1237. * Checks if `value` is a flattenable `arguments` object or array.
  1238. *
  1239. * @private
  1240. * @param {*} value The value to check.
  1241. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  1242. */
  1243. function isFlattenable(value) {
  1244. return isArray(value) || isArguments(value);
  1245. }
  1246. /**
  1247. * Checks if `value` is a valid array-like index.
  1248. *
  1249. * @private
  1250. * @param {*} value The value to check.
  1251. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  1252. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  1253. */
  1254. function isIndex(value, length) {
  1255. var type = typeof value;
  1256. length = length == null ? MAX_SAFE_INTEGER : length;
  1257. return !!length &&
  1258. (type == 'number' ||
  1259. (type != 'symbol' && reIsUint.test(value))) &&
  1260. (value > -1 && value % 1 == 0 && value < length);
  1261. }
  1262. /**
  1263. * Checks if the given arguments are from an iteratee call.
  1264. *
  1265. * @private
  1266. * @param {*} value The potential iteratee value argument.
  1267. * @param {*} index The potential iteratee index or key argument.
  1268. * @param {*} object The potential iteratee object argument.
  1269. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  1270. * else `false`.
  1271. */
  1272. function isIterateeCall(value, index, object) {
  1273. if (!isObject(object)) {
  1274. return false;
  1275. }
  1276. var type = typeof index;
  1277. if (type == 'number'
  1278. ? (isArrayLike(object) && isIndex(index, object.length))
  1279. : (type == 'string' && index in object)
  1280. ) {
  1281. return eq(object[index], value);
  1282. }
  1283. return false;
  1284. }
  1285. /**
  1286. * This function is like
  1287. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  1288. * except that it includes inherited enumerable properties.
  1289. *
  1290. * @private
  1291. * @param {Object} object The object to query.
  1292. * @returns {Array} Returns the array of property names.
  1293. */
  1294. function nativeKeysIn(object) {
  1295. var result = [];
  1296. if (object != null) {
  1297. for (var key in Object(object)) {
  1298. result.push(key);
  1299. }
  1300. }
  1301. return result;
  1302. }
  1303. /**
  1304. * Converts `value` to a string using `Object.prototype.toString`.
  1305. *
  1306. * @private
  1307. * @param {*} value The value to convert.
  1308. * @returns {string} Returns the converted string.
  1309. */
  1310. function objectToString(value) {
  1311. return nativeObjectToString.call(value);
  1312. }
  1313. /**
  1314. * A specialized version of `baseRest` which transforms the rest array.
  1315. *
  1316. * @private
  1317. * @param {Function} func The function to apply a rest parameter to.
  1318. * @param {number} [start=func.length-1] The start position of the rest parameter.
  1319. * @param {Function} transform The rest array transform.
  1320. * @returns {Function} Returns the new function.
  1321. */
  1322. function overRest(func, start, transform) {
  1323. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  1324. return function() {
  1325. var args = arguments,
  1326. index = -1,
  1327. length = nativeMax(args.length - start, 0),
  1328. array = Array(length);
  1329. while (++index < length) {
  1330. array[index] = args[start + index];
  1331. }
  1332. index = -1;
  1333. var otherArgs = Array(start + 1);
  1334. while (++index < start) {
  1335. otherArgs[index] = args[index];
  1336. }
  1337. otherArgs[start] = transform(array);
  1338. return func.apply(this, otherArgs);
  1339. };
  1340. }
  1341. /**
  1342. * Sets the `toString` method of `func` to return `string`.
  1343. *
  1344. * @private
  1345. * @param {Function} func The function to modify.
  1346. * @param {Function} string The `toString` result.
  1347. * @returns {Function} Returns `func`.
  1348. */
  1349. var setToString = identity;
  1350. /*------------------------------------------------------------------------*/
  1351. /**
  1352. * Creates an array with all falsey values removed. The values `false`, `null`,
  1353. * `0`, `""`, `undefined`, and `NaN` are falsey.
  1354. *
  1355. * @static
  1356. * @memberOf _
  1357. * @since 0.1.0
  1358. * @category Array
  1359. * @param {Array} array The array to compact.
  1360. * @returns {Array} Returns the new array of filtered values.
  1361. * @example
  1362. *
  1363. * _.compact([0, 1, false, 2, '', 3]);
  1364. * // => [1, 2, 3]
  1365. */
  1366. function compact(array) {
  1367. return baseFilter(array, Boolean);
  1368. }
  1369. /**
  1370. * Creates a new array concatenating `array` with any additional arrays
  1371. * and/or values.
  1372. *
  1373. * @static
  1374. * @memberOf _
  1375. * @since 4.0.0
  1376. * @category Array
  1377. * @param {Array} array The array to concatenate.
  1378. * @param {...*} [values] The values to concatenate.
  1379. * @returns {Array} Returns the new concatenated array.
  1380. * @example
  1381. *
  1382. * var array = [1];
  1383. * var other = _.concat(array, 2, [3], [[4]]);
  1384. *
  1385. * console.log(other);
  1386. * // => [1, 2, 3, [4]]
  1387. *
  1388. * console.log(array);
  1389. * // => [1]
  1390. */
  1391. function concat() {
  1392. var length = arguments.length;
  1393. if (!length) {
  1394. return [];
  1395. }
  1396. var args = Array(length - 1),
  1397. array = arguments[0],
  1398. index = length;
  1399. while (index--) {
  1400. args[index - 1] = arguments[index];
  1401. }
  1402. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  1403. }
  1404. /**
  1405. * This method is like `_.find` except that it returns the index of the first
  1406. * element `predicate` returns truthy for instead of the element itself.
  1407. *
  1408. * @static
  1409. * @memberOf _
  1410. * @since 1.1.0
  1411. * @category Array
  1412. * @param {Array} array The array to inspect.
  1413. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  1414. * @param {number} [fromIndex=0] The index to search from.
  1415. * @returns {number} Returns the index of the found element, else `-1`.
  1416. * @example
  1417. *
  1418. * var users = [
  1419. * { 'user': 'barney', 'active': false },
  1420. * { 'user': 'fred', 'active': false },
  1421. * { 'user': 'pebbles', 'active': true }
  1422. * ];
  1423. *
  1424. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  1425. * // => 0
  1426. *
  1427. * // The `_.matches` iteratee shorthand.
  1428. * _.findIndex(users, { 'user': 'fred', 'active': false });
  1429. * // => 1
  1430. *
  1431. * // The `_.matchesProperty` iteratee shorthand.
  1432. * _.findIndex(users, ['active', false]);
  1433. * // => 0
  1434. *
  1435. * // The `_.property` iteratee shorthand.
  1436. * _.findIndex(users, 'active');
  1437. * // => 2
  1438. */
  1439. function findIndex(array, predicate, fromIndex) {
  1440. var length = array == null ? 0 : array.length;
  1441. if (!length) {
  1442. return -1;
  1443. }
  1444. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  1445. if (index < 0) {
  1446. index = nativeMax(length + index, 0);
  1447. }
  1448. return baseFindIndex(array, baseIteratee(predicate, 3), index);
  1449. }
  1450. /**
  1451. * Flattens `array` a single level deep.
  1452. *
  1453. * @static
  1454. * @memberOf _
  1455. * @since 0.1.0
  1456. * @category Array
  1457. * @param {Array} array The array to flatten.
  1458. * @returns {Array} Returns the new flattened array.
  1459. * @example
  1460. *
  1461. * _.flatten([1, [2, [3, [4]], 5]]);
  1462. * // => [1, 2, [3, [4]], 5]
  1463. */
  1464. function flatten(array) {
  1465. var length = array == null ? 0 : array.length;
  1466. return length ? baseFlatten(array, 1) : [];
  1467. }
  1468. /**
  1469. * Recursively flattens `array`.
  1470. *
  1471. * @static
  1472. * @memberOf _
  1473. * @since 3.0.0
  1474. * @category Array
  1475. * @param {Array} array The array to flatten.
  1476. * @returns {Array} Returns the new flattened array.
  1477. * @example
  1478. *
  1479. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  1480. * // => [1, 2, 3, 4, 5]
  1481. */
  1482. function flattenDeep(array) {
  1483. var length = array == null ? 0 : array.length;
  1484. return length ? baseFlatten(array, INFINITY) : [];
  1485. }
  1486. /**
  1487. * Gets the first element of `array`.
  1488. *
  1489. * @static
  1490. * @memberOf _
  1491. * @since 0.1.0
  1492. * @alias first
  1493. * @category Array
  1494. * @param {Array} array The array to query.
  1495. * @returns {*} Returns the first element of `array`.
  1496. * @example
  1497. *
  1498. * _.head([1, 2, 3]);
  1499. * // => 1
  1500. *
  1501. * _.head([]);
  1502. * // => undefined
  1503. */
  1504. function head(array) {
  1505. return (array && array.length) ? array[0] : undefined;
  1506. }
  1507. /**
  1508. * Gets the index at which the first occurrence of `value` is found in `array`
  1509. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  1510. * for equality comparisons. If `fromIndex` is negative, it's used as the
  1511. * offset from the end of `array`.
  1512. *
  1513. * @static
  1514. * @memberOf _
  1515. * @since 0.1.0
  1516. * @category Array
  1517. * @param {Array} array The array to inspect.
  1518. * @param {*} value The value to search for.
  1519. * @param {number} [fromIndex=0] The index to search from.
  1520. * @returns {number} Returns the index of the matched value, else `-1`.
  1521. * @example
  1522. *
  1523. * _.indexOf([1, 2, 1, 2], 2);
  1524. * // => 1
  1525. *
  1526. * // Search from the `fromIndex`.
  1527. * _.indexOf([1, 2, 1, 2], 2, 2);
  1528. * // => 3
  1529. */
  1530. function indexOf(array, value, fromIndex) {
  1531. var length = array == null ? 0 : array.length;
  1532. if (typeof fromIndex == 'number') {
  1533. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
  1534. } else {
  1535. fromIndex = 0;
  1536. }
  1537. var index = (fromIndex || 0) - 1,
  1538. isReflexive = value === value;
  1539. while (++index < length) {
  1540. var other = array[index];
  1541. if ((isReflexive ? other === value : other !== other)) {
  1542. return index;
  1543. }
  1544. }
  1545. return -1;
  1546. }
  1547. /**
  1548. * Gets the last element of `array`.
  1549. *
  1550. * @static
  1551. * @memberOf _
  1552. * @since 0.1.0
  1553. * @category Array
  1554. * @param {Array} array The array to query.
  1555. * @returns {*} Returns the last element of `array`.
  1556. * @example
  1557. *
  1558. * _.last([1, 2, 3]);
  1559. * // => 3
  1560. */
  1561. function last(array) {
  1562. var length = array == null ? 0 : array.length;
  1563. return length ? array[length - 1] : undefined;
  1564. }
  1565. /**
  1566. * Creates a slice of `array` from `start` up to, but not including, `end`.
  1567. *
  1568. * **Note:** This method is used instead of
  1569. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  1570. * returned.
  1571. *
  1572. * @static
  1573. * @memberOf _
  1574. * @since 3.0.0
  1575. * @category Array
  1576. * @param {Array} array The array to slice.
  1577. * @param {number} [start=0] The start position.
  1578. * @param {number} [end=array.length] The end position.
  1579. * @returns {Array} Returns the slice of `array`.
  1580. */
  1581. function slice(array, start, end) {
  1582. var length = array == null ? 0 : array.length;
  1583. start = start == null ? 0 : +start;
  1584. end = end === undefined ? length : +end;
  1585. return length ? baseSlice(array, start, end) : [];
  1586. }
  1587. /*------------------------------------------------------------------------*/
  1588. /**
  1589. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  1590. * chain sequences enabled. The result of such sequences must be unwrapped
  1591. * with `_#value`.
  1592. *
  1593. * @static
  1594. * @memberOf _
  1595. * @since 1.3.0
  1596. * @category Seq
  1597. * @param {*} value The value to wrap.
  1598. * @returns {Object} Returns the new `lodash` wrapper instance.
  1599. * @example
  1600. *
  1601. * var users = [
  1602. * { 'user': 'barney', 'age': 36 },
  1603. * { 'user': 'fred', 'age': 40 },
  1604. * { 'user': 'pebbles', 'age': 1 }
  1605. * ];
  1606. *
  1607. * var youngest = _
  1608. * .chain(users)
  1609. * .sortBy('age')
  1610. * .map(function(o) {
  1611. * return o.user + ' is ' + o.age;
  1612. * })
  1613. * .head()
  1614. * .value();
  1615. * // => 'pebbles is 1'
  1616. */
  1617. function chain(value) {
  1618. var result = lodash(value);
  1619. result.__chain__ = true;
  1620. return result;
  1621. }
  1622. /**
  1623. * This method invokes `interceptor` and returns `value`. The interceptor
  1624. * is invoked with one argument; (value). The purpose of this method is to
  1625. * "tap into" a method chain sequence in order to modify intermediate results.
  1626. *
  1627. * @static
  1628. * @memberOf _
  1629. * @since 0.1.0
  1630. * @category Seq
  1631. * @param {*} value The value to provide to `interceptor`.
  1632. * @param {Function} interceptor The function to invoke.
  1633. * @returns {*} Returns `value`.
  1634. * @example
  1635. *
  1636. * _([1, 2, 3])
  1637. * .tap(function(array) {
  1638. * // Mutate input array.
  1639. * array.pop();
  1640. * })
  1641. * .reverse()
  1642. * .value();
  1643. * // => [2, 1]
  1644. */
  1645. function tap(value, interceptor) {
  1646. interceptor(value);
  1647. return value;
  1648. }
  1649. /**
  1650. * This method is like `_.tap` except that it returns the result of `interceptor`.
  1651. * The purpose of this method is to "pass thru" values replacing intermediate
  1652. * results in a method chain sequence.
  1653. *
  1654. * @static
  1655. * @memberOf _
  1656. * @since 3.0.0
  1657. * @category Seq
  1658. * @param {*} value The value to provide to `interceptor`.
  1659. * @param {Function} interceptor The function to invoke.
  1660. * @returns {*} Returns the result of `interceptor`.
  1661. * @example
  1662. *
  1663. * _(' abc ')
  1664. * .chain()
  1665. * .trim()
  1666. * .thru(function(value) {
  1667. * return [value];
  1668. * })
  1669. * .value();
  1670. * // => ['abc']
  1671. */
  1672. function thru(value, interceptor) {
  1673. return interceptor(value);
  1674. }
  1675. /**
  1676. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  1677. *
  1678. * @name chain
  1679. * @memberOf _
  1680. * @since 0.1.0
  1681. * @category Seq
  1682. * @returns {Object} Returns the new `lodash` wrapper instance.
  1683. * @example
  1684. *
  1685. * var users = [
  1686. * { 'user': 'barney', 'age': 36 },
  1687. * { 'user': 'fred', 'age': 40 }
  1688. * ];
  1689. *
  1690. * // A sequence without explicit chaining.
  1691. * _(users).head();
  1692. * // => { 'user': 'barney', 'age': 36 }
  1693. *
  1694. * // A sequence with explicit chaining.
  1695. * _(users)
  1696. * .chain()
  1697. * .head()
  1698. * .pick('user')
  1699. * .value();
  1700. * // => { 'user': 'barney' }
  1701. */
  1702. function wrapperChain() {
  1703. return chain(this);
  1704. }
  1705. /**
  1706. * Executes the chain sequence to resolve the unwrapped value.
  1707. *
  1708. * @name value
  1709. * @memberOf _
  1710. * @since 0.1.0
  1711. * @alias toJSON, valueOf
  1712. * @category Seq
  1713. * @returns {*} Returns the resolved unwrapped value.
  1714. * @example
  1715. *
  1716. * _([1, 2, 3]).value();
  1717. * // => [1, 2, 3]
  1718. */
  1719. function wrapperValue() {
  1720. return baseWrapperValue(this.__wrapped__, this.__actions__);
  1721. }
  1722. /*------------------------------------------------------------------------*/
  1723. /**
  1724. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  1725. * Iteration is stopped once `predicate` returns falsey. The predicate is
  1726. * invoked with three arguments: (value, index|key, collection).
  1727. *
  1728. * **Note:** This method returns `true` for
  1729. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  1730. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  1731. * elements of empty collections.
  1732. *
  1733. * @static
  1734. * @memberOf _
  1735. * @since 0.1.0
  1736. * @category Collection
  1737. * @param {Array|Object} collection The collection to iterate over.
  1738. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  1739. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  1740. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1741. * else `false`.
  1742. * @example
  1743. *
  1744. * _.every([true, 1, null, 'yes'], Boolean);
  1745. * // => false
  1746. *
  1747. * var users = [
  1748. * { 'user': 'barney', 'age': 36, 'active': false },
  1749. * { 'user': 'fred', 'age': 40, 'active': false }
  1750. * ];
  1751. *
  1752. * // The `_.matches` iteratee shorthand.
  1753. * _.every(users, { 'user': 'barney', 'active': false });
  1754. * // => false
  1755. *
  1756. * // The `_.matchesProperty` iteratee shorthand.
  1757. * _.every(users, ['active', false]);
  1758. * // => true
  1759. *
  1760. * // The `_.property` iteratee shorthand.
  1761. * _.every(users, 'active');
  1762. * // => false
  1763. */
  1764. function every(collection, predicate, guard) {
  1765. predicate = guard ? undefined : predicate;
  1766. return baseEvery(collection, baseIteratee(predicate));
  1767. }
  1768. /**
  1769. * Iterates over elements of `collection`, returning an array of all elements
  1770. * `predicate` returns truthy for. The predicate is invoked with three
  1771. * arguments: (value, index|key, collection).
  1772. *
  1773. * **Note:** Unlike `_.remove`, this method returns a new array.
  1774. *
  1775. * @static
  1776. * @memberOf _
  1777. * @since 0.1.0
  1778. * @category Collection
  1779. * @param {Array|Object} collection The collection to iterate over.
  1780. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  1781. * @returns {Array} Returns the new filtered array.
  1782. * @see _.reject
  1783. * @example
  1784. *
  1785. * var users = [
  1786. * { 'user': 'barney', 'age': 36, 'active': true },
  1787. * { 'user': 'fred', 'age': 40, 'active': false }
  1788. * ];
  1789. *
  1790. * _.filter(users, function(o) { return !o.active; });
  1791. * // => objects for ['fred']
  1792. *
  1793. * // The `_.matches` iteratee shorthand.
  1794. * _.filter(users, { 'age': 36, 'active': true });
  1795. * // => objects for ['barney']
  1796. *
  1797. * // The `_.matchesProperty` iteratee shorthand.
  1798. * _.filter(users, ['active', false]);
  1799. * // => objects for ['fred']
  1800. *
  1801. * // The `_.property` iteratee shorthand.
  1802. * _.filter(users, 'active');
  1803. * // => objects for ['barney']
  1804. *
  1805. * // Combining several predicates using `_.overEvery` or `_.overSome`.
  1806. * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
  1807. * // => objects for ['fred', 'barney']
  1808. */
  1809. function filter(collection, predicate) {
  1810. return baseFilter(collection, baseIteratee(predicate));
  1811. }
  1812. /**
  1813. * Iterates over elements of `collection`, returning the first element
  1814. * `predicate` returns truthy for. The predicate is invoked with three
  1815. * arguments: (value, index|key, collection).
  1816. *
  1817. * @static
  1818. * @memberOf _
  1819. * @since 0.1.0
  1820. * @category Collection
  1821. * @param {Array|Object} collection The collection to inspect.
  1822. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  1823. * @param {number} [fromIndex=0] The index to search from.
  1824. * @returns {*} Returns the matched element, else `undefined`.
  1825. * @example
  1826. *
  1827. * var users = [
  1828. * { 'user': 'barney', 'age': 36, 'active': true },
  1829. * { 'user': 'fred', 'age': 40, 'active': false },
  1830. * { 'user': 'pebbles', 'age': 1, 'active': true }
  1831. * ];
  1832. *
  1833. * _.find(users, function(o) { return o.age < 40; });
  1834. * // => object for 'barney'
  1835. *
  1836. * // The `_.matches` iteratee shorthand.
  1837. * _.find(users, { 'age': 1, 'active': true });
  1838. * // => object for 'pebbles'
  1839. *
  1840. * // The `_.matchesProperty` iteratee shorthand.
  1841. * _.find(users, ['active', false]);
  1842. * // => object for 'fred'
  1843. *
  1844. * // The `_.property` iteratee shorthand.
  1845. * _.find(users, 'active');
  1846. * // => object for 'barney'
  1847. */
  1848. var find = createFind(findIndex);
  1849. /**
  1850. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  1851. * The iteratee is invoked with three arguments: (value, index|key, collection).
  1852. * Iteratee functions may exit iteration early by explicitly returning `false`.
  1853. *
  1854. * **Note:** As with other "Collections" methods, objects with a "length"
  1855. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  1856. * or `_.forOwn` for object iteration.
  1857. *
  1858. * @static
  1859. * @memberOf _
  1860. * @since 0.1.0
  1861. * @alias each
  1862. * @category Collection
  1863. * @param {Array|Object} collection The collection to iterate over.
  1864. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  1865. * @returns {Array|Object} Returns `collection`.
  1866. * @see _.forEachRight
  1867. * @example
  1868. *
  1869. * _.forEach([1, 2], function(value) {
  1870. * console.log(value);
  1871. * });
  1872. * // => Logs `1` then `2`.
  1873. *
  1874. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  1875. * console.log(key);
  1876. * });
  1877. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  1878. */
  1879. function forEach(collection, iteratee) {
  1880. return baseEach(collection, baseIteratee(iteratee));
  1881. }
  1882. /**
  1883. * Creates an array of values by running each element in `collection` thru
  1884. * `iteratee`. The iteratee is invoked with three arguments:
  1885. * (value, index|key, collection).
  1886. *
  1887. * Many lodash methods are guarded to work as iteratees for methods like
  1888. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  1889. *
  1890. * The guarded methods are:
  1891. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  1892. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  1893. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  1894. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  1895. *
  1896. * @static
  1897. * @memberOf _
  1898. * @since 0.1.0
  1899. * @category Collection
  1900. * @param {Array|Object} collection The collection to iterate over.
  1901. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  1902. * @returns {Array} Returns the new mapped array.
  1903. * @example
  1904. *
  1905. * function square(n) {
  1906. * return n * n;
  1907. * }
  1908. *
  1909. * _.map([4, 8], square);
  1910. * // => [16, 64]
  1911. *
  1912. * _.map({ 'a': 4, 'b': 8 }, square);
  1913. * // => [16, 64] (iteration order is not guaranteed)
  1914. *
  1915. * var users = [
  1916. * { 'user': 'barney' },
  1917. * { 'user': 'fred' }
  1918. * ];
  1919. *
  1920. * // The `_.property` iteratee shorthand.
  1921. * _.map(users, 'user');
  1922. * // => ['barney', 'fred']
  1923. */
  1924. function map(collection, iteratee) {
  1925. return baseMap(collection, baseIteratee(iteratee));
  1926. }
  1927. /**
  1928. * Reduces `collection` to a value which is the accumulated result of running
  1929. * each element in `collection` thru `iteratee`, where each successive
  1930. * invocation is supplied the return value of the previous. If `accumulator`
  1931. * is not given, the first element of `collection` is used as the initial
  1932. * value. The iteratee is invoked with four arguments:
  1933. * (accumulator, value, index|key, collection).
  1934. *
  1935. * Many lodash methods are guarded to work as iteratees for methods like
  1936. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  1937. *
  1938. * The guarded methods are:
  1939. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  1940. * and `sortBy`
  1941. *
  1942. * @static
  1943. * @memberOf _
  1944. * @since 0.1.0
  1945. * @category Collection
  1946. * @param {Array|Object} collection The collection to iterate over.
  1947. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  1948. * @param {*} [accumulator] The initial value.
  1949. * @returns {*} Returns the accumulated value.
  1950. * @see _.reduceRight
  1951. * @example
  1952. *
  1953. * _.reduce([1, 2], function(sum, n) {
  1954. * return sum + n;
  1955. * }, 0);
  1956. * // => 3
  1957. *
  1958. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  1959. * (result[value] || (result[value] = [])).push(key);
  1960. * return result;
  1961. * }, {});
  1962. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  1963. */
  1964. function reduce(collection, iteratee, accumulator) {
  1965. return baseReduce(collection, baseIteratee(iteratee), accumulator, arguments.length < 3, baseEach);
  1966. }
  1967. /**
  1968. * Gets the size of `collection` by returning its length for array-like
  1969. * values or the number of own enumerable string keyed properties for objects.
  1970. *
  1971. * @static
  1972. * @memberOf _
  1973. * @since 0.1.0
  1974. * @category Collection
  1975. * @param {Array|Object|string} collection The collection to inspect.
  1976. * @returns {number} Returns the collection size.
  1977. * @example
  1978. *
  1979. * _.size([1, 2, 3]);
  1980. * // => 3
  1981. *
  1982. * _.size({ 'a': 1, 'b': 2 });
  1983. * // => 2
  1984. *
  1985. * _.size('pebbles');
  1986. * // => 7
  1987. */
  1988. function size(collection) {
  1989. if (collection == null) {
  1990. return 0;
  1991. }
  1992. collection = isArrayLike(collection) ? collection : nativeKeys(collection);
  1993. return collection.length;
  1994. }
  1995. /**
  1996. * Checks if `predicate` returns truthy for **any** element of `collection`.
  1997. * Iteration is stopped once `predicate` returns truthy. The predicate is
  1998. * invoked with three arguments: (value, index|key, collection).
  1999. *
  2000. * @static
  2001. * @memberOf _
  2002. * @since 0.1.0
  2003. * @category Collection
  2004. * @param {Array|Object} collection The collection to iterate over.
  2005. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  2006. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  2007. * @returns {boolean} Returns `true` if any element passes the predicate check,
  2008. * else `false`.
  2009. * @example
  2010. *
  2011. * _.some([null, 0, 'yes', false], Boolean);
  2012. * // => true
  2013. *
  2014. * var users = [
  2015. * { 'user': 'barney', 'active': true },
  2016. * { 'user': 'fred', 'active': false }
  2017. * ];
  2018. *
  2019. * // The `_.matches` iteratee shorthand.
  2020. * _.some(users, { 'user': 'barney', 'active': false });
  2021. * // => false
  2022. *
  2023. * // The `_.matchesProperty` iteratee shorthand.
  2024. * _.some(users, ['active', false]);
  2025. * // => true
  2026. *
  2027. * // The `_.property` iteratee shorthand.
  2028. * _.some(users, 'active');
  2029. * // => true
  2030. */
  2031. function some(collection, predicate, guard) {
  2032. predicate = guard ? undefined : predicate;
  2033. return baseSome(collection, baseIteratee(predicate));
  2034. }
  2035. /**
  2036. * Creates an array of elements, sorted in ascending order by the results of
  2037. * running each element in a collection thru each iteratee. This method
  2038. * performs a stable sort, that is, it preserves the original sort order of
  2039. * equal elements. The iteratees are invoked with one argument: (value).
  2040. *
  2041. * @static
  2042. * @memberOf _
  2043. * @since 0.1.0
  2044. * @category Collection
  2045. * @param {Array|Object} collection The collection to iterate over.
  2046. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  2047. * The iteratees to sort by.
  2048. * @returns {Array} Returns the new sorted array.
  2049. * @example
  2050. *
  2051. * var users = [
  2052. * { 'user': 'fred', 'age': 48 },
  2053. * { 'user': 'barney', 'age': 36 },
  2054. * { 'user': 'fred', 'age': 30 },
  2055. * { 'user': 'barney', 'age': 34 }
  2056. * ];
  2057. *
  2058. * _.sortBy(users, [function(o) { return o.user; }]);
  2059. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
  2060. *
  2061. * _.sortBy(users, ['user', 'age']);
  2062. * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
  2063. */
  2064. function sortBy(collection, iteratee) {
  2065. var index = 0;
  2066. iteratee = baseIteratee(iteratee);
  2067. return baseMap(baseMap(collection, function(value, key, collection) {
  2068. return { 'value': value, 'index': index++, 'criteria': iteratee(value, key, collection) };
  2069. }).sort(function(object, other) {
  2070. return compareAscending(object.criteria, other.criteria) || (object.index - other.index);
  2071. }), baseProperty('value'));
  2072. }
  2073. /*------------------------------------------------------------------------*/
  2074. /**
  2075. * Creates a function that invokes `func`, with the `this` binding and arguments
  2076. * of the created function, while it's called less than `n` times. Subsequent
  2077. * calls to the created function return the result of the last `func` invocation.
  2078. *
  2079. * @static
  2080. * @memberOf _
  2081. * @since 3.0.0
  2082. * @category Function
  2083. * @param {number} n The number of calls at which `func` is no longer invoked.
  2084. * @param {Function} func The function to restrict.
  2085. * @returns {Function} Returns the new restricted function.
  2086. * @example
  2087. *
  2088. * jQuery(element).on('click', _.before(5, addContactToList));
  2089. * // => Allows adding up to 4 contacts to the list.
  2090. */
  2091. function before(n, func) {
  2092. var result;
  2093. if (typeof func != 'function') {
  2094. throw new TypeError(FUNC_ERROR_TEXT);
  2095. }
  2096. n = toInteger(n);
  2097. return function() {
  2098. if (--n > 0) {
  2099. result = func.apply(this, arguments);
  2100. }
  2101. if (n <= 1) {
  2102. func = undefined;
  2103. }
  2104. return result;
  2105. };
  2106. }
  2107. /**
  2108. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  2109. * and `partials` prepended to the arguments it receives.
  2110. *
  2111. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  2112. * may be used as a placeholder for partially applied arguments.
  2113. *
  2114. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  2115. * property of bound functions.
  2116. *
  2117. * @static
  2118. * @memberOf _
  2119. * @since 0.1.0
  2120. * @category Function
  2121. * @param {Function} func The function to bind.
  2122. * @param {*} thisArg The `this` binding of `func`.
  2123. * @param {...*} [partials] The arguments to be partially applied.
  2124. * @returns {Function} Returns the new bound function.
  2125. * @example
  2126. *
  2127. * function greet(greeting, punctuation) {
  2128. * return greeting + ' ' + this.user + punctuation;
  2129. * }
  2130. *
  2131. * var object = { 'user': 'fred' };
  2132. *
  2133. * var bound = _.bind(greet, object, 'hi');
  2134. * bound('!');
  2135. * // => 'hi fred!'
  2136. *
  2137. * // Bound with placeholders.
  2138. * var bound = _.bind(greet, object, _, '!');
  2139. * bound('hi');
  2140. * // => 'hi fred!'
  2141. */
  2142. var bind = baseRest(function(func, thisArg, partials) {
  2143. return createPartial(func, WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG, thisArg, partials);
  2144. });
  2145. /**
  2146. * Defers invoking the `func` until the current call stack has cleared. Any
  2147. * additional arguments are provided to `func` when it's invoked.
  2148. *
  2149. * @static
  2150. * @memberOf _
  2151. * @since 0.1.0
  2152. * @category Function
  2153. * @param {Function} func The function to defer.
  2154. * @param {...*} [args] The arguments to invoke `func` with.
  2155. * @returns {number} Returns the timer id.
  2156. * @example
  2157. *
  2158. * _.defer(function(text) {
  2159. * console.log(text);
  2160. * }, 'deferred');
  2161. * // => Logs 'deferred' after one millisecond.
  2162. */
  2163. var defer = baseRest(function(func, args) {
  2164. return baseDelay(func, 1, args);
  2165. });
  2166. /**
  2167. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  2168. * provided to `func` when it's invoked.
  2169. *
  2170. * @static
  2171. * @memberOf _
  2172. * @since 0.1.0
  2173. * @category Function
  2174. * @param {Function} func The function to delay.
  2175. * @param {number} wait The number of milliseconds to delay invocation.
  2176. * @param {...*} [args] The arguments to invoke `func` with.
  2177. * @returns {number} Returns the timer id.
  2178. * @example
  2179. *
  2180. * _.delay(function(text) {
  2181. * console.log(text);
  2182. * }, 1000, 'later');
  2183. * // => Logs 'later' after one second.
  2184. */
  2185. var delay = baseRest(function(func, wait, args) {
  2186. return baseDelay(func, toNumber(wait) || 0, args);
  2187. });
  2188. /**
  2189. * Creates a function that negates the result of the predicate `func`. The
  2190. * `func` predicate is invoked with the `this` binding and arguments of the
  2191. * created function.
  2192. *
  2193. * @static
  2194. * @memberOf _
  2195. * @since 3.0.0
  2196. * @category Function
  2197. * @param {Function} predicate The predicate to negate.
  2198. * @returns {Function} Returns the new negated function.
  2199. * @example
  2200. *
  2201. * function isEven(n) {
  2202. * return n % 2 == 0;
  2203. * }
  2204. *
  2205. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  2206. * // => [1, 3, 5]
  2207. */
  2208. function negate(predicate) {
  2209. if (typeof predicate != 'function') {
  2210. throw new TypeError(FUNC_ERROR_TEXT);
  2211. }
  2212. return function() {
  2213. var args = arguments;
  2214. return !predicate.apply(this, args);
  2215. };
  2216. }
  2217. /**
  2218. * Creates a function that is restricted to invoking `func` once. Repeat calls
  2219. * to the function return the value of the first invocation. The `func` is
  2220. * invoked with the `this` binding and arguments of the created function.
  2221. *
  2222. * @static
  2223. * @memberOf _
  2224. * @since 0.1.0
  2225. * @category Function
  2226. * @param {Function} func The function to restrict.
  2227. * @returns {Function} Returns the new restricted function.
  2228. * @example
  2229. *
  2230. * var initialize = _.once(createApplication);
  2231. * initialize();
  2232. * initialize();
  2233. * // => `createApplication` is invoked once
  2234. */
  2235. function once(func) {
  2236. return before(2, func);
  2237. }
  2238. /*------------------------------------------------------------------------*/
  2239. /**
  2240. * Creates a shallow clone of `value`.
  2241. *
  2242. * **Note:** This method is loosely based on the
  2243. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  2244. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  2245. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  2246. * arrays. The own enumerable properties of `arguments` objects are cloned
  2247. * as plain objects. An empty object is returned for uncloneable values such
  2248. * as error objects, functions, DOM nodes, and WeakMaps.
  2249. *
  2250. * @static
  2251. * @memberOf _
  2252. * @since 0.1.0
  2253. * @category Lang
  2254. * @param {*} value The value to clone.
  2255. * @returns {*} Returns the cloned value.
  2256. * @see _.cloneDeep
  2257. * @example
  2258. *
  2259. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  2260. *
  2261. * var shallow = _.clone(objects);
  2262. * console.log(shallow[0] === objects[0]);
  2263. * // => true
  2264. */
  2265. function clone(value) {
  2266. if (!isObject(value)) {
  2267. return value;
  2268. }
  2269. return isArray(value) ? copyArray(value) : copyObject(value, nativeKeys(value));
  2270. }
  2271. /**
  2272. * Performs a
  2273. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2274. * comparison between two values to determine if they are equivalent.
  2275. *
  2276. * @static
  2277. * @memberOf _
  2278. * @since 4.0.0
  2279. * @category Lang
  2280. * @param {*} value The value to compare.
  2281. * @param {*} other The other value to compare.
  2282. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2283. * @example
  2284. *
  2285. * var object = { 'a': 1 };
  2286. * var other = { 'a': 1 };
  2287. *
  2288. * _.eq(object, object);
  2289. * // => true
  2290. *
  2291. * _.eq(object, other);
  2292. * // => false
  2293. *
  2294. * _.eq('a', 'a');
  2295. * // => true
  2296. *
  2297. * _.eq('a', Object('a'));
  2298. * // => false
  2299. *
  2300. * _.eq(NaN, NaN);
  2301. * // => true
  2302. */
  2303. function eq(value, other) {
  2304. return value === other || (value !== value && other !== other);
  2305. }
  2306. /**
  2307. * Checks if `value` is likely an `arguments` object.
  2308. *
  2309. * @static
  2310. * @memberOf _
  2311. * @since 0.1.0
  2312. * @category Lang
  2313. * @param {*} value The value to check.
  2314. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2315. * else `false`.
  2316. * @example
  2317. *
  2318. * _.isArguments(function() { return arguments; }());
  2319. * // => true
  2320. *
  2321. * _.isArguments([1, 2, 3]);
  2322. * // => false
  2323. */
  2324. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  2325. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  2326. !propertyIsEnumerable.call(value, 'callee');
  2327. };
  2328. /**
  2329. * Checks if `value` is classified as an `Array` object.
  2330. *
  2331. * @static
  2332. * @memberOf _
  2333. * @since 0.1.0
  2334. * @category Lang
  2335. * @param {*} value The value to check.
  2336. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  2337. * @example
  2338. *
  2339. * _.isArray([1, 2, 3]);
  2340. * // => true
  2341. *
  2342. * _.isArray(document.body.children);
  2343. * // => false
  2344. *
  2345. * _.isArray('abc');
  2346. * // => false
  2347. *
  2348. * _.isArray(_.noop);
  2349. * // => false
  2350. */
  2351. var isArray = Array.isArray;
  2352. /**
  2353. * Checks if `value` is array-like. A value is considered array-like if it's
  2354. * not a function and has a `value.length` that's an integer greater than or
  2355. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  2356. *
  2357. * @static
  2358. * @memberOf _
  2359. * @since 4.0.0
  2360. * @category Lang
  2361. * @param {*} value The value to check.
  2362. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  2363. * @example
  2364. *
  2365. * _.isArrayLike([1, 2, 3]);
  2366. * // => true
  2367. *
  2368. * _.isArrayLike(document.body.children);
  2369. * // => true
  2370. *
  2371. * _.isArrayLike('abc');
  2372. * // => true
  2373. *
  2374. * _.isArrayLike(_.noop);
  2375. * // => false
  2376. */
  2377. function isArrayLike(value) {
  2378. return value != null && isLength(value.length) && !isFunction(value);
  2379. }
  2380. /**
  2381. * Checks if `value` is classified as a boolean primitive or object.
  2382. *
  2383. * @static
  2384. * @memberOf _
  2385. * @since 0.1.0
  2386. * @category Lang
  2387. * @param {*} value The value to check.
  2388. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  2389. * @example
  2390. *
  2391. * _.isBoolean(false);
  2392. * // => true
  2393. *
  2394. * _.isBoolean(null);
  2395. * // => false
  2396. */
  2397. function isBoolean(value) {
  2398. return value === true || value === false ||
  2399. (isObjectLike(value) && baseGetTag(value) == boolTag);
  2400. }
  2401. /**
  2402. * Checks if `value` is classified as a `Date` object.
  2403. *
  2404. * @static
  2405. * @memberOf _
  2406. * @since 0.1.0
  2407. * @category Lang
  2408. * @param {*} value The value to check.
  2409. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2410. * @example
  2411. *
  2412. * _.isDate(new Date);
  2413. * // => true
  2414. *
  2415. * _.isDate('Mon April 23 2012');
  2416. * // => false
  2417. */
  2418. var isDate = baseIsDate;
  2419. /**
  2420. * Checks if `value` is an empty object, collection, map, or set.
  2421. *
  2422. * Objects are considered empty if they have no own enumerable string keyed
  2423. * properties.
  2424. *
  2425. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  2426. * jQuery-like collections are considered empty if they have a `length` of `0`.
  2427. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  2428. *
  2429. * @static
  2430. * @memberOf _
  2431. * @since 0.1.0
  2432. * @category Lang
  2433. * @param {*} value The value to check.
  2434. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  2435. * @example
  2436. *
  2437. * _.isEmpty(null);
  2438. * // => true
  2439. *
  2440. * _.isEmpty(true);
  2441. * // => true
  2442. *
  2443. * _.isEmpty(1);
  2444. * // => true
  2445. *
  2446. * _.isEmpty([1, 2, 3]);
  2447. * // => false
  2448. *
  2449. * _.isEmpty({ 'a': 1 });
  2450. * // => false
  2451. */
  2452. function isEmpty(value) {
  2453. if (isArrayLike(value) &&
  2454. (isArray(value) || isString(value) ||
  2455. isFunction(value.splice) || isArguments(value))) {
  2456. return !value.length;
  2457. }
  2458. return !nativeKeys(value).length;
  2459. }
  2460. /**
  2461. * Performs a deep comparison between two values to determine if they are
  2462. * equivalent.
  2463. *
  2464. * **Note:** This method supports comparing arrays, array buffers, booleans,
  2465. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  2466. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  2467. * by their own, not inherited, enumerable properties. Functions and DOM
  2468. * nodes are compared by strict equality, i.e. `===`.
  2469. *
  2470. * @static
  2471. * @memberOf _
  2472. * @since 0.1.0
  2473. * @category Lang
  2474. * @param {*} value The value to compare.
  2475. * @param {*} other The other value to compare.
  2476. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2477. * @example
  2478. *
  2479. * var object = { 'a': 1 };
  2480. * var other = { 'a': 1 };
  2481. *
  2482. * _.isEqual(object, other);
  2483. * // => true
  2484. *
  2485. * object === other;
  2486. * // => false
  2487. */
  2488. function isEqual(value, other) {
  2489. return baseIsEqual(value, other);
  2490. }
  2491. /**
  2492. * Checks if `value` is a finite primitive number.
  2493. *
  2494. * **Note:** This method is based on
  2495. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  2496. *
  2497. * @static
  2498. * @memberOf _
  2499. * @since 0.1.0
  2500. * @category Lang
  2501. * @param {*} value The value to check.
  2502. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  2503. * @example
  2504. *
  2505. * _.isFinite(3);
  2506. * // => true
  2507. *
  2508. * _.isFinite(Number.MIN_VALUE);
  2509. * // => true
  2510. *
  2511. * _.isFinite(Infinity);
  2512. * // => false
  2513. *
  2514. * _.isFinite('3');
  2515. * // => false
  2516. */
  2517. function isFinite(value) {
  2518. return typeof value == 'number' && nativeIsFinite(value);
  2519. }
  2520. /**
  2521. * Checks if `value` is classified as a `Function` object.
  2522. *
  2523. * @static
  2524. * @memberOf _
  2525. * @since 0.1.0
  2526. * @category Lang
  2527. * @param {*} value The value to check.
  2528. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  2529. * @example
  2530. *
  2531. * _.isFunction(_);
  2532. * // => true
  2533. *
  2534. * _.isFunction(/abc/);
  2535. * // => false
  2536. */
  2537. function isFunction(value) {
  2538. if (!isObject(value)) {
  2539. return false;
  2540. }
  2541. // The use of `Object#toString` avoids issues with the `typeof` operator
  2542. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  2543. var tag = baseGetTag(value);
  2544. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  2545. }
  2546. /**
  2547. * Checks if `value` is a valid array-like length.
  2548. *
  2549. * **Note:** This method is loosely based on
  2550. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  2551. *
  2552. * @static
  2553. * @memberOf _
  2554. * @since 4.0.0
  2555. * @category Lang
  2556. * @param {*} value The value to check.
  2557. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  2558. * @example
  2559. *
  2560. * _.isLength(3);
  2561. * // => true
  2562. *
  2563. * _.isLength(Number.MIN_VALUE);
  2564. * // => false
  2565. *
  2566. * _.isLength(Infinity);
  2567. * // => false
  2568. *
  2569. * _.isLength('3');
  2570. * // => false
  2571. */
  2572. function isLength(value) {
  2573. return typeof value == 'number' &&
  2574. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  2575. }
  2576. /**
  2577. * Checks if `value` is the
  2578. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  2579. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  2580. *
  2581. * @static
  2582. * @memberOf _
  2583. * @since 0.1.0
  2584. * @category Lang
  2585. * @param {*} value The value to check.
  2586. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  2587. * @example
  2588. *
  2589. * _.isObject({});
  2590. * // => true
  2591. *
  2592. * _.isObject([1, 2, 3]);
  2593. * // => true
  2594. *
  2595. * _.isObject(_.noop);
  2596. * // => true
  2597. *
  2598. * _.isObject(null);
  2599. * // => false
  2600. */
  2601. function isObject(value) {
  2602. var type = typeof value;
  2603. return value != null && (type == 'object' || type == 'function');
  2604. }
  2605. /**
  2606. * Checks if `value` is object-like. A value is object-like if it's not `null`
  2607. * and has a `typeof` result of "object".
  2608. *
  2609. * @static
  2610. * @memberOf _
  2611. * @since 4.0.0
  2612. * @category Lang
  2613. * @param {*} value The value to check.
  2614. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  2615. * @example
  2616. *
  2617. * _.isObjectLike({});
  2618. * // => true
  2619. *
  2620. * _.isObjectLike([1, 2, 3]);
  2621. * // => true
  2622. *
  2623. * _.isObjectLike(_.noop);
  2624. * // => false
  2625. *
  2626. * _.isObjectLike(null);
  2627. * // => false
  2628. */
  2629. function isObjectLike(value) {
  2630. return value != null && typeof value == 'object';
  2631. }
  2632. /**
  2633. * Checks if `value` is `NaN`.
  2634. *
  2635. * **Note:** This method is based on
  2636. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  2637. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  2638. * `undefined` and other non-number values.
  2639. *
  2640. * @static
  2641. * @memberOf _
  2642. * @since 0.1.0
  2643. * @category Lang
  2644. * @param {*} value The value to check.
  2645. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  2646. * @example
  2647. *
  2648. * _.isNaN(NaN);
  2649. * // => true
  2650. *
  2651. * _.isNaN(new Number(NaN));
  2652. * // => true
  2653. *
  2654. * isNaN(undefined);
  2655. * // => true
  2656. *
  2657. * _.isNaN(undefined);
  2658. * // => false
  2659. */
  2660. function isNaN(value) {
  2661. // An `NaN` primitive is the only value that is not equal to itself.
  2662. // Perform the `toStringTag` check first to avoid errors with some
  2663. // ActiveX objects in IE.
  2664. return isNumber(value) && value != +value;
  2665. }
  2666. /**
  2667. * Checks if `value` is `null`.
  2668. *
  2669. * @static
  2670. * @memberOf _
  2671. * @since 0.1.0
  2672. * @category Lang
  2673. * @param {*} value The value to check.
  2674. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  2675. * @example
  2676. *
  2677. * _.isNull(null);
  2678. * // => true
  2679. *
  2680. * _.isNull(void 0);
  2681. * // => false
  2682. */
  2683. function isNull(value) {
  2684. return value === null;
  2685. }
  2686. /**
  2687. * Checks if `value` is classified as a `Number` primitive or object.
  2688. *
  2689. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  2690. * classified as numbers, use the `_.isFinite` method.
  2691. *
  2692. * @static
  2693. * @memberOf _
  2694. * @since 0.1.0
  2695. * @category Lang
  2696. * @param {*} value The value to check.
  2697. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  2698. * @example
  2699. *
  2700. * _.isNumber(3);
  2701. * // => true
  2702. *
  2703. * _.isNumber(Number.MIN_VALUE);
  2704. * // => true
  2705. *
  2706. * _.isNumber(Infinity);
  2707. * // => true
  2708. *
  2709. * _.isNumber('3');
  2710. * // => false
  2711. */
  2712. function isNumber(value) {
  2713. return typeof value == 'number' ||
  2714. (isObjectLike(value) && baseGetTag(value) == numberTag);
  2715. }
  2716. /**
  2717. * Checks if `value` is classified as a `RegExp` object.
  2718. *
  2719. * @static
  2720. * @memberOf _
  2721. * @since 0.1.0
  2722. * @category Lang
  2723. * @param {*} value The value to check.
  2724. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  2725. * @example
  2726. *
  2727. * _.isRegExp(/abc/);
  2728. * // => true
  2729. *
  2730. * _.isRegExp('/abc/');
  2731. * // => false
  2732. */
  2733. var isRegExp = baseIsRegExp;
  2734. /**
  2735. * Checks if `value` is classified as a `String` primitive or object.
  2736. *
  2737. * @static
  2738. * @since 0.1.0
  2739. * @memberOf _
  2740. * @category Lang
  2741. * @param {*} value The value to check.
  2742. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  2743. * @example
  2744. *
  2745. * _.isString('abc');
  2746. * // => true
  2747. *
  2748. * _.isString(1);
  2749. * // => false
  2750. */
  2751. function isString(value) {
  2752. return typeof value == 'string' ||
  2753. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  2754. }
  2755. /**
  2756. * Checks if `value` is `undefined`.
  2757. *
  2758. * @static
  2759. * @since 0.1.0
  2760. * @memberOf _
  2761. * @category Lang
  2762. * @param {*} value The value to check.
  2763. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  2764. * @example
  2765. *
  2766. * _.isUndefined(void 0);
  2767. * // => true
  2768. *
  2769. * _.isUndefined(null);
  2770. * // => false
  2771. */
  2772. function isUndefined(value) {
  2773. return value === undefined;
  2774. }
  2775. /**
  2776. * Converts `value` to an array.
  2777. *
  2778. * @static
  2779. * @since 0.1.0
  2780. * @memberOf _
  2781. * @category Lang
  2782. * @param {*} value The value to convert.
  2783. * @returns {Array} Returns the converted array.
  2784. * @example
  2785. *
  2786. * _.toArray({ 'a': 1, 'b': 2 });
  2787. * // => [1, 2]
  2788. *
  2789. * _.toArray('abc');
  2790. * // => ['a', 'b', 'c']
  2791. *
  2792. * _.toArray(1);
  2793. * // => []
  2794. *
  2795. * _.toArray(null);
  2796. * // => []
  2797. */
  2798. function toArray(value) {
  2799. if (!isArrayLike(value)) {
  2800. return values(value);
  2801. }
  2802. return value.length ? copyArray(value) : [];
  2803. }
  2804. /**
  2805. * Converts `value` to an integer.
  2806. *
  2807. * **Note:** This method is loosely based on
  2808. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  2809. *
  2810. * @static
  2811. * @memberOf _
  2812. * @since 4.0.0
  2813. * @category Lang
  2814. * @param {*} value The value to convert.
  2815. * @returns {number} Returns the converted integer.
  2816. * @example
  2817. *
  2818. * _.toInteger(3.2);
  2819. * // => 3
  2820. *
  2821. * _.toInteger(Number.MIN_VALUE);
  2822. * // => 0
  2823. *
  2824. * _.toInteger(Infinity);
  2825. * // => 1.7976931348623157e+308
  2826. *
  2827. * _.toInteger('3.2');
  2828. * // => 3
  2829. */
  2830. var toInteger = Number;
  2831. /**
  2832. * Converts `value` to a number.
  2833. *
  2834. * @static
  2835. * @memberOf _
  2836. * @since 4.0.0
  2837. * @category Lang
  2838. * @param {*} value The value to process.
  2839. * @returns {number} Returns the number.
  2840. * @example
  2841. *
  2842. * _.toNumber(3.2);
  2843. * // => 3.2
  2844. *
  2845. * _.toNumber(Number.MIN_VALUE);
  2846. * // => 5e-324
  2847. *
  2848. * _.toNumber(Infinity);
  2849. * // => Infinity
  2850. *
  2851. * _.toNumber('3.2');
  2852. * // => 3.2
  2853. */
  2854. var toNumber = Number;
  2855. /**
  2856. * Converts `value` to a string. An empty string is returned for `null`
  2857. * and `undefined` values. The sign of `-0` is preserved.
  2858. *
  2859. * @static
  2860. * @memberOf _
  2861. * @since 4.0.0
  2862. * @category Lang
  2863. * @param {*} value The value to convert.
  2864. * @returns {string} Returns the converted string.
  2865. * @example
  2866. *
  2867. * _.toString(null);
  2868. * // => ''
  2869. *
  2870. * _.toString(-0);
  2871. * // => '-0'
  2872. *
  2873. * _.toString([1, 2, 3]);
  2874. * // => '1,2,3'
  2875. */
  2876. function toString(value) {
  2877. if (typeof value == 'string') {
  2878. return value;
  2879. }
  2880. return value == null ? '' : (value + '');
  2881. }
  2882. /*------------------------------------------------------------------------*/
  2883. /**
  2884. * Assigns own enumerable string keyed properties of source objects to the
  2885. * destination object. Source objects are applied from left to right.
  2886. * Subsequent sources overwrite property assignments of previous sources.
  2887. *
  2888. * **Note:** This method mutates `object` and is loosely based on
  2889. * [`Object.assign`](https://mdn.io/Object/assign).
  2890. *
  2891. * @static
  2892. * @memberOf _
  2893. * @since 0.10.0
  2894. * @category Object
  2895. * @param {Object} object The destination object.
  2896. * @param {...Object} [sources] The source objects.
  2897. * @returns {Object} Returns `object`.
  2898. * @see _.assignIn
  2899. * @example
  2900. *
  2901. * function Foo() {
  2902. * this.a = 1;
  2903. * }
  2904. *
  2905. * function Bar() {
  2906. * this.c = 3;
  2907. * }
  2908. *
  2909. * Foo.prototype.b = 2;
  2910. * Bar.prototype.d = 4;
  2911. *
  2912. * _.assign({ 'a': 0 }, new Foo, new Bar);
  2913. * // => { 'a': 1, 'c': 3 }
  2914. */
  2915. var assign = createAssigner(function(object, source) {
  2916. copyObject(source, nativeKeys(source), object);
  2917. });
  2918. /**
  2919. * This method is like `_.assign` except that it iterates over own and
  2920. * inherited source properties.
  2921. *
  2922. * **Note:** This method mutates `object`.
  2923. *
  2924. * @static
  2925. * @memberOf _
  2926. * @since 4.0.0
  2927. * @alias extend
  2928. * @category Object
  2929. * @param {Object} object The destination object.
  2930. * @param {...Object} [sources] The source objects.
  2931. * @returns {Object} Returns `object`.
  2932. * @see _.assign
  2933. * @example
  2934. *
  2935. * function Foo() {
  2936. * this.a = 1;
  2937. * }
  2938. *
  2939. * function Bar() {
  2940. * this.c = 3;
  2941. * }
  2942. *
  2943. * Foo.prototype.b = 2;
  2944. * Bar.prototype.d = 4;
  2945. *
  2946. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  2947. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  2948. */
  2949. var assignIn = createAssigner(function(object, source) {
  2950. copyObject(source, nativeKeysIn(source), object);
  2951. });
  2952. /**
  2953. * Creates an object that inherits from the `prototype` object. If a
  2954. * `properties` object is given, its own enumerable string keyed properties
  2955. * are assigned to the created object.
  2956. *
  2957. * @static
  2958. * @memberOf _
  2959. * @since 2.3.0
  2960. * @category Object
  2961. * @param {Object} prototype The object to inherit from.
  2962. * @param {Object} [properties] The properties to assign to the object.
  2963. * @returns {Object} Returns the new object.
  2964. * @example
  2965. *
  2966. * function Shape() {
  2967. * this.x = 0;
  2968. * this.y = 0;
  2969. * }
  2970. *
  2971. * function Circle() {
  2972. * Shape.call(this);
  2973. * }
  2974. *
  2975. * Circle.prototype = _.create(Shape.prototype, {
  2976. * 'constructor': Circle
  2977. * });
  2978. *
  2979. * var circle = new Circle;
  2980. * circle instanceof Circle;
  2981. * // => true
  2982. *
  2983. * circle instanceof Shape;
  2984. * // => true
  2985. */
  2986. function create(prototype, properties) {
  2987. var result = baseCreate(prototype);
  2988. return properties == null ? result : assign(result, properties);
  2989. }
  2990. /**
  2991. * Assigns own and inherited enumerable string keyed properties of source
  2992. * objects to the destination object for all destination properties that
  2993. * resolve to `undefined`. Source objects are applied from left to right.
  2994. * Once a property is set, additional values of the same property are ignored.
  2995. *
  2996. * **Note:** This method mutates `object`.
  2997. *
  2998. * @static
  2999. * @since 0.1.0
  3000. * @memberOf _
  3001. * @category Object
  3002. * @param {Object} object The destination object.
  3003. * @param {...Object} [sources] The source objects.
  3004. * @returns {Object} Returns `object`.
  3005. * @see _.defaultsDeep
  3006. * @example
  3007. *
  3008. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  3009. * // => { 'a': 1, 'b': 2 }
  3010. */
  3011. var defaults = baseRest(function(object, sources) {
  3012. object = Object(object);
  3013. var index = -1;
  3014. var length = sources.length;
  3015. var guard = length > 2 ? sources[2] : undefined;
  3016. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  3017. length = 1;
  3018. }
  3019. while (++index < length) {
  3020. var source = sources[index];
  3021. var props = keysIn(source);
  3022. var propsIndex = -1;
  3023. var propsLength = props.length;
  3024. while (++propsIndex < propsLength) {
  3025. var key = props[propsIndex];
  3026. var value = object[key];
  3027. if (value === undefined ||
  3028. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  3029. object[key] = source[key];
  3030. }
  3031. }
  3032. }
  3033. return object;
  3034. });
  3035. /**
  3036. * Checks if `path` is a direct property of `object`.
  3037. *
  3038. * @static
  3039. * @since 0.1.0
  3040. * @memberOf _
  3041. * @category Object
  3042. * @param {Object} object The object to query.
  3043. * @param {Array|string} path The path to check.
  3044. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  3045. * @example
  3046. *
  3047. * var object = { 'a': { 'b': 2 } };
  3048. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  3049. *
  3050. * _.has(object, 'a');
  3051. * // => true
  3052. *
  3053. * _.has(object, 'a.b');
  3054. * // => true
  3055. *
  3056. * _.has(object, ['a', 'b']);
  3057. * // => true
  3058. *
  3059. * _.has(other, 'a');
  3060. * // => false
  3061. */
  3062. function has(object, path) {
  3063. return object != null && hasOwnProperty.call(object, path);
  3064. }
  3065. /**
  3066. * Creates an array of the own enumerable property names of `object`.
  3067. *
  3068. * **Note:** Non-object values are coerced to objects. See the
  3069. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  3070. * for more details.
  3071. *
  3072. * @static
  3073. * @since 0.1.0
  3074. * @memberOf _
  3075. * @category Object
  3076. * @param {Object} object The object to query.
  3077. * @returns {Array} Returns the array of property names.
  3078. * @example
  3079. *
  3080. * function Foo() {
  3081. * this.a = 1;
  3082. * this.b = 2;
  3083. * }
  3084. *
  3085. * Foo.prototype.c = 3;
  3086. *
  3087. * _.keys(new Foo);
  3088. * // => ['a', 'b'] (iteration order is not guaranteed)
  3089. *
  3090. * _.keys('hi');
  3091. * // => ['0', '1']
  3092. */
  3093. var keys = nativeKeys;
  3094. /**
  3095. * Creates an array of the own and inherited enumerable property names of `object`.
  3096. *
  3097. * **Note:** Non-object values are coerced to objects.
  3098. *
  3099. * @static
  3100. * @memberOf _
  3101. * @since 3.0.0
  3102. * @category Object
  3103. * @param {Object} object The object to query.
  3104. * @returns {Array} Returns the array of property names.
  3105. * @example
  3106. *
  3107. * function Foo() {
  3108. * this.a = 1;
  3109. * this.b = 2;
  3110. * }
  3111. *
  3112. * Foo.prototype.c = 3;
  3113. *
  3114. * _.keysIn(new Foo);
  3115. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  3116. */
  3117. var keysIn = nativeKeysIn;
  3118. /**
  3119. * Creates an object composed of the picked `object` properties.
  3120. *
  3121. * @static
  3122. * @since 0.1.0
  3123. * @memberOf _
  3124. * @category Object
  3125. * @param {Object} object The source object.
  3126. * @param {...(string|string[])} [paths] The property paths to pick.
  3127. * @returns {Object} Returns the new object.
  3128. * @example
  3129. *
  3130. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  3131. *
  3132. * _.pick(object, ['a', 'c']);
  3133. * // => { 'a': 1, 'c': 3 }
  3134. */
  3135. var pick = flatRest(function(object, paths) {
  3136. return object == null ? {} : basePick(object, paths);
  3137. });
  3138. /**
  3139. * This method is like `_.get` except that if the resolved value is a
  3140. * function it's invoked with the `this` binding of its parent object and
  3141. * its result is returned.
  3142. *
  3143. * @static
  3144. * @since 0.1.0
  3145. * @memberOf _
  3146. * @category Object
  3147. * @param {Object} object The object to query.
  3148. * @param {Array|string} path The path of the property to resolve.
  3149. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  3150. * @returns {*} Returns the resolved value.
  3151. * @example
  3152. *
  3153. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  3154. *
  3155. * _.result(object, 'a[0].b.c1');
  3156. * // => 3
  3157. *
  3158. * _.result(object, 'a[0].b.c2');
  3159. * // => 4
  3160. *
  3161. * _.result(object, 'a[0].b.c3', 'default');
  3162. * // => 'default'
  3163. *
  3164. * _.result(object, 'a[0].b.c3', _.constant('default'));
  3165. * // => 'default'
  3166. */
  3167. function result(object, path, defaultValue) {
  3168. var value = object == null ? undefined : object[path];
  3169. if (value === undefined) {
  3170. value = defaultValue;
  3171. }
  3172. return isFunction(value) ? value.call(object) : value;
  3173. }
  3174. /**
  3175. * Creates an array of the own enumerable string keyed property values of `object`.
  3176. *
  3177. * **Note:** Non-object values are coerced to objects.
  3178. *
  3179. * @static
  3180. * @since 0.1.0
  3181. * @memberOf _
  3182. * @category Object
  3183. * @param {Object} object The object to query.
  3184. * @returns {Array} Returns the array of property values.
  3185. * @example
  3186. *
  3187. * function Foo() {
  3188. * this.a = 1;
  3189. * this.b = 2;
  3190. * }
  3191. *
  3192. * Foo.prototype.c = 3;
  3193. *
  3194. * _.values(new Foo);
  3195. * // => [1, 2] (iteration order is not guaranteed)
  3196. *
  3197. * _.values('hi');
  3198. * // => ['h', 'i']
  3199. */
  3200. function values(object) {
  3201. return object == null ? [] : baseValues(object, keys(object));
  3202. }
  3203. /*------------------------------------------------------------------------*/
  3204. /**
  3205. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  3206. * corresponding HTML entities.
  3207. *
  3208. * **Note:** No other characters are escaped. To escape additional
  3209. * characters use a third-party library like [_he_](https://mths.be/he).
  3210. *
  3211. * Though the ">" character is escaped for symmetry, characters like
  3212. * ">" and "/" don't need escaping in HTML and have no special meaning
  3213. * unless they're part of a tag or unquoted attribute value. See
  3214. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  3215. * (under "semi-related fun fact") for more details.
  3216. *
  3217. * When working with HTML you should always
  3218. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  3219. * XSS vectors.
  3220. *
  3221. * @static
  3222. * @since 0.1.0
  3223. * @memberOf _
  3224. * @category String
  3225. * @param {string} [string=''] The string to escape.
  3226. * @returns {string} Returns the escaped string.
  3227. * @example
  3228. *
  3229. * _.escape('fred, barney, & pebbles');
  3230. * // => 'fred, barney, &amp; pebbles'
  3231. */
  3232. function escape(string) {
  3233. string = toString(string);
  3234. return (string && reHasUnescapedHtml.test(string))
  3235. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  3236. : string;
  3237. }
  3238. /*------------------------------------------------------------------------*/
  3239. /**
  3240. * This method returns the first argument it receives.
  3241. *
  3242. * @static
  3243. * @since 0.1.0
  3244. * @memberOf _
  3245. * @category Util
  3246. * @param {*} value Any value.
  3247. * @returns {*} Returns `value`.
  3248. * @example
  3249. *
  3250. * var object = { 'a': 1 };
  3251. *
  3252. * console.log(_.identity(object) === object);
  3253. * // => true
  3254. */
  3255. function identity(value) {
  3256. return value;
  3257. }
  3258. /**
  3259. * Creates a function that invokes `func` with the arguments of the created
  3260. * function. If `func` is a property name, the created function returns the
  3261. * property value for a given element. If `func` is an array or object, the
  3262. * created function returns `true` for elements that contain the equivalent
  3263. * source properties, otherwise it returns `false`.
  3264. *
  3265. * @static
  3266. * @since 4.0.0
  3267. * @memberOf _
  3268. * @category Util
  3269. * @param {*} [func=_.identity] The value to convert to a callback.
  3270. * @returns {Function} Returns the callback.
  3271. * @example
  3272. *
  3273. * var users = [
  3274. * { 'user': 'barney', 'age': 36, 'active': true },
  3275. * { 'user': 'fred', 'age': 40, 'active': false }
  3276. * ];
  3277. *
  3278. * // The `_.matches` iteratee shorthand.
  3279. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  3280. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  3281. *
  3282. * // The `_.matchesProperty` iteratee shorthand.
  3283. * _.filter(users, _.iteratee(['user', 'fred']));
  3284. * // => [{ 'user': 'fred', 'age': 40 }]
  3285. *
  3286. * // The `_.property` iteratee shorthand.
  3287. * _.map(users, _.iteratee('user'));
  3288. * // => ['barney', 'fred']
  3289. *
  3290. * // Create custom iteratee shorthands.
  3291. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  3292. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  3293. * return func.test(string);
  3294. * };
  3295. * });
  3296. *
  3297. * _.filter(['abc', 'def'], /ef/);
  3298. * // => ['def']
  3299. */
  3300. var iteratee = baseIteratee;
  3301. /**
  3302. * Creates a function that performs a partial deep comparison between a given
  3303. * object and `source`, returning `true` if the given object has equivalent
  3304. * property values, else `false`.
  3305. *
  3306. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  3307. * partially applied.
  3308. *
  3309. * Partial comparisons will match empty array and empty object `source`
  3310. * values against any array or object value, respectively. See `_.isEqual`
  3311. * for a list of supported value comparisons.
  3312. *
  3313. * **Note:** Multiple values can be checked by combining several matchers
  3314. * using `_.overSome`
  3315. *
  3316. * @static
  3317. * @memberOf _
  3318. * @since 3.0.0
  3319. * @category Util
  3320. * @param {Object} source The object of property values to match.
  3321. * @returns {Function} Returns the new spec function.
  3322. * @example
  3323. *
  3324. * var objects = [
  3325. * { 'a': 1, 'b': 2, 'c': 3 },
  3326. * { 'a': 4, 'b': 5, 'c': 6 }
  3327. * ];
  3328. *
  3329. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  3330. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  3331. *
  3332. * // Checking for several possible values
  3333. * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
  3334. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  3335. */
  3336. function matches(source) {
  3337. return baseMatches(assign({}, source));
  3338. }
  3339. /**
  3340. * Adds all own enumerable string keyed function properties of a source
  3341. * object to the destination object. If `object` is a function, then methods
  3342. * are added to its prototype as well.
  3343. *
  3344. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  3345. * avoid conflicts caused by modifying the original.
  3346. *
  3347. * @static
  3348. * @since 0.1.0
  3349. * @memberOf _
  3350. * @category Util
  3351. * @param {Function|Object} [object=lodash] The destination object.
  3352. * @param {Object} source The object of functions to add.
  3353. * @param {Object} [options={}] The options object.
  3354. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  3355. * @returns {Function|Object} Returns `object`.
  3356. * @example
  3357. *
  3358. * function vowels(string) {
  3359. * return _.filter(string, function(v) {
  3360. * return /[aeiou]/i.test(v);
  3361. * });
  3362. * }
  3363. *
  3364. * _.mixin({ 'vowels': vowels });
  3365. * _.vowels('fred');
  3366. * // => ['e']
  3367. *
  3368. * _('fred').vowels().value();
  3369. * // => ['e']
  3370. *
  3371. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  3372. * _('fred').vowels();
  3373. * // => ['e']
  3374. */
  3375. function mixin(object, source, options) {
  3376. var props = keys(source),
  3377. methodNames = baseFunctions(source, props);
  3378. if (options == null &&
  3379. !(isObject(source) && (methodNames.length || !props.length))) {
  3380. options = source;
  3381. source = object;
  3382. object = this;
  3383. methodNames = baseFunctions(source, keys(source));
  3384. }
  3385. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  3386. isFunc = isFunction(object);
  3387. baseEach(methodNames, function(methodName) {
  3388. var func = source[methodName];
  3389. object[methodName] = func;
  3390. if (isFunc) {
  3391. object.prototype[methodName] = function() {
  3392. var chainAll = this.__chain__;
  3393. if (chain || chainAll) {
  3394. var result = object(this.__wrapped__),
  3395. actions = result.__actions__ = copyArray(this.__actions__);
  3396. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  3397. result.__chain__ = chainAll;
  3398. return result;
  3399. }
  3400. return func.apply(object, arrayPush([this.value()], arguments));
  3401. };
  3402. }
  3403. });
  3404. return object;
  3405. }
  3406. /**
  3407. * Reverts the `_` variable to its previous value and returns a reference to
  3408. * the `lodash` function.
  3409. *
  3410. * @static
  3411. * @since 0.1.0
  3412. * @memberOf _
  3413. * @category Util
  3414. * @returns {Function} Returns the `lodash` function.
  3415. * @example
  3416. *
  3417. * var lodash = _.noConflict();
  3418. */
  3419. function noConflict() {
  3420. if (root._ === this) {
  3421. root._ = oldDash;
  3422. }
  3423. return this;
  3424. }
  3425. /**
  3426. * This method returns `undefined`.
  3427. *
  3428. * @static
  3429. * @memberOf _
  3430. * @since 2.3.0
  3431. * @category Util
  3432. * @example
  3433. *
  3434. * _.times(2, _.noop);
  3435. * // => [undefined, undefined]
  3436. */
  3437. function noop() {
  3438. // No operation performed.
  3439. }
  3440. /**
  3441. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  3442. *
  3443. * @static
  3444. * @since 0.1.0
  3445. * @memberOf _
  3446. * @category Util
  3447. * @param {string} [prefix=''] The value to prefix the ID with.
  3448. * @returns {string} Returns the unique ID.
  3449. * @example
  3450. *
  3451. * _.uniqueId('contact_');
  3452. * // => 'contact_104'
  3453. *
  3454. * _.uniqueId();
  3455. * // => '105'
  3456. */
  3457. function uniqueId(prefix) {
  3458. var id = ++idCounter;
  3459. return toString(prefix) + id;
  3460. }
  3461. /*------------------------------------------------------------------------*/
  3462. /**
  3463. * Computes the maximum 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 maximum value.
  3472. * @example
  3473. *
  3474. * _.max([4, 2, 8, 6]);
  3475. * // => 8
  3476. *
  3477. * _.max([]);
  3478. * // => undefined
  3479. */
  3480. function max(array) {
  3481. return (array && array.length)
  3482. ? baseExtremum(array, identity, baseGt)
  3483. : undefined;
  3484. }
  3485. /**
  3486. * Computes the minimum value of `array`. If `array` is empty or falsey,
  3487. * `undefined` is returned.
  3488. *
  3489. * @static
  3490. * @since 0.1.0
  3491. * @memberOf _
  3492. * @category Math
  3493. * @param {Array} array The array to iterate over.
  3494. * @returns {*} Returns the minimum value.
  3495. * @example
  3496. *
  3497. * _.min([4, 2, 8, 6]);
  3498. * // => 2
  3499. *
  3500. * _.min([]);
  3501. * // => undefined
  3502. */
  3503. function min(array) {
  3504. return (array && array.length)
  3505. ? baseExtremum(array, identity, baseLt)
  3506. : undefined;
  3507. }
  3508. /*------------------------------------------------------------------------*/
  3509. // Add methods that return wrapped values in chain sequences.
  3510. lodash.assignIn = assignIn;
  3511. lodash.before = before;
  3512. lodash.bind = bind;
  3513. lodash.chain = chain;
  3514. lodash.compact = compact;
  3515. lodash.concat = concat;
  3516. lodash.create = create;
  3517. lodash.defaults = defaults;
  3518. lodash.defer = defer;
  3519. lodash.delay = delay;
  3520. lodash.filter = filter;
  3521. lodash.flatten = flatten;
  3522. lodash.flattenDeep = flattenDeep;
  3523. lodash.iteratee = iteratee;
  3524. lodash.keys = keys;
  3525. lodash.map = map;
  3526. lodash.matches = matches;
  3527. lodash.mixin = mixin;
  3528. lodash.negate = negate;
  3529. lodash.once = once;
  3530. lodash.pick = pick;
  3531. lodash.slice = slice;
  3532. lodash.sortBy = sortBy;
  3533. lodash.tap = tap;
  3534. lodash.thru = thru;
  3535. lodash.toArray = toArray;
  3536. lodash.values = values;
  3537. // Add aliases.
  3538. lodash.extend = assignIn;
  3539. // Add methods to `lodash.prototype`.
  3540. mixin(lodash, lodash);
  3541. /*------------------------------------------------------------------------*/
  3542. // Add methods that return unwrapped values in chain sequences.
  3543. lodash.clone = clone;
  3544. lodash.escape = escape;
  3545. lodash.every = every;
  3546. lodash.find = find;
  3547. lodash.forEach = forEach;
  3548. lodash.has = has;
  3549. lodash.head = head;
  3550. lodash.identity = identity;
  3551. lodash.indexOf = indexOf;
  3552. lodash.isArguments = isArguments;
  3553. lodash.isArray = isArray;
  3554. lodash.isBoolean = isBoolean;
  3555. lodash.isDate = isDate;
  3556. lodash.isEmpty = isEmpty;
  3557. lodash.isEqual = isEqual;
  3558. lodash.isFinite = isFinite;
  3559. lodash.isFunction = isFunction;
  3560. lodash.isNaN = isNaN;
  3561. lodash.isNull = isNull;
  3562. lodash.isNumber = isNumber;
  3563. lodash.isObject = isObject;
  3564. lodash.isRegExp = isRegExp;
  3565. lodash.isString = isString;
  3566. lodash.isUndefined = isUndefined;
  3567. lodash.last = last;
  3568. lodash.max = max;
  3569. lodash.min = min;
  3570. lodash.noConflict = noConflict;
  3571. lodash.noop = noop;
  3572. lodash.reduce = reduce;
  3573. lodash.result = result;
  3574. lodash.size = size;
  3575. lodash.some = some;
  3576. lodash.uniqueId = uniqueId;
  3577. // Add aliases.
  3578. lodash.each = forEach;
  3579. lodash.first = head;
  3580. mixin(lodash, (function() {
  3581. var source = {};
  3582. baseForOwn(lodash, function(func, methodName) {
  3583. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  3584. source[methodName] = func;
  3585. }
  3586. });
  3587. return source;
  3588. }()), { 'chain': false });
  3589. /*------------------------------------------------------------------------*/
  3590. /**
  3591. * The semantic version number.
  3592. *
  3593. * @static
  3594. * @memberOf _
  3595. * @type {string}
  3596. */
  3597. lodash.VERSION = VERSION;
  3598. // Add `Array` methods to `lodash.prototype`.
  3599. baseEach(['pop', 'join', 'replace', 'reverse', 'split', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  3600. var func = (/^(?:replace|split)$/.test(methodName) ? String.prototype : arrayProto)[methodName],
  3601. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  3602. retUnwrapped = /^(?:pop|join|replace|shift)$/.test(methodName);
  3603. lodash.prototype[methodName] = function() {
  3604. var args = arguments;
  3605. if (retUnwrapped && !this.__chain__) {
  3606. var value = this.value();
  3607. return func.apply(isArray(value) ? value : [], args);
  3608. }
  3609. return this[chainName](function(value) {
  3610. return func.apply(isArray(value) ? value : [], args);
  3611. });
  3612. };
  3613. });
  3614. // Add chain sequence methods to the `lodash` wrapper.
  3615. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  3616. /*--------------------------------------------------------------------------*/
  3617. // Some AMD build optimizers, like r.js, check for condition patterns like:
  3618. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  3619. // Expose Lodash on the global object to prevent errors when Lodash is
  3620. // loaded by a script tag in the presence of an AMD loader.
  3621. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  3622. // Use `_.noConflict` to remove Lodash from the global object.
  3623. root._ = lodash;
  3624. // Define as an anonymous module so, through path mapping, it can be
  3625. // referenced as the "underscore" module.
  3626. define(function() {
  3627. return lodash;
  3628. });
  3629. }
  3630. // Check for `exports` after `define` in case a build optimizer adds it.
  3631. else if (freeModule) {
  3632. // Export for Node.js.
  3633. (freeModule.exports = lodash)._ = lodash;
  3634. // Export for CommonJS support.
  3635. freeExports._ = lodash;
  3636. }
  3637. else {
  3638. // Export to the global object.
  3639. root._ = lodash;
  3640. }
  3641. }.call(this));