Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

core.js 113KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877
  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.20';
  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));