12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307 |
- /**
- * @license
- * Lo-Dash 1.0.2 (Custom Build) <http://lodash.com/>
- * Build: `lodash underscore -o ./dist/lodash.underscore.js`
- * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
- * Based on Underscore.js 1.4.4 <http://underscorejs.org/>
- * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
- * Available under MIT license <http://lodash.com/license>
- */
- ;(function(window, undefined) {
- /** Detect free variable `exports` */
- var freeExports = typeof exports == 'object' && exports;
- /** Detect free variable `module` */
- var freeModule = typeof module == 'object' && module && module.exports == freeExports && module;
- /** Detect free variable `global` and use it as `window` */
- var freeGlobal = typeof global == 'object' && global;
- if (freeGlobal.global === freeGlobal) {
- window = freeGlobal;
- }
- /** Used for array and object method references */
- var arrayRef = [],
- objectRef = {};
- /** Used to generate unique IDs */
- var idCounter = 0;
- /** Used internally to indicate various things */
- var indicatorObject = objectRef;
- /** Used to restore the original `_` reference in `noConflict` */
- var oldDash = window._;
- /** Used to match HTML entities */
- var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g;
- /** Used to match empty string literals in compiled template source */
- var reEmptyStringLeading = /\b__p \+= '';/g,
- reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
- reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
- /** Used to match regexp flags from their coerced string values */
- var reFlags = /\w*$/;
- /** Used to detect if a method is native */
- var reNative = RegExp('^' +
- (objectRef.valueOf + '')
- .replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
- .replace(/valueOf|for [^\]]+/g, '.+?') + '$'
- );
- /**
- * Used to match ES6 template delimiters
- * http://people.mozilla.org/~jorendorff/es6-draft.html#sec-7.8.6
- */
- var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
- /** Used to match "interpolate" template delimiters */
- var reInterpolate = /<%=([\s\S]+?)%>/g;
- /** Used to ensure capturing order of template delimiters */
- var reNoMatch = /($^)/;
- /** Used to match HTML characters */
- var reUnescapedHtml = /[&<>"']/g;
- /** Used to match unescaped characters in compiled string literals */
- var reUnescapedString = /['\n\r\t\u2028\u2029\\]/g;
- /** Used to make template sourceURLs easier to identify */
- var templateCounter = 0;
- /** Native method shortcuts */
- var ceil = Math.ceil,
- concat = arrayRef.concat,
- floor = Math.floor,
- hasOwnProperty = objectRef.hasOwnProperty,
- push = arrayRef.push,
- toString = objectRef.toString;
- /* Native method shortcuts for methods with the same name as other `lodash` methods */
- var nativeBind = reNative.test(nativeBind = slice.bind) && nativeBind,
- nativeIsArray = reNative.test(nativeIsArray = Array.isArray) && nativeIsArray,
- nativeIsFinite = window.isFinite,
- nativeIsNaN = window.isNaN,
- nativeKeys = reNative.test(nativeKeys = Object.keys) && nativeKeys,
- nativeMax = Math.max,
- nativeMin = Math.min,
- nativeRandom = Math.random;
- /** `Object#toString` result shortcuts */
- var argsClass = '[object Arguments]',
- arrayClass = '[object Array]',
- boolClass = '[object Boolean]',
- dateClass = '[object Date]',
- funcClass = '[object Function]',
- numberClass = '[object Number]',
- objectClass = '[object Object]',
- regexpClass = '[object RegExp]',
- stringClass = '[object String]';
- /** Detect various environments */
- var isIeOpera = !!window.attachEvent,
- isV8 = nativeBind && !/\n|true/.test(nativeBind + isIeOpera);
- /* Detect if `Function#bind` exists and is inferred to be fast (all but V8) */
- var isBindFast = nativeBind && !isV8;
- /**
- * Detect if `Array#shift` and `Array#splice` augment array-like objects
- * incorrectly:
- *
- * Firefox < 10, IE compatibility mode, and IE < 9 have buggy Array `shift()`
- * and `splice()` functions that fail to remove the last element, `value[0]`,
- * of array-like objects even though the `length` property is set to `0`.
- * The `shift()` method is buggy in IE 8 compatibility mode, while `splice()`
- * is buggy regardless of mode in IE < 9 and buggy in compatibility mode in IE 9.
- */
- var hasObjectSpliceBug = (hasObjectSpliceBug = { '0': 1, 'length': 1 },
- arrayRef.splice.call(hasObjectSpliceBug, 0, 1), hasObjectSpliceBug[0]);
- /** Detect if `arguments` objects are `Object` objects (all but Opera < 10.5) */
- var argsAreObjects = arguments.constructor == Object;
- /** Used to determine if values are of the language type Object */
- var objectTypes = {
- 'boolean': false,
- 'function': true,
- 'object': true,
- 'number': false,
- 'string': false,
- 'undefined': false
- };
- /** Used to escape characters for inclusion in compiled string literals */
- var stringEscapes = {
- '\\': '\\',
- "'": "'",
- '\n': 'n',
- '\r': 'r',
- '\t': 't',
- '\u2028': 'u2028',
- '\u2029': 'u2029'
- };
- /*--------------------------------------------------------------------------*/
- /**
- * Creates a `lodash` object, that wraps the given `value`, to enable method
- * chaining.
- *
- * In addition to Lo-Dash methods, wrappers also have the following `Array` methods:
- * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`,
- * and `unshift`
- *
- * The chainable wrapper functions are:
- * `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`, `compose`,
- * `concat`, `countBy`, `debounce`, `defaults`, `defer`, `delay`, `difference`,
- * `filter`, `flatten`, `forEach`, `forIn`, `forOwn`, `functions`, `groupBy`,
- * `initial`, `intersection`, `invert`, `invoke`, `keys`, `map`, `max`, `memoize`,
- * `merge`, `min`, `object`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
- * `pick`, `pluck`, `push`, `range`, `reject`, `rest`, `reverse`, `shuffle`,
- * `slice`, `sort`, `sortBy`, `splice`, `tap`, `throttle`, `times`, `toArray`,
- * `union`, `uniq`, `unshift`, `values`, `where`, `without`, `wrap`, and `zip`
- *
- * The non-chainable wrapper functions are:
- * `clone`, `cloneDeep`, `contains`, `escape`, `every`, `find`, `has`, `identity`,
- * `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`, `isEmpty`,
- * `isEqual`, `isFinite`, `isFunction`, `isNaN`, `isNull`, `isNumber`, `isObject`,
- * `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `join`, `lastIndexOf`,
- * `mixin`, `noConflict`, `pop`, `random`, `reduce`, `reduceRight`, `result`,
- * `shift`, `size`, `some`, `sortedIndex`, `template`, `unescape`, and `uniqueId`
- *
- * The wrapper functions `first` and `last` return wrapped values when `n` is
- * passed, otherwise they return unwrapped values.
- *
- * @name _
- * @constructor
- * @category Chaining
- * @param {Mixed} value The value to wrap in a `lodash` instance.
- * @returns {Object} Returns a `lodash` instance.
- */
- function lodash(value) {
- // exit early if already wrapped, even if wrapped by a different `lodash` constructor
- if (value && typeof value == 'object' && value.__wrapped__) {
- return value;
- }
- // allow invoking `lodash` without the `new` operator
- if (!(this instanceof lodash)) {
- return new lodash(value);
- }
- this.__wrapped__ = value;
- }
- /**
- * By default, the template delimiters used by Lo-Dash are similar to those in
- * embedded Ruby (ERB). Change the following template settings to use alternative
- * delimiters.
- *
- * @static
- * @memberOf _
- * @type Object
- */
- lodash.templateSettings = {
- /**
- * Used to detect `data` property values to be HTML-escaped.
- *
- * @memberOf _.templateSettings
- * @type RegExp
- */
- 'escape': /<%-([\s\S]+?)%>/g,
- /**
- * Used to detect code to be evaluated.
- *
- * @memberOf _.templateSettings
- * @type RegExp
- */
- 'evaluate': /<%([\s\S]+?)%>/g,
- /**
- * Used to detect `data` property values to inject.
- *
- * @memberOf _.templateSettings
- * @type RegExp
- */
- 'interpolate': reInterpolate,
- /**
- * Used to reference the data object in the template text.
- *
- * @memberOf _.templateSettings
- * @type String
- */
- 'variable': ''
- };
- /*--------------------------------------------------------------------------*/
- /**
- * Used by `_.max` and `_.min` as the default `callback` when a given
- * `collection` is a string value.
- *
- * @private
- * @param {String} value The character to inspect.
- * @returns {Number} Returns the code unit of given character.
- */
- function charAtCallback(value) {
- return value.charCodeAt(0);
- }
- /**
- * Used by `sortBy` to compare transformed `collection` values, stable sorting
- * them in ascending order.
- *
- * @private
- * @param {Object} a The object to compare to `b`.
- * @param {Object} b The object to compare to `a`.
- * @returns {Number} Returns the sort order indicator of `1` or `-1`.
- */
- function compareAscending(a, b) {
- var ai = a.index,
- bi = b.index;
- a = a.criteria;
- b = b.criteria;
- // ensure a stable sort in V8 and other engines
- // http://code.google.com/p/v8/issues/detail?id=90
- if (a !== b) {
- if (a > b || typeof a == 'undefined') {
- return 1;
- }
- if (a < b || typeof b == 'undefined') {
- return -1;
- }
- }
- return ai < bi ? -1 : 1;
- }
- /**
- * Creates a function that, when called, invokes `func` with the `this` binding
- * of `thisArg` and prepends any `partialArgs` to the arguments passed to the
- * bound function.
- *
- * @private
- * @param {Function|String} func The function to bind or the method name.
- * @param {Mixed} [thisArg] The `this` binding of `func`.
- * @param {Array} partialArgs An array of arguments to be partially applied.
- * @param {Object} [rightIndicator] Used to indicate partially applying arguments from the right.
- * @returns {Function} Returns the new bound function.
- */
- function createBound(func, thisArg, partialArgs, rightIndicator) {
- var isFunc = isFunction(func),
- isPartial = !partialArgs,
- key = thisArg;
- // juggle arguments
- if (isPartial) {
- partialArgs = thisArg;
- }
- if (!isFunc) {
- thisArg = func;
- }
- function bound() {
- // `Function#bind` spec
- // http://es5.github.com/#x15.3.4.5
- var args = arguments,
- thisBinding = isPartial ? this : thisArg;
- if (!isFunc) {
- func = thisArg[key];
- }
- if (partialArgs.length) {
- args = args.length
- ? (args = slice(args), rightIndicator ? args.concat(partialArgs) : partialArgs.concat(args))
- : partialArgs;
- }
- if (this instanceof bound) {
- // ensure `new bound` is an instance of `bound` and `func`
- noop.prototype = func.prototype;
- thisBinding = new noop;
- noop.prototype = null;
- // mimic the constructor's `return` behavior
- // http://es5.github.com/#x13.2.2
- var result = func.apply(thisBinding, args);
- return isObject(result) ? result : thisBinding;
- }
- return func.apply(thisBinding, args);
- }
- return bound;
- }
- /**
- * Produces a callback bound to an optional `thisArg`. If `func` is a property
- * name, the created callback will return the property value for a given element.
- * If `func` is an object, the created callback will return `true` for elements
- * that contain the equivalent object properties, otherwise it will return `false`.
- *
- * @private
- * @param {Mixed} [func=identity] The value to convert to a callback.
- * @param {Mixed} [thisArg] The `this` binding of the created callback.
- * @param {Number} [argCount=3] The number of arguments the callback accepts.
- * @returns {Function} Returns a callback function.
- */
- function createCallback(func, thisArg, argCount) {
- if (func == null) {
- return identity;
- }
- var type = typeof func;
- if (type != 'function') {
- if (type != 'object') {
- return function(object) {
- return object[func];
- };
- }
- var props = keys(func);
- return function(object) {
- var length = props.length,
- result = false;
- while (length--) {
- if (!(result = object[props[length]] === func[props[length]])) {
- break;
- }
- }
- return result;
- };
- }
- if (typeof thisArg != 'undefined') {
- if (argCount === 1) {
- return function(value) {
- return func.call(thisArg, value);
- };
- }
- if (argCount === 2) {
- return function(a, b) {
- return func.call(thisArg, a, b);
- };
- }
- if (argCount === 4) {
- return function(accumulator, value, index, object) {
- return func.call(thisArg, accumulator, value, index, object);
- };
- }
- return function(value, index, object) {
- return func.call(thisArg, value, index, object);
- };
- }
- return func;
- }
- /**
- * A function compiled to iterate `arguments` objects, arrays, objects, and
- * strings consistenly across environments, executing the `callback` for each
- * element in the `collection`. The `callback` is bound to `thisArg` and invoked
- * with three arguments; (value, index|key, collection). Callbacks may exit
- * iteration early by explicitly returning `false`.
- *
- * @private
- * @type Function
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function} [callback=identity] The function called per iteration.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Array|Object|String} Returns `collection`.
- */
- var each = function (collection, callback, thisArg) {
- var index, iterable = collection, result = iterable;
- if (!iterable) return result;
- callback = callback && typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg);
- var length = iterable.length; index = -1;
- if (typeof length == 'number') {
- while (++index < length) {
- if (callback(iterable[index], index, collection) === indicatorObject) return result
- }
- }
- else {
- for (index in iterable) {
- if (hasOwnProperty.call(iterable, index)) {
- if (callback(iterable[index], index, collection) === indicatorObject) return result;
- }
- }
- }
- };
- /**
- * Used by `template` to escape characters for inclusion in compiled
- * string literals.
- *
- * @private
- * @param {String} match The matched character to escape.
- * @returns {String} Returns the escaped character.
- */
- function escapeStringChar(match) {
- return '\\' + stringEscapes[match];
- }
- /**
- * Used by `escape` to convert characters to HTML entities.
- *
- * @private
- * @param {String} match The matched character to escape.
- * @returns {String} Returns the escaped character.
- */
- function escapeHtmlChar(match) {
- return htmlEscapes[match];
- }
- /**
- * Checks if `value` is a DOM node in IE < 9.
- *
- * @private
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true` if the `value` is a DOM node, else `false`.
- */
- function isNode(value) {
- // IE < 9 presents DOM nodes as `Object` objects except they have `toString`
- // methods that are `typeof` "string" and still can coerce nodes to strings
- return typeof value.toString != 'function' && typeof (value + '') == 'string';
- }
- /**
- * A no-operation function.
- *
- * @private
- */
- function noop() {
- // no operation performed
- }
- /**
- * Slices the `collection` from the `start` index up to, but not including,
- * the `end` index.
- *
- * Note: This function is used, instead of `Array#slice`, to support node lists
- * in IE < 9 and to ensure dense arrays are returned.
- *
- * @private
- * @param {Array|Object|String} collection The collection to slice.
- * @param {Number} start The start index.
- * @param {Number} end The end index.
- * @returns {Array} Returns the new array.
- */
- function slice(array, start, end) {
- start || (start = 0);
- if (typeof end == 'undefined') {
- end = array ? array.length : 0;
- }
- var index = -1,
- length = end - start || 0,
- result = Array(length < 0 ? 0 : length);
- while (++index < length) {
- result[index] = array[start + index];
- }
- return result;
- }
- /**
- * Used by `unescape` to convert HTML entities to characters.
- *
- * @private
- * @param {String} match The matched character to unescape.
- * @returns {String} Returns the unescaped character.
- */
- function unescapeHtmlChar(match) {
- return htmlUnescapes[match];
- }
- /*--------------------------------------------------------------------------*/
- /**
- * Checks if `value` is an `arguments` object.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is an `arguments` object, else `false`.
- * @example
- *
- * (function() { return _.isArguments(arguments); })(1, 2, 3);
- * // => true
- *
- * _.isArguments([1, 2, 3]);
- * // => false
- */
- function isArguments(value) {
- return toString.call(value) == argsClass;
- }
- // fallback for browsers that can't detect `arguments` objects by [[Class]]
- if (!isArguments(arguments)) {
- isArguments = function(value) {
- return value ? hasOwnProperty.call(value, 'callee') : false;
- };
- }
- /**
- * Iterates over `object`'s own and inherited enumerable properties, executing
- * the `callback` for each property. The `callback` is bound to `thisArg` and
- * invoked with three arguments; (value, key, object). Callbacks may exit iteration
- * early by explicitly returning `false`.
- *
- * @static
- * @memberOf _
- * @type Function
- * @category Objects
- * @param {Object} object The object to iterate over.
- * @param {Function} [callback=identity] The function called per iteration.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Object} Returns `object`.
- * @example
- *
- * function Dog(name) {
- * this.name = name;
- * }
- *
- * Dog.prototype.bark = function() {
- * alert('Woof, woof!');
- * };
- *
- * _.forIn(new Dog('Dagny'), function(value, key) {
- * alert(key);
- * });
- * // => alerts 'name' and 'bark' (order is not guaranteed)
- */
- var forIn = function (collection, callback) {
- var index, iterable = collection, result = iterable;
- if (!iterable) return result;
- if (!objectTypes[typeof iterable]) return result;
- callback || (callback = identity);
-
- for (index in iterable) {
- if (callback(iterable[index], index, collection) === indicatorObject) return result;
- }
- return result
- };
- /**
- * Iterates over an object's own enumerable properties, executing the `callback`
- * for each property. The `callback` is bound to `thisArg` and invoked with three
- * arguments; (value, key, object). Callbacks may exit iteration early by explicitly
- * returning `false`.
- *
- * @static
- * @memberOf _
- * @type Function
- * @category Objects
- * @param {Object} object The object to iterate over.
- * @param {Function} [callback=identity] The function called per iteration.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Object} Returns `object`.
- * @example
- *
- * _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) {
- * alert(key);
- * });
- * // => alerts '0', '1', and 'length' (order is not guaranteed)
- */
- var forOwn = function (collection, callback) {
- var index, iterable = collection, result = iterable;
- if (!iterable) return result;
- if (!objectTypes[typeof iterable]) return result;
- callback || (callback = identity);
-
- for (index in iterable) {
- if (hasOwnProperty.call(iterable, index)) {
- if (callback(iterable[index], index, collection) === indicatorObject) return result;
- }
- }
- return result
- };
- /**
- * Checks if `value` is an array.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is an array, else `false`.
- * @example
- *
- * (function() { return _.isArray(arguments); })();
- * // => false
- *
- * _.isArray([1, 2, 3]);
- * // => true
- */
- var isArray = nativeIsArray || function(value) {
- // `instanceof` may cause a memory leak in IE 7 if `value` is a host object
- // http://ajaxian.com/archives/working-aroung-the-instanceof-memory-leak
- return (argsAreObjects && value instanceof Array) || toString.call(value) == arrayClass;
- };
- /**
- * Creates an array composed of the own enumerable property names of `object`.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Object} object The object to inspect.
- * @returns {Array} Returns a new array of property names.
- * @example
- *
- * _.keys({ 'one': 1, 'two': 2, 'three': 3 });
- * // => ['one', 'two', 'three'] (order is not guaranteed)
- */
- var keys = !nativeKeys ? shimKeys : function(object) {
- if (!isObject(object)) {
- return [];
- }
- return nativeKeys(object);
- };
- /**
- * A fallback implementation of `isPlainObject` that checks if a given `value`
- * is an object created by the `Object` constructor, assuming objects created
- * by the `Object` constructor have no inherited enumerable properties and that
- * there are no `Object.prototype` extensions.
- *
- * @private
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if `value` is a plain object, else `false`.
- */
- function shimIsPlainObject(value) {
- // avoid non-objects and false positives for `arguments` objects
- var result = false;
- if (!(value && typeof value == 'object') || isArguments(value)) {
- return result;
- }
- // check that the constructor is `Object` (i.e. `Object instanceof Object`)
- var ctor = value.constructor;
- if ((!isFunction(ctor)) || ctor instanceof ctor) {
- // In most environments an object's own properties are iterated before
- // its inherited properties. If the last iterated property is an object's
- // own property then there are no inherited enumerable properties.
- forIn(value, function(value, key) {
- result = key;
- });
- return result === false || hasOwnProperty.call(value, result);
- }
- return result;
- }
- /**
- * A fallback implementation of `Object.keys` that produces an array of the
- * given object's own enumerable property names.
- *
- * @private
- * @param {Object} object The object to inspect.
- * @returns {Array} Returns a new array of property names.
- */
- function shimKeys(object) {
- var result = [];
- forOwn(object, function(value, key) {
- result.push(key);
- });
- return result;
- }
- /**
- * Used to convert characters to HTML entities:
- *
- * Though the `>` character is escaped for symmetry, characters like `>` and `/`
- * don't require escaping in HTML and have no special meaning unless they're part
- * of a tag or an unquoted attribute value.
- * http://mathiasbynens.be/notes/ambiguous-ampersands (under "semi-related fun fact")
- */
- var htmlEscapes = {
- '&': '&',
- '<': '<',
- '>': '>',
- '"': '"',
- "'": '''
- };
- /** Used to convert HTML entities to characters */
- var htmlUnescapes = invert(htmlEscapes);
- /*--------------------------------------------------------------------------*/
- /**
- * Assigns own enumerable properties of source object(s) to the destination
- * object. Subsequent sources will overwrite propery assignments of previous
- * sources. If a `callback` function is passed, it will be executed to produce
- * the assigned values. The `callback` is bound to `thisArg` and invoked with
- * two arguments; (objectValue, sourceValue).
- *
- * @static
- * @memberOf _
- * @type Function
- * @alias extend
- * @category Objects
- * @param {Object} object The destination object.
- * @param {Object} [source1, source2, ...] The source objects.
- * @param {Function} [callback] The function to customize assigning values.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Object} Returns the destination object.
- * @example
- *
- * _.assign({ 'name': 'moe' }, { 'age': 40 });
- * // => { 'name': 'moe', 'age': 40 }
- *
- * var defaults = _.partialRight(_.assign, function(a, b) {
- * return typeof a == 'undefined' ? b : a;
- * });
- *
- * var food = { 'name': 'apple' };
- * defaults(food, { 'name': 'banana', 'type': 'fruit' });
- * // => { 'name': 'apple', 'type': 'fruit' }
- */
- function assign(object) {
- if (!object) {
- return object;
- }
- for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) {
- var iterable = arguments[argsIndex];
- if (iterable) {
- for (var key in iterable) {
- object[key] = iterable[key];
- }
- }
- }
- return object;
- }
- /**
- * Creates a clone of `value`. If `deep` is `true`, nested objects will also
- * be cloned, otherwise they will be assigned by reference. If a `callback`
- * function is passed, it will be executed to produce the cloned values. If
- * `callback` returns `undefined`, cloning will be handled by the method instead.
- * The `callback` is bound to `thisArg` and invoked with one argument; (value).
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to clone.
- * @param {Boolean} [deep=false] A flag to indicate a deep clone.
- * @param {Function} [callback] The function to customize cloning values.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @param- {Array} [stackA=[]] Internally used to track traversed source objects.
- * @param- {Array} [stackB=[]] Internally used to associate clones with source counterparts.
- * @returns {Mixed} Returns the cloned `value`.
- * @example
- *
- * var stooges = [
- * { 'name': 'moe', 'age': 40 },
- * { 'name': 'larry', 'age': 50 }
- * ];
- *
- * var shallow = _.clone(stooges);
- * shallow[0] === stooges[0];
- * // => true
- *
- * var deep = _.clone(stooges, true);
- * deep[0] === stooges[0];
- * // => false
- *
- * _.mixin({
- * 'clone': _.partialRight(_.clone, function(value) {
- * return _.isElement(value) ? value.cloneNode(false) : undefined;
- * })
- * });
- *
- * var clone = _.clone(document.body);
- * clone.childNodes.length;
- * // => 0
- */
- function clone(value) {
- return isObject(value)
- ? (isArray(value) ? slice(value) : assign({}, value))
- : value
- }
- /**
- * Assigns own enumerable properties of source object(s) to the destination
- * object for all destination properties that resolve to `undefined`. Once a
- * property is set, additional defaults of the same property will be ignored.
- *
- * @static
- * @memberOf _
- * @type Function
- * @category Objects
- * @param {Object} object The destination object.
- * @param {Object} [source1, source2, ...] The source objects.
- * @param- {Object} [guard] Internally used to allow working with `_.reduce`
- * without using its callback's `key` and `object` arguments as sources.
- * @returns {Object} Returns the destination object.
- * @example
- *
- * var food = { 'name': 'apple' };
- * _.defaults(food, { 'name': 'banana', 'type': 'fruit' });
- * // => { 'name': 'apple', 'type': 'fruit' }
- */
- function defaults(object) {
- if (!object) {
- return object;
- }
- for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) {
- var iterable = arguments[argsIndex];
- if (iterable) {
- for (var key in iterable) {
- if (object[key] == null) {
- object[key] = iterable[key];
- }
- }
- }
- }
- return object;
- }
- /**
- * Creates a sorted array of all enumerable properties, own and inherited,
- * of `object` that have function values.
- *
- * @static
- * @memberOf _
- * @alias methods
- * @category Objects
- * @param {Object} object The object to inspect.
- * @returns {Array} Returns a new array of property names that have function values.
- * @example
- *
- * _.functions(_);
- * // => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...]
- */
- function functions(object) {
- var result = [];
- forIn(object, function(value, key) {
- if (isFunction(value)) {
- result.push(key);
- }
- });
- return result.sort();
- }
- /**
- * Checks if the specified object `property` exists and is a direct property,
- * instead of an inherited property.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Object} object The object to check.
- * @param {String} property The property to check for.
- * @returns {Boolean} Returns `true` if key is a direct property, else `false`.
- * @example
- *
- * _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b');
- * // => true
- */
- function has(object, property) {
- return object ? hasOwnProperty.call(object, property) : false;
- }
- /**
- * Creates an object composed of the inverted keys and values of the given `object`.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Object} object The object to invert.
- * @returns {Object} Returns the created inverted object.
- * @example
- *
- * _.invert({ 'first': 'moe', 'second': 'larry' });
- * // => { 'moe': 'first', 'larry': 'second' } (order is not guaranteed)
- */
- function invert(object) {
- var index = -1,
- props = keys(object),
- length = props.length,
- result = {};
- while (++index < length) {
- var key = props[index];
- result[object[key]] = key;
- }
- return result;
- }
- /**
- * Checks if `value` is a boolean value.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is a boolean value, else `false`.
- * @example
- *
- * _.isBoolean(null);
- * // => false
- */
- function isBoolean(value) {
- return value === true || value === false || toString.call(value) == boolClass;
- }
- /**
- * Checks if `value` is a date.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is a date, else `false`.
- * @example
- *
- * _.isDate(new Date);
- * // => true
- */
- function isDate(value) {
- return value instanceof Date || toString.call(value) == dateClass;
- }
- /**
- * Checks if `value` is a DOM element.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is a DOM element, else `false`.
- * @example
- *
- * _.isElement(document.body);
- * // => true
- */
- function isElement(value) {
- return value ? value.nodeType === 1 : false;
- }
- /**
- * Checks if `value` is empty. Arrays, strings, or `arguments` objects with a
- * length of `0` and objects with no own enumerable properties are considered
- * "empty".
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Array|Object|String} value The value to inspect.
- * @returns {Boolean} Returns `true`, if the `value` is empty, else `false`.
- * @example
- *
- * _.isEmpty([1, 2, 3]);
- * // => false
- *
- * _.isEmpty({});
- * // => true
- *
- * _.isEmpty('');
- * // => true
- */
- function isEmpty(value) {
- if (!value) {
- return true;
- }
- if (isArray(value) || isString(value)) {
- return !value.length;
- }
- for (var key in value) {
- if (hasOwnProperty.call(value, key)) {
- return false;
- }
- }
- return true;
- }
- /**
- * Performs a deep comparison between two values to determine if they are
- * equivalent to each other. If `callback` is passed, it will be executed to
- * compare values. If `callback` returns `undefined`, comparisons will be handled
- * by the method instead. The `callback` is bound to `thisArg` and invoked with
- * two arguments; (a, b).
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} a The value to compare.
- * @param {Mixed} b The other value to compare.
- * @param {Function} [callback] The function to customize comparing values.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @param- {Object} [stackA=[]] Internally used track traversed `a` objects.
- * @param- {Object} [stackB=[]] Internally used track traversed `b` objects.
- * @returns {Boolean} Returns `true`, if the values are equvalent, else `false`.
- * @example
- *
- * var moe = { 'name': 'moe', 'age': 40 };
- * var copy = { 'name': 'moe', 'age': 40 };
- *
- * moe == copy;
- * // => false
- *
- * _.isEqual(moe, copy);
- * // => true
- *
- * var words = ['hello', 'goodbye'];
- * var otherWords = ['hi', 'goodbye'];
- *
- * _.isEqual(words, otherWords, function(a, b) {
- * var reGreet = /^(?:hello|hi)$/i,
- * aGreet = _.isString(a) && reGreet.test(a),
- * bGreet = _.isString(b) && reGreet.test(b);
- *
- * return (aGreet || bGreet) ? (aGreet == bGreet) : undefined;
- * });
- * // => true
- */
- function isEqual(a, b, stackA, stackB) {
- if (a === b) {
- return a !== 0 || (1 / a == 1 / b);
- }
- var type = typeof a,
- otherType = typeof b;
- if (a === a &&
- (!a || (type != 'function' && type != 'object')) &&
- (!b || (otherType != 'function' && otherType != 'object'))) {
- return false;
- }
- if (a == null || b == null) {
- return a === b;
- }
- var className = toString.call(a),
- otherClass = toString.call(b);
- if (className != otherClass) {
- return false;
- }
- switch (className) {
- case boolClass:
- case dateClass:
- return +a == +b;
- case numberClass:
- return a != +a
- ? b != +b
- : (a == 0 ? (1 / a == 1 / b) : a == +b);
- case regexpClass:
- case stringClass:
- return a == b + '';
- }
- var isArr = className == arrayClass;
- if (!isArr) {
- if (a.__wrapped__ || b.__wrapped__) {
- return isEqual(a.__wrapped__ || a, b.__wrapped__ || b, stackA, stackB);
- }
- if (className != objectClass) {
- return false;
- }
- var ctorA = a.constructor,
- ctorB = b.constructor;
- if (ctorA != ctorB && !(
- isFunction(ctorA) && ctorA instanceof ctorA &&
- isFunction(ctorB) && ctorB instanceof ctorB
- )) {
- return false;
- }
- }
- stackA || (stackA = []);
- stackB || (stackB = []);
- var length = stackA.length;
- while (length--) {
- if (stackA[length] == a) {
- return stackB[length] == b;
- }
- }
- var result = true,
- size = 0;
- stackA.push(a);
- stackB.push(b);
- if (isArr) {
- size = b.length;
- result = size == a.length;
- if (result) {
- while (size--) {
- if (!(result = isEqual(a[size], b[size], stackA, stackB))) {
- break;
- }
- }
- }
- return result;
- }
- forIn(b, function(value, key, b) {
- if (hasOwnProperty.call(b, key)) {
- size++;
- return !(result = hasOwnProperty.call(a, key) && isEqual(a[key], value, stackA, stackB)) && indicatorObject;
- }
- });
- if (result) {
- forIn(a, function(value, key, a) {
- if (hasOwnProperty.call(a, key)) {
- return !(result = --size > -1) && indicatorObject;
- }
- });
- }
- return result;
- }
- /**
- * Checks if `value` is, or can be coerced to, a finite number.
- *
- * Note: This is not the same as native `isFinite`, which will return true for
- * booleans and empty strings. See http://es5.github.com/#x15.1.2.5.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is finite, else `false`.
- * @example
- *
- * _.isFinite(-101);
- * // => true
- *
- * _.isFinite('10');
- * // => true
- *
- * _.isFinite(true);
- * // => false
- *
- * _.isFinite('');
- * // => false
- *
- * _.isFinite(Infinity);
- * // => false
- */
- function isFinite(value) {
- return nativeIsFinite(value) && !nativeIsNaN(parseFloat(value));
- }
- /**
- * Checks if `value` is a function.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is a function, else `false`.
- * @example
- *
- * _.isFunction(_);
- * // => true
- */
- function isFunction(value) {
- return typeof value == 'function';
- }
- // fallback for older versions of Chrome and Safari
- if (isFunction(/x/)) {
- isFunction = function(value) {
- return value instanceof Function || toString.call(value) == funcClass;
- };
- }
- /**
- * Checks if `value` is the language type of Object.
- * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is an object, else `false`.
- * @example
- *
- * _.isObject({});
- * // => true
- *
- * _.isObject([1, 2, 3]);
- * // => true
- *
- * _.isObject(1);
- * // => false
- */
- function isObject(value) {
- // check if the value is the ECMAScript language type of Object
- // http://es5.github.com/#x8
- // and avoid a V8 bug
- // http://code.google.com/p/v8/issues/detail?id=2291
- return value ? objectTypes[typeof value] : false;
- }
- /**
- * Checks if `value` is `NaN`.
- *
- * Note: This is not the same as native `isNaN`, which will return `true` for
- * `undefined` and other values. See http://es5.github.com/#x15.1.2.4.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is `NaN`, else `false`.
- * @example
- *
- * _.isNaN(NaN);
- * // => true
- *
- * _.isNaN(new Number(NaN));
- * // => true
- *
- * isNaN(undefined);
- * // => true
- *
- * _.isNaN(undefined);
- * // => false
- */
- function isNaN(value) {
- // `NaN` as a primitive is the only value that is not equal to itself
- // (perform the [[Class]] check first to avoid errors with some host objects in IE)
- return isNumber(value) && value != +value
- }
- /**
- * Checks if `value` is `null`.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is `null`, else `false`.
- * @example
- *
- * _.isNull(null);
- * // => true
- *
- * _.isNull(undefined);
- * // => false
- */
- function isNull(value) {
- return value === null;
- }
- /**
- * Checks if `value` is a number.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is a number, else `false`.
- * @example
- *
- * _.isNumber(8.4 * 5);
- * // => true
- */
- function isNumber(value) {
- return typeof value == 'number' || toString.call(value) == numberClass;
- }
- /**
- * Checks if `value` is a regular expression.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is a regular expression, else `false`.
- * @example
- *
- * _.isRegExp(/moe/);
- * // => true
- */
- function isRegExp(value) {
- return value instanceof RegExp || toString.call(value) == regexpClass;
- }
- /**
- * Checks if `value` is a string.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is a string, else `false`.
- * @example
- *
- * _.isString('moe');
- * // => true
- */
- function isString(value) {
- return typeof value == 'string' || toString.call(value) == stringClass;
- }
- /**
- * Checks if `value` is `undefined`.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Mixed} value The value to check.
- * @returns {Boolean} Returns `true`, if the `value` is `undefined`, else `false`.
- * @example
- *
- * _.isUndefined(void 0);
- * // => true
- */
- function isUndefined(value) {
- return typeof value == 'undefined';
- }
- /**
- * Creates a shallow clone of `object` excluding the specified properties.
- * Property names may be specified as individual arguments or as arrays of
- * property names. If a `callback` function is passed, it will be executed
- * for each property in the `object`, omitting the properties `callback`
- * returns truthy for. The `callback` is bound to `thisArg` and invoked
- * with three arguments; (value, key, object).
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Object} object The source object.
- * @param {Function|String} callback|[prop1, prop2, ...] The properties to omit
- * or the function called per iteration.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Object} Returns an object without the omitted properties.
- * @example
- *
- * _.omit({ 'name': 'moe', 'age': 40 }, 'age');
- * // => { 'name': 'moe' }
- *
- * _.omit({ 'name': 'moe', 'age': 40 }, function(value) {
- * return typeof value == 'number';
- * });
- * // => { 'name': 'moe' }
- */
- function omit(object) {
- var props = concat.apply(arrayRef, arguments),
- result = {};
- forIn(object, function(value, key) {
- if (indexOf(props, key, 1) < 0) {
- result[key] = value;
- }
- });
- return result;
- }
- /**
- * Creates a two dimensional array of the given object's key-value pairs,
- * i.e. `[[key1, value1], [key2, value2]]`.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Object} object The object to inspect.
- * @returns {Array} Returns new array of key-value pairs.
- * @example
- *
- * _.pairs({ 'moe': 30, 'larry': 40 });
- * // => [['moe', 30], ['larry', 40]] (order is not guaranteed)
- */
- function pairs(object) {
- var index = -1,
- props = keys(object),
- length = props.length,
- result = Array(length);
- while (++index < length) {
- var key = props[index];
- result[index] = [key, object[key]];
- }
- return result;
- }
- /**
- * Creates a shallow clone of `object` composed of the specified properties.
- * Property names may be specified as individual arguments or as arrays of property
- * names. If `callback` is passed, it will be executed for each property in the
- * `object`, picking the properties `callback` returns truthy for. The `callback`
- * is bound to `thisArg` and invoked with three arguments; (value, key, object).
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Object} object The source object.
- * @param {Array|Function|String} callback|[prop1, prop2, ...] The function called
- * per iteration or properties to pick, either as individual arguments or arrays.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Object} Returns an object composed of the picked properties.
- * @example
- *
- * _.pick({ 'name': 'moe', '_userid': 'moe1' }, 'name');
- * // => { 'name': 'moe' }
- *
- * _.pick({ 'name': 'moe', '_userid': 'moe1' }, function(value, key) {
- * return key.charAt(0) != '_';
- * });
- * // => { 'name': 'moe' }
- */
- function pick(object) {
- var index = 0,
- props = concat.apply(arrayRef, arguments),
- length = props.length,
- result = {};
- while (++index < length) {
- var prop = props[index];
- if (prop in object) {
- result[prop] = object[prop];
- }
- }
- return result;
- }
- /**
- * Creates an array composed of the own enumerable property values of `object`.
- *
- * @static
- * @memberOf _
- * @category Objects
- * @param {Object} object The object to inspect.
- * @returns {Array} Returns a new array of property values.
- * @example
- *
- * _.values({ 'one': 1, 'two': 2, 'three': 3 });
- * // => [1, 2, 3]
- */
- function values(object) {
- var index = -1,
- props = keys(object),
- length = props.length,
- result = Array(length);
- while (++index < length) {
- result[index] = object[props[index]];
- }
- return result;
- }
- /*--------------------------------------------------------------------------*/
- /**
- * Checks if a given `target` element is present in a `collection` using strict
- * equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used
- * as the offset from the end of the collection.
- *
- * @static
- * @memberOf _
- * @alias include
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Mixed} target The value to check for.
- * @param {Number} [fromIndex=0] The index to search from.
- * @returns {Boolean} Returns `true` if the `target` element is found, else `false`.
- * @example
- *
- * _.contains([1, 2, 3], 1);
- * // => true
- *
- * _.contains([1, 2, 3], 1, 2);
- * // => false
- *
- * _.contains({ 'name': 'moe', 'age': 40 }, 'moe');
- * // => true
- *
- * _.contains('curly', 'ur');
- * // => true
- */
- function contains(collection, target) {
- var length = collection ? collection.length : 0,
- result = false;
- if (typeof length == 'number') {
- result = indexOf(collection, target) > -1;
- } else {
- each(collection, function(value) {
- return (result = value === target) && indicatorObject;
- });
- }
- return result;
- }
- /**
- * Creates an object composed of keys returned from running each element of the
- * `collection` through the given `callback`. The corresponding value of each key
- * is the number of times the key was returned by the `callback`. The `callback`
- * is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Object} Returns the composed aggregate object.
- * @example
- *
- * _.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); });
- * // => { '4': 1, '6': 2 }
- *
- * _.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math);
- * // => { '4': 1, '6': 2 }
- *
- * _.countBy(['one', 'two', 'three'], 'length');
- * // => { '3': 2, '5': 1 }
- */
- function countBy(collection, callback, thisArg) {
- var result = {};
- callback = createCallback(callback, thisArg);
- forEach(collection, function(value, key, collection) {
- key = callback(value, key, collection) + '';
- (hasOwnProperty.call(result, key) ? result[key]++ : result[key] = 1);
- });
- return result;
- }
- /**
- * Checks if the `callback` returns a truthy value for **all** elements of a
- * `collection`. The `callback` is bound to `thisArg` and invoked with three
- * arguments; (value, index|key, collection).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @alias all
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Boolean} Returns `true` if all elements pass the callback check,
- * else `false`.
- * @example
- *
- * _.every([true, 1, null, 'yes'], Boolean);
- * // => false
- *
- * var stooges = [
- * { 'name': 'moe', 'age': 40 },
- * { 'name': 'larry', 'age': 50 }
- * ];
- *
- * // using "_.pluck" callback shorthand
- * _.every(stooges, 'age');
- * // => true
- *
- * // using "_.where" callback shorthand
- * _.every(stooges, { 'age': 50 });
- * // => false
- */
- function every(collection, callback, thisArg) {
- var result = true;
- callback = createCallback(callback, thisArg);
- if (isArray(collection)) {
- var index = -1,
- length = collection.length;
- while (++index < length) {
- if (!(result = !!callback(collection[index], index, collection))) {
- break;
- }
- }
- } else {
- each(collection, function(value, index, collection) {
- return !(result = !!callback(value, index, collection)) && indicatorObject;
- });
- }
- return result;
- }
- /**
- * Examines each element in a `collection`, returning an array of all elements
- * the `callback` returns truthy for. The `callback` is bound to `thisArg` and
- * invoked with three arguments; (value, index|key, collection).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @alias select
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Array} Returns a new array of elements that passed the callback check.
- * @example
- *
- * var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; });
- * // => [2, 4, 6]
- *
- * var food = [
- * { 'name': 'apple', 'organic': false, 'type': 'fruit' },
- * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' }
- * ];
- *
- * // using "_.pluck" callback shorthand
- * _.filter(food, 'organic');
- * // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }]
- *
- * // using "_.where" callback shorthand
- * _.filter(food, { 'type': 'fruit' });
- * // => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }]
- */
- function filter(collection, callback, thisArg) {
- var result = [];
- callback = createCallback(callback, thisArg);
- if (isArray(collection)) {
- var index = -1,
- length = collection.length;
- while (++index < length) {
- var value = collection[index];
- if (callback(value, index, collection)) {
- result.push(value);
- }
- }
- } else {
- each(collection, function(value, index, collection) {
- if (callback(value, index, collection)) {
- result.push(value);
- }
- });
- }
- return result;
- }
- /**
- * Examines each element in a `collection`, returning the first that the `callback`
- * returns truthy for. The `callback` is bound to `thisArg` and invoked with three
- * arguments; (value, index|key, collection).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @alias detect
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Mixed} Returns the element that passed the callback check,
- * else `undefined`.
- * @example
- *
- * var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; });
- * // => 2
- *
- * var food = [
- * { 'name': 'apple', 'organic': false, 'type': 'fruit' },
- * { 'name': 'banana', 'organic': true, 'type': 'fruit' },
- * { 'name': 'beet', 'organic': false, 'type': 'vegetable' },
- * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' }
- * ];
- *
- * // using "_.where" callback shorthand
- * var veggie = _.find(food, { 'type': 'vegetable' });
- * // => { 'name': 'beet', 'organic': false, 'type': 'vegetable' }
- *
- * // using "_.pluck" callback shorthand
- * var healthy = _.find(food, 'organic');
- * // => { 'name': 'banana', 'organic': true, 'type': 'fruit' }
- */
- function find(collection, callback, thisArg) {
- var result;
- callback = createCallback(callback, thisArg);
- forEach(collection, function(value, index, collection) {
- if (callback(value, index, collection)) {
- result = value;
- return indicatorObject;
- }
- });
- return result;
- }
- function findWhere(object, properties) {
- return where(object, properties, true);
- }
- /**
- * Iterates over a `collection`, executing the `callback` for each element in
- * the `collection`. The `callback` is bound to `thisArg` and invoked with three
- * arguments; (value, index|key, collection). Callbacks may exit iteration early
- * by explicitly returning `false`.
- *
- * @static
- * @memberOf _
- * @alias each
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function} [callback=identity] The function called per iteration.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Array|Object|String} Returns `collection`.
- * @example
- *
- * _([1, 2, 3]).forEach(alert).join(',');
- * // => alerts each number and returns '1,2,3'
- *
- * _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert);
- * // => alerts each number value (order is not guaranteed)
- */
- function forEach(collection, callback, thisArg) {
- if (callback && typeof thisArg == 'undefined' && isArray(collection)) {
- var index = -1,
- length = collection.length;
- while (++index < length) {
- if (callback(collection[index], index, collection) === indicatorObject) {
- break;
- }
- }
- } else {
- each(collection, callback, thisArg);
- };
- }
- /**
- * Creates an object composed of keys returned from running each element of the
- * `collection` through the `callback`. The corresponding value of each key is
- * an array of elements passed to `callback` that returned the key. The `callback`
- * is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`
- *
- * @static
- * @memberOf _
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Object} Returns the composed aggregate object.
- * @example
- *
- * _.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); });
- * // => { '4': [4.2], '6': [6.1, 6.4] }
- *
- * _.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math);
- * // => { '4': [4.2], '6': [6.1, 6.4] }
- *
- * // using "_.pluck" callback shorthand
- * _.groupBy(['one', 'two', 'three'], 'length');
- * // => { '3': ['one', 'two'], '5': ['three'] }
- */
- function groupBy(collection, callback, thisArg) {
- var result = {};
- callback = createCallback(callback, thisArg);
- forEach(collection, function(value, key, collection) {
- key = callback(value, key, collection) + '';
- (hasOwnProperty.call(result, key) ? result[key] : result[key] = []).push(value);
- });
- return result;
- }
- /**
- * Invokes the method named by `methodName` on each element in the `collection`,
- * returning an array of the results of each invoked method. Additional arguments
- * will be passed to each invoked method. If `methodName` is a function, it will
- * be invoked for, and `this` bound to, each element in the `collection`.
- *
- * @static
- * @memberOf _
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|String} methodName The name of the method to invoke or
- * the function invoked per iteration.
- * @param {Mixed} [arg1, arg2, ...] Arguments to invoke the method with.
- * @returns {Array} Returns a new array of the results of each invoked method.
- * @example
- *
- * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
- * // => [[1, 5, 7], [1, 2, 3]]
- *
- * _.invoke([123, 456], String.prototype.split, '');
- * // => [['1', '2', '3'], ['4', '5', '6']]
- */
- function invoke(collection, methodName) {
- var args = slice(arguments, 2),
- index = -1,
- isFunc = typeof methodName == 'function',
- length = collection ? collection.length : 0,
- result = Array(typeof length == 'number' ? length : 0);
- forEach(collection, function(value) {
- result[++index] = (isFunc ? methodName : value[methodName]).apply(value, args);
- });
- return result;
- }
- /**
- * Creates an array of values by running each element in the `collection`
- * through the `callback`. The `callback` is bound to `thisArg` and invoked with
- * three arguments; (value, index|key, collection).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @alias collect
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Array} Returns a new array of the results of each `callback` execution.
- * @example
- *
- * _.map([1, 2, 3], function(num) { return num * 3; });
- * // => [3, 6, 9]
- *
- * _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; });
- * // => [3, 6, 9] (order is not guaranteed)
- *
- * var stooges = [
- * { 'name': 'moe', 'age': 40 },
- * { 'name': 'larry', 'age': 50 }
- * ];
- *
- * // using "_.pluck" callback shorthand
- * _.map(stooges, 'name');
- * // => ['moe', 'larry']
- */
- function map(collection, callback, thisArg) {
- var index = -1,
- length = collection ? collection.length : 0,
- result = Array(typeof length == 'number' ? length : 0);
- callback = createCallback(callback, thisArg);
- if (isArray(collection)) {
- while (++index < length) {
- result[index] = callback(collection[index], index, collection);
- }
- } else {
- each(collection, function(value, key, collection) {
- result[++index] = callback(value, key, collection);
- });
- }
- return result;
- }
- /**
- * Retrieves the maximum value of an `array`. If `callback` is passed,
- * it will be executed for each value in the `array` to generate the
- * criterion by which the value is ranked. The `callback` is bound to
- * `thisArg` and invoked with three arguments; (value, index, collection).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Mixed} Returns the maximum value.
- * @example
- *
- * _.max([4, 2, 8, 6]);
- * // => 8
- *
- * var stooges = [
- * { 'name': 'moe', 'age': 40 },
- * { 'name': 'larry', 'age': 50 }
- * ];
- *
- * _.max(stooges, function(stooge) { return stooge.age; });
- * // => { 'name': 'larry', 'age': 50 };
- *
- * // using "_.pluck" callback shorthand
- * _.max(stooges, 'age');
- * // => { 'name': 'larry', 'age': 50 };
- */
- function max(collection, callback, thisArg) {
- var computed = -Infinity,
- result = computed;
- if (!callback && isArray(collection)) {
- var index = -1,
- length = collection.length;
- while (++index < length) {
- var value = collection[index];
- if (value > result) {
- result = value;
- }
- }
- } else {
- callback = createCallback(callback, thisArg);
- each(collection, function(value, index, collection) {
- var current = callback(value, index, collection);
- if (current > computed) {
- computed = current;
- result = value;
- }
- });
- }
- return result;
- }
- /**
- * Retrieves the minimum value of an `array`. If `callback` is passed,
- * it will be executed for each value in the `array` to generate the
- * criterion by which the value is ranked. The `callback` is bound to `thisArg`
- * and invoked with three arguments; (value, index, collection).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Mixed} Returns the minimum value.
- * @example
- *
- * _.min([4, 2, 8, 6]);
- * // => 2
- *
- * var stooges = [
- * { 'name': 'moe', 'age': 40 },
- * { 'name': 'larry', 'age': 50 }
- * ];
- *
- * _.min(stooges, function(stooge) { return stooge.age; });
- * // => { 'name': 'moe', 'age': 40 };
- *
- * // using "_.pluck" callback shorthand
- * _.min(stooges, 'age');
- * // => { 'name': 'moe', 'age': 40 };
- */
- function min(collection, callback, thisArg) {
- var computed = Infinity,
- result = computed;
- if (!callback && isArray(collection)) {
- var index = -1,
- length = collection.length;
- while (++index < length) {
- var value = collection[index];
- if (value < result) {
- result = value;
- }
- }
- } else {
- callback = createCallback(callback, thisArg);
- each(collection, function(value, index, collection) {
- var current = callback(value, index, collection);
- if (current < computed) {
- computed = current;
- result = value;
- }
- });
- }
- return result;
- }
- /**
- * Retrieves the value of a specified property from all elements in the `collection`.
- *
- * @static
- * @memberOf _
- * @type Function
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {String} property The property to pluck.
- * @returns {Array} Returns a new array of property values.
- * @example
- *
- * var stooges = [
- * { 'name': 'moe', 'age': 40 },
- * { 'name': 'larry', 'age': 50 }
- * ];
- *
- * _.pluck(stooges, 'name');
- * // => ['moe', 'larry']
- */
- var pluck = map;
- /**
- * Reduces a `collection` to a value that is the accumulated result of running
- * each element in the `collection` through the `callback`, where each successive
- * `callback` execution consumes the return value of the previous execution.
- * If `accumulator` is not passed, the first element of the `collection` will be
- * used as the initial `accumulator` value. The `callback` is bound to `thisArg`
- * and invoked with four arguments; (accumulator, value, index|key, collection).
- *
- * @static
- * @memberOf _
- * @alias foldl, inject
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function} [callback=identity] The function called per iteration.
- * @param {Mixed} [accumulator] Initial value of the accumulator.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Mixed} Returns the accumulated value.
- * @example
- *
- * var sum = _.reduce([1, 2, 3], function(sum, num) {
- * return sum + num;
- * });
- * // => 6
- *
- * var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, num, key) {
- * result[key] = num * 3;
- * return result;
- * }, {});
- * // => { 'a': 3, 'b': 6, 'c': 9 }
- */
- function reduce(collection, callback, accumulator, thisArg) {
- var noaccum = arguments.length < 3;
- callback = createCallback(callback, thisArg, 4);
- if (isArray(collection)) {
- var index = -1,
- length = collection.length;
- if (noaccum) {
- accumulator = collection[++index];
- }
- while (++index < length) {
- accumulator = callback(accumulator, collection[index], index, collection);
- }
- } else {
- each(collection, function(value, index, collection) {
- accumulator = noaccum
- ? (noaccum = false, value)
- : callback(accumulator, value, index, collection)
- });
- }
- return accumulator;
- }
- /**
- * This method is similar to `_.reduce`, except that it iterates over a
- * `collection` from right to left.
- *
- * @static
- * @memberOf _
- * @alias foldr
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function} [callback=identity] The function called per iteration.
- * @param {Mixed} [accumulator] Initial value of the accumulator.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Mixed} Returns the accumulated value.
- * @example
- *
- * var list = [[0, 1], [2, 3], [4, 5]];
- * var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []);
- * // => [4, 5, 2, 3, 0, 1]
- */
- function reduceRight(collection, callback, accumulator, thisArg) {
- var iterable = collection,
- length = collection ? collection.length : 0,
- noaccum = arguments.length < 3;
- if (typeof length != 'number') {
- var props = keys(collection);
- length = props.length;
- }
- callback = createCallback(callback, thisArg, 4);
- forEach(collection, function(value, index, collection) {
- index = props ? props[--length] : --length;
- accumulator = noaccum
- ? (noaccum = false, iterable[index])
- : callback(accumulator, iterable[index], index, collection);
- });
- return accumulator;
- }
- /**
- * The opposite of `_.filter`, this method returns the elements of a
- * `collection` that `callback` does **not** return truthy for.
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Array} Returns a new array of elements that did **not** pass the
- * callback check.
- * @example
- *
- * var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; });
- * // => [1, 3, 5]
- *
- * var food = [
- * { 'name': 'apple', 'organic': false, 'type': 'fruit' },
- * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' }
- * ];
- *
- * // using "_.pluck" callback shorthand
- * _.reject(food, 'organic');
- * // => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }]
- *
- * // using "_.where" callback shorthand
- * _.reject(food, { 'type': 'fruit' });
- * // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }]
- */
- function reject(collection, callback, thisArg) {
- callback = createCallback(callback, thisArg);
- return filter(collection, function(value, index, collection) {
- return !callback(value, index, collection);
- });
- }
- /**
- * Creates an array of shuffled `array` values, using a version of the
- * Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle.
- *
- * @static
- * @memberOf _
- * @category Collections
- * @param {Array|Object|String} collection The collection to shuffle.
- * @returns {Array} Returns a new shuffled collection.
- * @example
- *
- * _.shuffle([1, 2, 3, 4, 5, 6]);
- * // => [4, 1, 6, 3, 5, 2]
- */
- function shuffle(collection) {
- var index = -1,
- length = collection ? collection.length : 0,
- result = Array(typeof length == 'number' ? length : 0);
- forEach(collection, function(value) {
- var rand = floor(nativeRandom() * (++index + 1));
- result[index] = result[rand];
- result[rand] = value;
- });
- return result;
- }
- /**
- * Gets the size of the `collection` by returning `collection.length` for arrays
- * and array-like objects or the number of own enumerable properties for objects.
- *
- * @static
- * @memberOf _
- * @category Collections
- * @param {Array|Object|String} collection The collection to inspect.
- * @returns {Number} Returns `collection.length` or number of own enumerable properties.
- * @example
- *
- * _.size([1, 2]);
- * // => 2
- *
- * _.size({ 'one': 1, 'two': 2, 'three': 3 });
- * // => 3
- *
- * _.size('curly');
- * // => 5
- */
- function size(collection) {
- var length = collection ? collection.length : 0;
- return typeof length == 'number' ? length : keys(collection).length;
- }
- /**
- * Checks if the `callback` returns a truthy value for **any** element of a
- * `collection`. The function returns as soon as it finds passing value, and
- * does not iterate over the entire `collection`. The `callback` is bound to
- * `thisArg` and invoked with three arguments; (value, index|key, collection).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @alias any
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Boolean} Returns `true` if any element passes the callback check,
- * else `false`.
- * @example
- *
- * _.some([null, 0, 'yes', false], Boolean);
- * // => true
- *
- * var food = [
- * { 'name': 'apple', 'organic': false, 'type': 'fruit' },
- * { 'name': 'carrot', 'organic': true, 'type': 'vegetable' }
- * ];
- *
- * // using "_.pluck" callback shorthand
- * _.some(food, 'organic');
- * // => true
- *
- * // using "_.where" callback shorthand
- * _.some(food, { 'type': 'meat' });
- * // => false
- */
- function some(collection, callback, thisArg) {
- var result;
- callback = createCallback(callback, thisArg);
- if (isArray(collection)) {
- var index = -1,
- length = collection.length;
- while (++index < length) {
- if ((result = callback(collection[index], index, collection))) {
- break;
- }
- }
- } else {
- each(collection, function(value, index, collection) {
- return (result = callback(value, index, collection)) && indicatorObject;
- });
- }
- return !!result;
- }
- /**
- * Creates an array of elements, sorted in ascending order by the results of
- * running each element in the `collection` through the `callback`. This method
- * performs a stable sort, that is, it will preserve the original sort order of
- * equal elements. The `callback` is bound to `thisArg` and invoked with three
- * arguments; (value, index|key, collection).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Array} Returns a new array of sorted elements.
- * @example
- *
- * _.sortBy([1, 2, 3], function(num) { return Math.sin(num); });
- * // => [3, 1, 2]
- *
- * _.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math);
- * // => [3, 1, 2]
- *
- * // using "_.pluck" callback shorthand
- * _.sortBy(['banana', 'strawberry', 'apple'], 'length');
- * // => ['apple', 'banana', 'strawberry']
- */
- function sortBy(collection, callback, thisArg) {
- var index = -1,
- length = collection ? collection.length : 0,
- result = Array(typeof length == 'number' ? length : 0);
- callback = createCallback(callback, thisArg);
- forEach(collection, function(value, key, collection) {
- result[++index] = {
- 'criteria': callback(value, key, collection),
- 'index': index,
- 'value': value
- };
- });
- length = result.length;
- result.sort(compareAscending);
- while (length--) {
- result[length] = result[length].value;
- }
- return result;
- }
- /**
- * Converts the `collection` to an array.
- *
- * @static
- * @memberOf _
- * @category Collections
- * @param {Array|Object|String} collection The collection to convert.
- * @returns {Array} Returns the new converted array.
- * @example
- *
- * (function() { return _.toArray(arguments).slice(1); })(1, 2, 3, 4);
- * // => [2, 3, 4]
- */
- function toArray(collection) {
- if (collection && typeof collection.length == 'number') {
- return slice(collection);
- }
- return values(collection);
- }
- /**
- * Examines each element in a `collection`, returning an array of all elements
- * that have the given `properties`. When checking `properties`, this method
- * performs a deep comparison between values to determine if they are equivalent
- * to each other.
- *
- * @static
- * @memberOf _
- * @type Function
- * @category Collections
- * @param {Array|Object|String} collection The collection to iterate over.
- * @param {Object} properties The object of property values to filter by.
- * @returns {Array} Returns a new array of elements that have the given `properties`.
- * @example
- *
- * var stooges = [
- * { 'name': 'moe', 'age': 40 },
- * { 'name': 'larry', 'age': 50 }
- * ];
- *
- * _.where(stooges, { 'age': 40 });
- * // => [{ 'name': 'moe', 'age': 40 }]
- */
- function where(collection, properties, first) {
- return (first && isEmpty(properties))
- ? null
- : (first ? find : filter)(collection, properties);
- }
- /*--------------------------------------------------------------------------*/
- /**
- * Creates an array with all falsey values of `array` removed. The values
- * `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} array The array to compact.
- * @returns {Array} Returns a new filtered array.
- * @example
- *
- * _.compact([0, 1, false, 2, '', 3]);
- * // => [1, 2, 3]
- */
- function compact(array) {
- var index = -1,
- length = array ? array.length : 0,
- result = [];
- while (++index < length) {
- var value = array[index];
- if (value) {
- result.push(value);
- }
- }
- return result;
- }
- /**
- * Creates an array of `array` elements not present in the other arrays
- * using strict equality for comparisons, i.e. `===`.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} array The array to process.
- * @param {Array} [array1, array2, ...] Arrays to check.
- * @returns {Array} Returns a new array of `array` elements not present in the
- * other arrays.
- * @example
- *
- * _.difference([1, 2, 3, 4, 5], [5, 2, 10]);
- * // => [1, 3, 4]
- */
- function difference(array) {
- var index = -1,
- length = array.length,
- flattened = concat.apply(arrayRef, arguments),
- result = [];
- while (++index < length) {
- var value = array[index]
- if (indexOf(flattened, value, length) < 0) {
- result.push(value);
- }
- }
- return result
- }
- /**
- * Gets the first element of the `array`. If a number `n` is passed, the first
- * `n` elements of the `array` are returned. If a `callback` function is passed,
- * the first elements the `callback` returns truthy for are returned. The `callback`
- * is bound to `thisArg` and invoked with three arguments; (value, index, array).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @alias head, take
- * @category Arrays
- * @param {Array} array The array to query.
- * @param {Function|Object|Number|String} [callback|n] The function called
- * per element or the number of elements to return. If a property name or
- * object is passed, it will be used to create a "_.pluck" or "_.where"
- * style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Mixed} Returns the first element(s) of `array`.
- * @example
- *
- * _.first([1, 2, 3]);
- * // => 1
- *
- * _.first([1, 2, 3], 2);
- * // => [1, 2]
- *
- * _.first([1, 2, 3], function(num) {
- * return num < 3;
- * });
- * // => [1, 2]
- *
- * var food = [
- * { 'name': 'banana', 'organic': true },
- * { 'name': 'beet', 'organic': false },
- * ];
- *
- * // using "_.pluck" callback shorthand
- * _.first(food, 'organic');
- * // => [{ 'name': 'banana', 'organic': true }]
- *
- * var food = [
- * { 'name': 'apple', 'type': 'fruit' },
- * { 'name': 'banana', 'type': 'fruit' },
- * { 'name': 'beet', 'type': 'vegetable' }
- * ];
- *
- * // using "_.where" callback shorthand
- * _.first(food, { 'type': 'fruit' });
- * // => [{ 'name': 'apple', 'type': 'fruit' }, { 'name': 'banana', 'type': 'fruit' }]
- */
- function first(array, callback, thisArg) {
- if (array) {
- var n = 0,
- length = array.length;
- if (typeof callback != 'number' && callback != null) {
- var index = -1;
- callback = createCallback(callback, thisArg);
- while (++index < length && callback(array[index], index, array)) {
- n++;
- }
- } else {
- n = callback;
- if (n == null || thisArg) {
- return array[0];
- }
- }
- return slice(array, 0, nativeMin(nativeMax(0, n), length));
- }
- }
- /**
- * Flattens a nested array (the nesting can be to any depth). If `shallow` is
- * truthy, `array` will only be flattened a single level.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} array The array to compact.
- * @param {Boolean} shallow A flag to indicate only flattening a single level.
- * @returns {Array} Returns a new flattened array.
- * @example
- *
- * _.flatten([1, [2], [3, [[4]]]]);
- * // => [1, 2, 3, 4];
- *
- * _.flatten([1, [2], [3, [[4]]]], true);
- * // => [1, 2, 3, [[4]]];
- */
- function flatten(array, shallow) {
- var index = -1,
- length = array ? array.length : 0,
- result = [];
- while (++index < length) {
- var value = array[index];
- // recursively flatten arrays (susceptible to call stack limits)
- if (isArray(value)) {
- push.apply(result, shallow ? value : flatten(value));
- } else {
- result.push(value);
- }
- }
- return result;
- }
- /**
- * Gets the index at which the first occurrence of `value` is found using
- * strict equality for comparisons, i.e. `===`. If the `array` is already
- * sorted, passing `true` for `fromIndex` will run a faster binary search.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} array The array to search.
- * @param {Mixed} value The value to search for.
- * @param {Boolean|Number} [fromIndex=0] The index to search from or `true` to
- * perform a binary search on a sorted `array`.
- * @returns {Number} Returns the index of the matched value or `-1`.
- * @example
- *
- * _.indexOf([1, 2, 3, 1, 2, 3], 2);
- * // => 1
- *
- * _.indexOf([1, 2, 3, 1, 2, 3], 2, 3);
- * // => 4
- *
- * _.indexOf([1, 1, 2, 2, 3, 3], 2, true);
- * // => 2
- */
- function indexOf(array, value, fromIndex) {
- var index = -1,
- length = array ? array.length : 0;
- if (typeof fromIndex == 'number') {
- index = (fromIndex < 0 ? nativeMax(0, length + fromIndex) : fromIndex || 0) - 1;
- } else if (fromIndex) {
- index = sortedIndex(array, value);
- return array[index] === value ? index : -1;
- }
- while (++index < length) {
- if (array[index] === value) {
- return index;
- }
- }
- return -1;
- }
- /**
- * Gets all but the last element of `array`. If a number `n` is passed, the
- * last `n` elements are excluded from the result. If a `callback` function
- * is passed, the last elements the `callback` returns truthy for are excluded
- * from the result. The `callback` is bound to `thisArg` and invoked with three
- * arguments; (value, index, array).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} array The array to query.
- * @param {Function|Object|Number|String} [callback|n=1] The function called
- * per element or the number of elements to exclude. If a property name or
- * object is passed, it will be used to create a "_.pluck" or "_.where"
- * style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Array} Returns a slice of `array`.
- * @example
- *
- * _.initial([1, 2, 3]);
- * // => [1, 2]
- *
- * _.initial([1, 2, 3], 2);
- * // => [1]
- *
- * _.initial([1, 2, 3], function(num) {
- * return num > 1;
- * });
- * // => [1]
- *
- * var food = [
- * { 'name': 'beet', 'organic': false },
- * { 'name': 'carrot', 'organic': true }
- * ];
- *
- * // using "_.pluck" callback shorthand
- * _.initial(food, 'organic');
- * // => [{ 'name': 'beet', 'organic': false }]
- *
- * var food = [
- * { 'name': 'banana', 'type': 'fruit' },
- * { 'name': 'beet', 'type': 'vegetable' },
- * { 'name': 'carrot', 'type': 'vegetable' }
- * ];
- *
- * // using "_.where" callback shorthand
- * _.initial(food, { 'type': 'vegetable' });
- * // => [{ 'name': 'banana', 'type': 'fruit' }]
- */
- function initial(array, callback, thisArg) {
- if (!array) {
- return [];
- }
- var n = 0,
- length = array.length;
- if (typeof callback != 'number' && callback != null) {
- var index = length;
- callback = createCallback(callback, thisArg);
- while (index-- && callback(array[index], index, array)) {
- n++;
- }
- } else {
- n = (callback == null || thisArg) ? 1 : callback || n;
- }
- return slice(array, 0, nativeMin(nativeMax(0, length - n), length));
- }
- /**
- * Computes the intersection of all the passed-in arrays using strict equality
- * for comparisons, i.e. `===`.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} [array1, array2, ...] Arrays to process.
- * @returns {Array} Returns a new array of unique elements that are present
- * in **all** of the arrays.
- * @example
- *
- * _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
- * // => [1, 2]
- */
- function intersection(array) {
- var args = arguments,
- argsLength = args.length,
- index = -1,
- length = array ? array.length : 0,
- result = [];
- outer:
- while (++index < length) {
- var value = array[index];
- if (indexOf(result, value) < 0) {
- var argsIndex = argsLength;
- while (--argsIndex) {
- if (indexOf(args[argsIndex], value) < 0) {
- continue outer;
- }
- }
- result.push(value);
- }
- }
- return result;
- }
- /**
- * Gets the last element of the `array`. If a number `n` is passed, the last
- * `n` elements of the `array` are returned. If a `callback` function is passed,
- * the last elements the `callback` returns truthy for are returned. The `callback`
- * is bound to `thisArg` and invoked with three arguments; (value, index, array).
- *
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} array The array to query.
- * @param {Function|Object|Number|String} [callback|n] The function called
- * per element or the number of elements to return. If a property name or
- * object is passed, it will be used to create a "_.pluck" or "_.where"
- * style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Mixed} Returns the last element(s) of `array`.
- * @example
- *
- * _.last([1, 2, 3]);
- * // => 3
- *
- * _.last([1, 2, 3], 2);
- * // => [2, 3]
- *
- * _.last([1, 2, 3], function(num) {
- * return num > 1;
- * });
- * // => [2, 3]
- *
- * var food = [
- * { 'name': 'beet', 'organic': false },
- * { 'name': 'carrot', 'organic': true }
- * ];
- *
- * // using "_.pluck" callback shorthand
- * _.last(food, 'organic');
- * // => [{ 'name': 'carrot', 'organic': true }]
- *
- * var food = [
- * { 'name': 'banana', 'type': 'fruit' },
- * { 'name': 'beet', 'type': 'vegetable' },
- * { 'name': 'carrot', 'type': 'vegetable' }
- * ];
- *
- * // using "_.where" callback shorthand
- * _.last(food, { 'type': 'vegetable' });
- * // => [{ 'name': 'beet', 'type': 'vegetable' }, { 'name': 'carrot', 'type': 'vegetable' }]
- */
- function last(array, callback, thisArg) {
- if (array) {
- var n = 0,
- length = array.length;
- if (typeof callback != 'number' && callback != null) {
- var index = length;
- callback = createCallback(callback, thisArg);
- while (index-- && callback(array[index], index, array)) {
- n++;
- }
- } else {
- n = callback;
- if (n == null || thisArg) {
- return array[length - 1];
- }
- }
- return slice(array, nativeMax(0, length - n));
- }
- }
- /**
- * Gets the index at which the last occurrence of `value` is found using strict
- * equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used
- * as the offset from the end of the collection.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} array The array to search.
- * @param {Mixed} value The value to search for.
- * @param {Number} [fromIndex=array.length-1] The index to search from.
- * @returns {Number} Returns the index of the matched value or `-1`.
- * @example
- *
- * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
- * // => 4
- *
- * _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3);
- * // => 1
- */
- function lastIndexOf(array, value, fromIndex) {
- var index = array ? array.length : 0;
- if (typeof fromIndex == 'number') {
- index = (fromIndex < 0 ? nativeMax(0, index + fromIndex) : nativeMin(fromIndex, index - 1)) + 1;
- }
- while (index--) {
- if (array[index] === value) {
- return index;
- }
- }
- return -1;
- }
- /**
- * Creates an object composed from arrays of `keys` and `values`. Pass either
- * a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or
- * two arrays, one of `keys` and one of corresponding `values`.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} keys The array of keys.
- * @param {Array} [values=[]] The array of values.
- * @returns {Object} Returns an object composed of the given keys and
- * corresponding values.
- * @example
- *
- * _.object(['moe', 'larry'], [30, 40]);
- * // => { 'moe': 30, 'larry': 40 }
- */
- function object(keys, values) {
- var index = -1,
- length = keys ? keys.length : 0,
- result = {};
- while (++index < length) {
- var key = keys[index];
- if (values) {
- result[key] = values[index];
- } else {
- result[key[0]] = key[1];
- }
- }
- return result;
- }
- /**
- * Creates an array of numbers (positive and/or negative) progressing from
- * `start` up to but not including `end`.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Number} [start=0] The start of the range.
- * @param {Number} end The end of the range.
- * @param {Number} [step=1] The value to increment or descrement by.
- * @returns {Array} Returns a new range array.
- * @example
- *
- * _.range(10);
- * // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
- *
- * _.range(1, 11);
- * // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- *
- * _.range(0, 30, 5);
- * // => [0, 5, 10, 15, 20, 25]
- *
- * _.range(0, -10, -1);
- * // => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
- *
- * _.range(0);
- * // => []
- */
- function range(start, end, step) {
- start = +start || 0;
- step = +step || 1;
- if (end == null) {
- end = start;
- start = 0;
- }
- // use `Array(length)` so V8 will avoid the slower "dictionary" mode
- // http://youtu.be/XAqIpGU8ZZk#t=17m25s
- var index = -1,
- length = nativeMax(0, ceil((end - start) / step)),
- result = Array(length);
- while (++index < length) {
- result[index] = start;
- start += step;
- }
- return result;
- }
- /**
- * The opposite of `_.initial`, this method gets all but the first value of `array`.
- * If a number `n` is passed, the first `n` values are excluded from the result.
- * If a `callback` function is passed, the first elements the `callback` returns
- * truthy for are excluded from the result. The `callback` is bound to `thisArg`
- * and invoked with three arguments; (value, index, array).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @alias drop, tail
- * @category Arrays
- * @param {Array} array The array to query.
- * @param {Function|Object|Number|String} [callback|n=1] The function called
- * per element or the number of elements to exclude. If a property name or
- * object is passed, it will be used to create a "_.pluck" or "_.where"
- * style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Array} Returns a slice of `array`.
- * @example
- *
- * _.rest([1, 2, 3]);
- * // => [2, 3]
- *
- * _.rest([1, 2, 3], 2);
- * // => [3]
- *
- * _.rest([1, 2, 3], function(num) {
- * return num < 3;
- * });
- * // => [3]
- *
- * var food = [
- * { 'name': 'banana', 'organic': true },
- * { 'name': 'beet', 'organic': false },
- * ];
- *
- * // using "_.pluck" callback shorthand
- * _.rest(food, 'organic');
- * // => [{ 'name': 'beet', 'organic': false }]
- *
- * var food = [
- * { 'name': 'apple', 'type': 'fruit' },
- * { 'name': 'banana', 'type': 'fruit' },
- * { 'name': 'beet', 'type': 'vegetable' }
- * ];
- *
- * // using "_.where" callback shorthand
- * _.rest(food, { 'type': 'fruit' });
- * // => [{ 'name': 'beet', 'type': 'vegetable' }]
- */
- function rest(array, callback, thisArg) {
- if (typeof callback != 'number' && callback != null) {
- var n = 0,
- index = -1,
- length = array ? array.length : 0;
- callback = createCallback(callback, thisArg);
- while (++index < length && callback(array[index], index, array)) {
- n++;
- }
- } else {
- n = (callback == null || thisArg) ? 1 : nativeMax(0, callback);
- }
- return slice(array, n);
- }
- /**
- * Uses a binary search to determine the smallest index at which the `value`
- * should be inserted into `array` in order to maintain the sort order of the
- * sorted `array`. If `callback` is passed, it will be executed for `value` and
- * each element in `array` to compute their sort ranking. The `callback` is
- * bound to `thisArg` and invoked with one argument; (value).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} array The array to iterate over.
- * @param {Mixed} value The value to evaluate.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Number} Returns the index at which the value should be inserted
- * into `array`.
- * @example
- *
- * _.sortedIndex([20, 30, 50], 40);
- * // => 2
- *
- * // using "_.pluck" callback shorthand
- * _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
- * // => 2
- *
- * var dict = {
- * 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 }
- * };
- *
- * _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) {
- * return dict.wordToNumber[word];
- * });
- * // => 2
- *
- * _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) {
- * return this.wordToNumber[word];
- * }, dict);
- * // => 2
- */
- function sortedIndex(array, value, callback, thisArg) {
- var low = 0,
- high = array ? array.length : low;
- // explicitly reference `identity` for better inlining in Firefox
- callback = callback ? createCallback(callback, thisArg, 1) : identity;
- value = callback(value);
- while (low < high) {
- var mid = (low + high) >>> 1;
- callback(array[mid]) < value
- ? low = mid + 1
- : high = mid;
- }
- return low;
- }
- /**
- * Computes the union of the passed-in arrays using strict equality for
- * comparisons, i.e. `===`.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} [array1, array2, ...] Arrays to process.
- * @returns {Array} Returns a new array of unique values, in order, that are
- * present in one or more of the arrays.
- * @example
- *
- * _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
- * // => [1, 2, 3, 101, 10]
- */
- function union() {
- return uniq(concat.apply(arrayRef, arguments));
- }
- /**
- * Creates a duplicate-value-free version of the `array` using strict equality
- * for comparisons, i.e. `===`. If the `array` is already sorted, passing `true`
- * for `isSorted` will run a faster algorithm. If `callback` is passed, each
- * element of `array` is passed through a callback` before uniqueness is computed.
- * The `callback` is bound to `thisArg` and invoked with three arguments; (value, index, array).
- *
- * If a property name is passed for `callback`, the created "_.pluck" style
- * callback will return the property value of the given element.
- *
- * If an object is passed for `callback`, the created "_.where" style callback
- * will return `true` for elements that have the propeties of the given object,
- * else `false`.
- *
- * @static
- * @memberOf _
- * @alias unique
- * @category Arrays
- * @param {Array} array The array to process.
- * @param {Boolean} [isSorted=false] A flag to indicate that the `array` is already sorted.
- * @param {Function|Object|String} [callback=identity] The function called per
- * iteration. If a property name or object is passed, it will be used to create
- * a "_.pluck" or "_.where" style callback, respectively.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Array} Returns a duplicate-value-free array.
- * @example
- *
- * _.uniq([1, 2, 1, 3, 1]);
- * // => [1, 2, 3]
- *
- * _.uniq([1, 1, 2, 2, 3], true);
- * // => [1, 2, 3]
- *
- * _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return Math.floor(num); });
- * // => [1, 2, 3]
- *
- * _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math);
- * // => [1, 2, 3]
- *
- * // using "_.pluck" callback shorthand
- * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
- * // => [{ 'x': 1 }, { 'x': 2 }]
- */
- function uniq(array, isSorted, callback, thisArg) {
- var index = -1,
- length = array ? array.length : 0,
- result = [],
- seen = result;
- if (typeof isSorted == 'function') {
- thisArg = callback;
- callback = isSorted;
- isSorted = false;
- }
- if (callback) {
- seen = [];
- callback = createCallback(callback, thisArg);
- }
- while (++index < length) {
- var value = array[index],
- computed = callback ? callback(value, index, array) : value;
- if (isSorted
- ? !index || seen[seen.length - 1] !== computed
- : indexOf(seen, computed) < 0
- ) {
- if (callback) {
- seen.push(computed);
- }
- result.push(value);
- }
- }
- return result;
- }
- /**
- * Creates an array with all occurrences of the passed values removed using
- * strict equality for comparisons, i.e. `===`.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} array The array to filter.
- * @param {Mixed} [value1, value2, ...] Values to remove.
- * @returns {Array} Returns a new filtered array.
- * @example
- *
- * _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
- * // => [2, 3, 4]
- */
- function without(array) {
- var index = -1,
- length = array.length,
- result = [];
- while (++index < length) {
- var value = array[index]
- if (indexOf(arguments, value, 1) < 0) {
- result.push(value);
- }
- }
- return result
- }
- /**
- * Groups the elements of each array at their corresponding indexes. Useful for
- * separate data sources that are coordinated through matching array indexes.
- * For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix
- * in a similar fashion.
- *
- * @static
- * @memberOf _
- * @category Arrays
- * @param {Array} [array1, array2, ...] Arrays to process.
- * @returns {Array} Returns a new array of grouped elements.
- * @example
- *
- * _.zip(['moe', 'larry'], [30, 40], [true, false]);
- * // => [['moe', 30, true], ['larry', 40, false]]
- */
- function zip(array) {
- var index = -1,
- length = array ? max(pluck(arguments, 'length')) : 0,
- result = Array(length);
- while (++index < length) {
- result[index] = pluck(arguments, index);
- }
- return result;
- }
- /*--------------------------------------------------------------------------*/
- /**
- * Creates a function that is restricted to executing `func` only after it is
- * called `n` times. The `func` is executed with the `this` binding of the
- * created function.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Number} n The number of times the function must be called before
- * it is executed.
- * @param {Function} func The function to restrict.
- * @returns {Function} Returns the new restricted function.
- * @example
- *
- * var renderNotes = _.after(notes.length, render);
- * _.forEach(notes, function(note) {
- * note.asyncSave({ 'success': renderNotes });
- * });
- * // `renderNotes` is run once, after all notes have saved
- */
- function after(n, func) {
- if (n < 1) {
- return func();
- }
- return function() {
- if (--n < 1) {
- return func.apply(this, arguments);
- }
- };
- }
- /**
- * Creates a function that, when called, invokes `func` with the `this`
- * binding of `thisArg` and prepends any additional `bind` arguments to those
- * passed to the bound function.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Function} func The function to bind.
- * @param {Mixed} [thisArg] The `this` binding of `func`.
- * @param {Mixed} [arg1, arg2, ...] Arguments to be partially applied.
- * @returns {Function} Returns the new bound function.
- * @example
- *
- * var func = function(greeting) {
- * return greeting + ' ' + this.name;
- * };
- *
- * func = _.bind(func, { 'name': 'moe' }, 'hi');
- * func();
- * // => 'hi moe'
- */
- function bind(func, thisArg) {
- // use `Function#bind` if it exists and is fast
- // (in V8 `Function#bind` is slower except when partially applied)
- return isBindFast || (nativeBind && arguments.length > 2)
- ? nativeBind.call.apply(nativeBind, arguments)
- : createBound(func, thisArg, slice(arguments, 2));
- }
- /**
- * Binds methods on `object` to `object`, overwriting the existing method.
- * Method names may be specified as individual arguments or as arrays of method
- * names. If no method names are provided, all the function properties of `object`
- * will be bound.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Object} object The object to bind and assign the bound methods to.
- * @param {String} [methodName1, methodName2, ...] Method names on the object to bind.
- * @returns {Object} Returns `object`.
- * @example
- *
- * var view = {
- * 'label': 'docs',
- * 'onClick': function() { alert('clicked ' + this.label); }
- * };
- *
- * _.bindAll(view);
- * jQuery('#docs').on('click', view.onClick);
- * // => alerts 'clicked docs', when the button is clicked
- */
- function bindAll(object) {
- var funcs = concat.apply(arrayRef, arguments),
- index = funcs.length > 1 ? 0 : (funcs = functions(object), -1),
- length = funcs.length;
- while (++index < length) {
- var key = funcs[index];
- object[key] = bind(object[key], object);
- }
- return object;
- }
- /**
- * Creates a function that is the composition of the passed functions,
- * where each function consumes the return value of the function that follows.
- * For example, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`.
- * Each function is executed with the `this` binding of the composed function.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Function} [func1, func2, ...] Functions to compose.
- * @returns {Function} Returns the new composed function.
- * @example
- *
- * var greet = function(name) { return 'hi ' + name; };
- * var exclaim = function(statement) { return statement + '!'; };
- * var welcome = _.compose(exclaim, greet);
- * welcome('moe');
- * // => 'hi moe!'
- */
- function compose() {
- var funcs = arguments;
- return function() {
- var args = arguments,
- length = funcs.length;
- while (length--) {
- args = [funcs[length].apply(this, args)];
- }
- return args[0];
- };
- }
- /**
- * Creates a function that will delay the execution of `func` until after
- * `wait` milliseconds have elapsed since the last time it was invoked. Pass
- * `true` for `immediate` to cause debounce to invoke `func` on the leading,
- * instead of the trailing, edge of the `wait` timeout. Subsequent calls to
- * the debounced function will return the result of the last `func` call.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Function} func The function to debounce.
- * @param {Number} wait The number of milliseconds to delay.
- * @param {Boolean} immediate A flag to indicate execution is on the leading
- * edge of the timeout.
- * @returns {Function} Returns the new debounced function.
- * @example
- *
- * var lazyLayout = _.debounce(calculateLayout, 300);
- * jQuery(window).on('resize', lazyLayout);
- */
- function debounce(func, wait, immediate) {
- var args,
- result,
- thisArg,
- timeoutId;
- function delayed() {
- timeoutId = null;
- if (!immediate) {
- result = func.apply(thisArg, args);
- }
- }
- return function() {
- var isImmediate = immediate && !timeoutId;
- args = arguments;
- thisArg = this;
- clearTimeout(timeoutId);
- timeoutId = setTimeout(delayed, wait);
- if (isImmediate) {
- result = func.apply(thisArg, args);
- }
- return result;
- };
- }
- /**
- * Executes the `func` function after `wait` milliseconds. Additional arguments
- * will be passed to `func` when it is invoked.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Function} func The function to delay.
- * @param {Number} wait The number of milliseconds to delay execution.
- * @param {Mixed} [arg1, arg2, ...] Arguments to invoke the function with.
- * @returns {Number} Returns the `setTimeout` timeout id.
- * @example
- *
- * var log = _.bind(console.log, console);
- * _.delay(log, 1000, 'logged later');
- * // => 'logged later' (Appears after one second.)
- */
- function delay(func, wait) {
- var args = slice(arguments, 2);
- return setTimeout(function() { func.apply(undefined, args); }, wait);
- }
- /**
- * Defers executing the `func` function until the current call stack has cleared.
- * Additional arguments will be passed to `func` when it is invoked.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Function} func The function to defer.
- * @param {Mixed} [arg1, arg2, ...] Arguments to invoke the function with.
- * @returns {Number} Returns the `setTimeout` timeout id.
- * @example
- *
- * _.defer(function() { alert('deferred'); });
- * // returns from the function before `alert` is called
- */
- function defer(func) {
- var args = slice(arguments, 1);
- return setTimeout(function() { func.apply(undefined, args); }, 1);
- }
- // use `setImmediate` if it's available in Node.js
- if (isV8 && freeModule && typeof setImmediate == 'function') {
- defer = bind(setImmediate, window);
- }
- /**
- * Creates a function that memoizes the result of `func`. If `resolver` is
- * passed, it will be used to determine the cache key for storing the result
- * based on the arguments passed to the memoized function. By default, the first
- * argument passed to the memoized function is used as the cache key. The `func`
- * is executed with the `this` binding of the memoized function.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Function} func The function to have its output memoized.
- * @param {Function} [resolver] A function used to resolve the cache key.
- * @returns {Function} Returns the new memoizing function.
- * @example
- *
- * var fibonacci = _.memoize(function(n) {
- * return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
- * });
- */
- function memoize(func, resolver) {
- var cache = {};
- return function() {
- var key = (resolver ? resolver.apply(this, arguments) : arguments[0]) + '';
- return hasOwnProperty.call(cache, key)
- ? cache[key]
- : (cache[key] = func.apply(this, arguments));
- };
- }
- /**
- * Creates a function that is restricted to execute `func` once. Repeat calls to
- * the function will return the value of the first call. The `func` is executed
- * with the `this` binding of the created function.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Function} func The function to restrict.
- * @returns {Function} Returns the new restricted function.
- * @example
- *
- * var initialize = _.once(createApplication);
- * initialize();
- * initialize();
- * // `initialize` executes `createApplication` once
- */
- function once(func) {
- var ran,
- result;
- return function() {
- if (ran) {
- return result;
- }
- ran = true;
- result = func.apply(this, arguments);
- // clear the `func` variable so the function may be garbage collected
- func = null;
- return result;
- };
- }
- /**
- * Creates a function that, when called, invokes `func` with any additional
- * `partial` arguments prepended to those passed to the new function. This
- * method is similar to `_.bind`, except it does **not** alter the `this` binding.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Function} func The function to partially apply arguments to.
- * @param {Mixed} [arg1, arg2, ...] Arguments to be partially applied.
- * @returns {Function} Returns the new partially applied function.
- * @example
- *
- * var greet = function(greeting, name) { return greeting + ' ' + name; };
- * var hi = _.partial(greet, 'hi');
- * hi('moe');
- * // => 'hi moe'
- */
- function partial(func) {
- return createBound(func, slice(arguments, 1));
- }
- /**
- * Creates a function that, when executed, will only call the `func`
- * function at most once per every `wait` milliseconds. If the throttled
- * function is invoked more than once during the `wait` timeout, `func` will
- * also be called on the trailing edge of the timeout. Subsequent calls to the
- * throttled function will return the result of the last `func` call.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Function} func The function to throttle.
- * @param {Number} wait The number of milliseconds to throttle executions to.
- * @returns {Function} Returns the new throttled function.
- * @example
- *
- * var throttled = _.throttle(updatePosition, 100);
- * jQuery(window).on('scroll', throttled);
- */
- function throttle(func, wait) {
- var args,
- result,
- thisArg,
- timeoutId,
- lastCalled = 0;
- function trailingCall() {
- lastCalled = new Date;
- timeoutId = null;
- result = func.apply(thisArg, args);
- }
- return function() {
- var now = new Date,
- remaining = wait - (now - lastCalled);
- args = arguments;
- thisArg = this;
- if (remaining <= 0) {
- clearTimeout(timeoutId);
- timeoutId = null;
- lastCalled = now;
- result = func.apply(thisArg, args);
- }
- else if (!timeoutId) {
- timeoutId = setTimeout(trailingCall, remaining);
- }
- return result;
- };
- }
- /**
- * Creates a function that passes `value` to the `wrapper` function as its
- * first argument. Additional arguments passed to the function are appended
- * to those passed to the `wrapper` function. The `wrapper` is executed with
- * the `this` binding of the created function.
- *
- * @static
- * @memberOf _
- * @category Functions
- * @param {Mixed} value The value to wrap.
- * @param {Function} wrapper The wrapper function.
- * @returns {Function} Returns the new function.
- * @example
- *
- * var hello = function(name) { return 'hello ' + name; };
- * hello = _.wrap(hello, function(func) {
- * return 'before, ' + func('moe') + ', after';
- * });
- * hello();
- * // => 'before, hello moe, after'
- */
- function wrap(value, wrapper) {
- return function() {
- var args = [value];
- push.apply(args, arguments);
- return wrapper.apply(this, args);
- };
- }
- /*--------------------------------------------------------------------------*/
- /**
- * Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their
- * corresponding HTML entities.
- *
- * @static
- * @memberOf _
- * @category Utilities
- * @param {String} string The string to escape.
- * @returns {String} Returns the escaped string.
- * @example
- *
- * _.escape('Moe, Larry & Curly');
- * // => 'Moe, Larry & Curly'
- */
- function escape(string) {
- return string == null ? '' : (string + '').replace(reUnescapedHtml, escapeHtmlChar);
- }
- /**
- * This function returns the first argument passed to it.
- *
- * @static
- * @memberOf _
- * @category Utilities
- * @param {Mixed} value Any value.
- * @returns {Mixed} Returns `value`.
- * @example
- *
- * var moe = { 'name': 'moe' };
- * moe === _.identity(moe);
- * // => true
- */
- function identity(value) {
- return value;
- }
- /**
- * Adds functions properties of `object` to the `lodash` function and chainable
- * wrapper.
- *
- * @static
- * @memberOf _
- * @category Utilities
- * @param {Object} object The object of function properties to add to `lodash`.
- * @example
- *
- * _.mixin({
- * 'capitalize': function(string) {
- * return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
- * }
- * });
- *
- * _.capitalize('moe');
- * // => 'Moe'
- *
- * _('moe').capitalize();
- * // => 'Moe'
- */
- function mixin(object) {
- forEach(functions(object), function(methodName) {
- var func = lodash[methodName] = object[methodName];
- lodash.prototype[methodName] = function() {
- var args = [this.__wrapped__];
- push.apply(args, arguments);
-
- var result = func.apply(lodash, args);
- if (this.__chain__) {
- result = new lodash(result);
- result.__chain__ = true;
- }
- return result;
- };
- });
- }
- /**
- * Reverts the '_' variable to its previous value and returns a reference to
- * the `lodash` function.
- *
- * @static
- * @memberOf _
- * @category Utilities
- * @returns {Function} Returns the `lodash` function.
- * @example
- *
- * var lodash = _.noConflict();
- */
- function noConflict() {
- window._ = oldDash;
- return this;
- }
- /**
- * Produces a random number between `min` and `max` (inclusive). If only one
- * argument is passed, a number between `0` and the given number will be returned.
- *
- * @static
- * @memberOf _
- * @category Utilities
- * @param {Number} [min=0] The minimum possible value.
- * @param {Number} [max=1] The maximum possible value.
- * @returns {Number} Returns a random number.
- * @example
- *
- * _.random(0, 5);
- * // => a number between 0 and 5
- *
- * _.random(5);
- * // => also a number between 0 and 5
- */
- function random(min, max) {
- if (min == null && max == null) {
- max = 1;
- }
- min = +min || 0;
- if (max == null) {
- max = min;
- min = 0;
- }
- return min + floor(nativeRandom() * ((+max || 0) - min + 1));
- }
- /**
- * Resolves the value of `property` on `object`. If `property` is a function,
- * it will be invoked and its result returned, else the property value is
- * returned. If `object` is falsey, then `null` is returned.
- *
- * @static
- * @memberOf _
- * @category Utilities
- * @param {Object} object The object to inspect.
- * @param {String} property The property to get the value of.
- * @returns {Mixed} Returns the resolved value.
- * @example
- *
- * var object = {
- * 'cheese': 'crumpets',
- * 'stuff': function() {
- * return 'nonsense';
- * }
- * };
- *
- * _.result(object, 'cheese');
- * // => 'crumpets'
- *
- * _.result(object, 'stuff');
- * // => 'nonsense'
- */
- function result(object, property) {
- var value = object ? object[property] : null;
- return isFunction(value) ? object[property]() : value;
- }
- /**
- * A micro-templating method that handles arbitrary delimiters, preserves
- * whitespace, and correctly escapes quotes within interpolated code.
- *
- * Note: In the development build, `_.template` utilizes sourceURLs for easier
- * debugging. See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
- *
- * Note: Lo-Dash may be used in Chrome extensions by either creating a `lodash csp`
- * build and using precompiled templates, or loading Lo-Dash in a sandbox.
- *
- * For more information on precompiling templates see:
- * http://lodash.com/#custom-builds
- *
- * For more information on Chrome extension sandboxes see:
- * http://developer.chrome.com/stable/extensions/sandboxingEval.html
- *
- * @static
- * @memberOf _
- * @category Utilities
- * @param {String} text The template text.
- * @param {Obect} data The data object used to populate the text.
- * @param {Object} options The options object.
- * escape - The "escape" delimiter regexp.
- * evaluate - The "evaluate" delimiter regexp.
- * interpolate - The "interpolate" delimiter regexp.
- * sourceURL - The sourceURL of the template's compiled source.
- * variable - The data object variable name.
- *
- * @returns {Function|String} Returns a compiled function when no `data` object
- * is given, else it returns the interpolated text.
- * @example
- *
- * // using a compiled template
- * var compiled = _.template('hello <%= name %>');
- * compiled({ 'name': 'moe' });
- * // => 'hello moe'
- *
- * var list = '<% _.forEach(people, function(name) { %><li><%= name %></li><% }); %>';
- * _.template(list, { 'people': ['moe', 'larry'] });
- * // => '<li>moe</li><li>larry</li>'
- *
- * // using the "escape" delimiter to escape HTML in data property values
- * _.template('<b><%- value %></b>', { 'value': '<script>' });
- * // => '<b><script></b>'
- *
- * // using the ES6 delimiter as an alternative to the default "interpolate" delimiter
- * _.template('hello ${ name }', { 'name': 'curly' });
- * // => 'hello curly'
- *
- * // using the internal `print` function in "evaluate" delimiters
- * _.template('<% print("hello " + epithet); %>!', { 'epithet': 'stooge' });
- * // => 'hello stooge!'
- *
- * // using custom template delimiters
- * _.templateSettings = {
- * 'interpolate': /{{([\s\S]+?)}}/g
- * };
- *
- * _.template('hello {{ name }}!', { 'name': 'mustache' });
- * // => 'hello mustache!'
- *
- * // using the `sourceURL` option to specify a custom sourceURL for the template
- * var compiled = _.template('hello <%= name %>', null, { 'sourceURL': '/basic/greeting.jst' });
- * compiled(data);
- * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
- *
- * // using the `variable` option to ensure a with-statement isn't used in the compiled template
- * var compiled = _.template('hi <%= data.name %>!', null, { 'variable': 'data' });
- * compiled.source;
- * // => function(data) {
- * var __t, __p = '', __e = _.escape;
- * __p += 'hi ' + ((__t = ( data.name )) == null ? '' : __t) + '!';
- * return __p;
- * }
- *
- * // using the `source` property to inline compiled templates for meaningful
- * // line numbers in error messages and a stack trace
- * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
- * var JST = {\
- * "main": ' + _.template(mainText).source + '\
- * };\
- * ');
- */
- function template(text, data, options) {
- text || (text = '');
- options = defaults({}, options, lodash.templateSettings);
- var index = 0,
- source = "__p += '",
- variable = options.variable;
- var reDelimiters = RegExp(
- (options.escape || reNoMatch).source + '|' +
- (options.interpolate || reNoMatch).source + '|' +
- (options.evaluate || reNoMatch).source + '|$'
- , 'g');
- text.replace(reDelimiters, function(match, escapeValue, interpolateValue, evaluateValue, offset) {
- source += text.slice(index, offset).replace(reUnescapedString, escapeStringChar);
- if (escapeValue) {
- source += "' +\n_.escape(" + escapeValue + ") +\n'";
- }
- if (evaluateValue) {
- source += "';\n" + evaluateValue + ";\n__p += '";
- }
- if (interpolateValue) {
- source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
- }
- index = offset + match.length;
- return match;
- });
- source += "';\n";
- if (!variable) {
- variable = 'obj';
- source = 'with (' + variable + ' || {}) {\n' + source + '\n}\n';
- }
- source = 'function(' + variable + ') {\n' +
- "var __t, __p = '', __j = Array.prototype.join;\n" +
- "function print() { __p += __j.call(arguments, '') }\n" +
- source +
- 'return __p\n}';
- try {
- var result = Function('_', 'return ' + source)(lodash);
- } catch(e) {
- e.source = source;
- throw e;
- }
- if (data) {
- return result(data);
- }
- result.source = source;
- return result;
- }
- /**
- * Executes the `callback` function `n` times, returning an array of the results
- * of each `callback` execution. The `callback` is bound to `thisArg` and invoked
- * with one argument; (index).
- *
- * @static
- * @memberOf _
- * @category Utilities
- * @param {Number} n The number of times to execute the callback.
- * @param {Function} callback The function called per iteration.
- * @param {Mixed} [thisArg] The `this` binding of `callback`.
- * @returns {Array} Returns a new array of the results of each `callback` execution.
- * @example
- *
- * var diceRolls = _.times(3, _.partial(_.random, 1, 6));
- * // => [3, 6, 4]
- *
- * _.times(3, function(n) { mage.castSpell(n); });
- * // => calls `mage.castSpell(n)` three times, passing `n` of `0`, `1`, and `2` respectively
- *
- * _.times(3, function(n) { this.cast(n); }, mage);
- * // => also calls `mage.castSpell(n)` three times
- */
- function times(n, callback, thisArg) {
- n = +n || 0;
- var index = -1,
- result = Array(n);
- while (++index < n) {
- result[index] = callback.call(thisArg, index);
- }
- return result;
- }
- /**
- * The opposite of `_.escape`, this method converts the HTML entities
- * `&`, `<`, `>`, `"`, and `'` in `string` to their
- * corresponding characters.
- *
- * @static
- * @memberOf _
- * @category Utilities
- * @param {String} string The string to unescape.
- * @returns {String} Returns the unescaped string.
- * @example
- *
- * _.unescape('Moe, Larry & Curly');
- * // => 'Moe, Larry & Curly'
- */
- function unescape(string) {
- return string == null ? '' : (string + '').replace(reEscapedHtml, unescapeHtmlChar);
- }
- /**
- * Generates a unique ID. If `prefix` is passed, the ID will be appended to it.
- *
- * @static
- * @memberOf _
- * @category Utilities
- * @param {String} [prefix] The value to prefix the ID with.
- * @returns {String} Returns the unique ID.
- * @example
- *
- * _.uniqueId('contact_');
- * // => 'contact_104'
- *
- * _.uniqueId();
- * // => '105'
- */
- function uniqueId(prefix) {
- var id = ++idCounter + '';
- return prefix ? prefix + id : id;
- }
- /*--------------------------------------------------------------------------*/
- /**
- * Creates a `lodash` object that wraps the given `value`.
- *
- * @static
- * @memberOf _
- * @category Chaining
- * @param {Mixed} value The value to wrap.
- * @returns {Object} Returns the wrapper object.
- * @example
- *
- * var stooges = [
- * { 'name': 'moe', 'age': 40 },
- * { 'name': 'larry', 'age': 50 },
- * { 'name': 'curly', 'age': 60 }
- * ];
- *
- * var youngest = _.chain(stooges)
- * .sortBy(function(stooge) { return stooge.age; })
- * .map(function(stooge) { return stooge.name + ' is ' + stooge.age; })
- * .first();
- * // => 'moe is 40'
- */
- function chain(value) {
- value = new lodash(value);
- value.__chain__ = true;
- return value;
- }
- /**
- * Invokes `interceptor` with the `value` as the first argument, and then
- * returns `value`. The purpose of this method is to "tap into" a method chain,
- * in order to perform operations on intermediate results within the chain.
- *
- * @static
- * @memberOf _
- * @category Chaining
- * @param {Mixed} value The value to pass to `interceptor`.
- * @param {Function} interceptor The function to invoke.
- * @returns {Mixed} Returns `value`.
- * @example
- *
- * _([1, 2, 3, 4])
- * .filter(function(num) { return num % 2 == 0; })
- * .tap(alert)
- * .map(function(num) { return num * num; })
- * .value();
- * // => // [2, 4] (alerted)
- * // => [4, 16]
- */
- function tap(value, interceptor) {
- interceptor(value);
- return value;
- }
- /**
- * Enables method chaining on the wrapper object.
- *
- * @name chain
- * @memberOf _
- * @category Chaining
- * @returns {Mixed} Returns the wrapper object.
- * @example
- *
- * var sum = _([1, 2, 3])
- * .chain()
- * .reduce(function(sum, num) { return sum + num; })
- * .value()
- * // => 6`
- */
- function wrapperChain() {
- this.__chain__ = true;
- return this;
- }
- /**
- * Produces the `toString` result of the wrapped value.
- *
- * @name toString
- * @memberOf _
- * @category Chaining
- * @returns {String} Returns the string result.
- * @example
- *
- * _([1, 2, 3]).toString();
- * // => '1,2,3'
- */
- function wrapperToString() {
- return this.__wrapped__ + '';
- }
- /**
- * Extracts the wrapped value.
- *
- * @name valueOf
- * @memberOf _
- * @alias value
- * @category Chaining
- * @returns {Mixed} Returns the wrapped value.
- * @example
- *
- * _([1, 2, 3]).valueOf();
- * // => [1, 2, 3]
- */
- function wrapperValueOf() {
- return this.__wrapped__;
- }
- /*--------------------------------------------------------------------------*/
- // add functions that return wrapped values when chaining
- lodash.after = after;
- lodash.bind = bind;
- lodash.bindAll = bindAll;
- lodash.compact = compact;
- lodash.compose = compose;
- lodash.countBy = countBy;
- lodash.debounce = debounce;
- lodash.defaults = defaults;
- lodash.defer = defer;
- lodash.delay = delay;
- lodash.difference = difference;
- lodash.filter = filter;
- lodash.flatten = flatten;
- lodash.forEach = forEach;
- lodash.functions = functions;
- lodash.groupBy = groupBy;
- lodash.initial = initial;
- lodash.intersection = intersection;
- lodash.invert = invert;
- lodash.invoke = invoke;
- lodash.keys = keys;
- lodash.map = map;
- lodash.max = max;
- lodash.memoize = memoize;
- lodash.min = min;
- lodash.object = object;
- lodash.omit = omit;
- lodash.once = once;
- lodash.pairs = pairs;
- lodash.partial = partial;
- lodash.pick = pick;
- lodash.pluck = pluck;
- lodash.range = range;
- lodash.reject = reject;
- lodash.rest = rest;
- lodash.shuffle = shuffle;
- lodash.sortBy = sortBy;
- lodash.tap = tap;
- lodash.throttle = throttle;
- lodash.times = times;
- lodash.toArray = toArray;
- lodash.union = union;
- lodash.uniq = uniq;
- lodash.values = values;
- lodash.where = where;
- lodash.without = without;
- lodash.wrap = wrap;
- lodash.zip = zip;
- // add aliases
- lodash.collect = map;
- lodash.drop = rest;
- lodash.each = forEach;
- lodash.extend = assign;
- lodash.methods = functions;
- lodash.select = filter;
- lodash.tail = rest;
- lodash.unique = uniq;
- /*--------------------------------------------------------------------------*/
- // add functions that return unwrapped values when chaining
- lodash.clone = clone;
- lodash.contains = contains;
- lodash.escape = escape;
- lodash.every = every;
- lodash.find = find;
- lodash.findWhere = findWhere;
- lodash.has = has;
- lodash.identity = identity;
- lodash.indexOf = indexOf;
- lodash.isArguments = isArguments;
- lodash.isArray = isArray;
- lodash.isBoolean = isBoolean;
- lodash.isDate = isDate;
- lodash.isElement = isElement;
- lodash.isEmpty = isEmpty;
- lodash.isEqual = isEqual;
- lodash.isFinite = isFinite;
- lodash.isFunction = isFunction;
- lodash.isNaN = isNaN;
- lodash.isNull = isNull;
- lodash.isNumber = isNumber;
- lodash.isObject = isObject;
- lodash.isRegExp = isRegExp;
- lodash.isString = isString;
- lodash.isUndefined = isUndefined;
- lodash.lastIndexOf = lastIndexOf;
- lodash.mixin = mixin;
- lodash.noConflict = noConflict;
- lodash.random = random;
- lodash.reduce = reduce;
- lodash.reduceRight = reduceRight;
- lodash.result = result;
- lodash.size = size;
- lodash.some = some;
- lodash.sortedIndex = sortedIndex;
- lodash.template = template;
- lodash.unescape = unescape;
- lodash.uniqueId = uniqueId;
- // add aliases
- lodash.all = every;
- lodash.any = some;
- lodash.detect = find;
- lodash.foldl = reduce;
- lodash.foldr = reduceRight;
- lodash.include = contains;
- lodash.inject = reduce;
- /*--------------------------------------------------------------------------*/
- // add functions capable of returning wrapped and unwrapped values when chaining
- lodash.first = first;
- lodash.last = last;
- // add aliases
- lodash.take = first;
- lodash.head = first;
- /*--------------------------------------------------------------------------*/
- lodash.chain = chain;
- /**
- * The semantic version number.
- *
- * @static
- * @memberOf _
- * @type String
- */
- lodash.VERSION = '1.0.2';
- // add functions to `lodash.prototype`
- mixin(lodash);
- // add "Chaining" functions to the wrapper
- lodash.prototype.chain = wrapperChain;
- lodash.prototype.value = wrapperValueOf;
- // add `Array` mutator functions to the wrapper
- each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
- var func = arrayRef[methodName];
- lodash.prototype[methodName] = function() {
- var value = this.__wrapped__;
- func.apply(value, arguments);
- // avoid array-like object bugs with `Array#shift` and `Array#splice`
- // in Firefox < 10 and IE < 9
- if (hasObjectSpliceBug && value.length === 0) {
- delete value[0];
- }
- return this;
- };
- });
- // add `Array` accessor functions to the wrapper
- each(['concat', 'join', 'slice'], function(methodName) {
- var func = arrayRef[methodName];
- lodash.prototype[methodName] = function() {
- var value = this.__wrapped__,
- result = func.apply(value, arguments);
- if (this.__chain__) {
- result = new lodash(result);
- result.__chain__ = true;
- }
- return result;
- };
- });
- /*--------------------------------------------------------------------------*/
- if (freeExports) {
- // in Node.js or RingoJS v0.8.0+
- if (freeModule) {
- (freeModule.exports = lodash)._ = lodash;
- }
- // in Narwhal or RingoJS v0.7.0-
- else {
- freeExports._ = lodash;
- }
- }
- else {
- // in a browser or Rhino
- window._ = lodash;
- }
- }(this));
|