underscore
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -18,25 +18,26 @@ { | ||
"main": "underscore.js", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"devDependencies": { | ||
"docco": "0.6.x", | ||
"phantomjs": "1.9.7-1", | ||
"uglify-js": "2.4.x", | ||
"eslint": "0.6.x" | ||
"eslint": "0.6.x", | ||
"karma": "~0.12.31", | ||
"karma-qunit": "~0.1.4", | ||
"qunit-cli": "~0.2.0", | ||
"uglify-js": "2.4.x" | ||
}, | ||
"scripts": { | ||
"test": "phantomjs test/vendor/runner.js test/index.html?noglobals=true && eslint underscore.js test/*.js test/vendor/runner.js", | ||
"test": "npm run test-node && npm run lint", | ||
"lint": "eslint underscore.js test/*.js", | ||
"test-node": "qunit-cli test/*.js", | ||
"test-browser": "npm i karma-phantomjs-launcher && ./node_modules/karma/bin/karma start", | ||
"build": "uglifyjs underscore.js -c \"evaluate=false\" --comments \"/ .*/\" -m --source-map underscore-min.map -o underscore-min.js", | ||
"doc": "docco underscore.js" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://raw.github.com/jashkenas/underscore/master/LICENSE" | ||
} | ||
], | ||
"license": "MIT", | ||
"files": [ | ||
"underscore.js", | ||
"underscore-min.js", | ||
"underscore-min.map", | ||
"LICENSE" | ||
] | ||
} |
@@ -1,6 +0,6 @@ | ||
// Underscore.js 1.7.0 | ||
// Underscore.js 1.8.0 | ||
// http://underscorejs.org | ||
// (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
// (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
// Underscore may be freely distributed under the MIT license. | ||
(function(){var n=this,t=n._,r=Array.prototype,e=Object.prototype,u=Function.prototype,i=r.push,a=r.slice,o=r.concat,l=e.toString,c=e.hasOwnProperty,f=Array.isArray,s=Object.keys,p=u.bind,h=function(n){return n instanceof h?n:this instanceof h?void(this._wrapped=n):new h(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=h),exports._=h):n._=h,h.VERSION="1.7.0";var g=function(n,t,r){if(t===void 0)return n;switch(null==r?3:r){case 1:return function(r){return n.call(t,r)};case 2:return function(r,e){return n.call(t,r,e)};case 3:return function(r,e,u){return n.call(t,r,e,u)};case 4:return function(r,e,u,i){return n.call(t,r,e,u,i)}}return function(){return n.apply(t,arguments)}};h.iteratee=function(n,t,r){return null==n?h.identity:h.isFunction(n)?g(n,t,r):h.isObject(n)?h.matches(n):h.property(n)},h.each=h.forEach=function(n,t,r){if(null==n)return n;t=g(t,r);var e,u=n.length;if(u===+u)for(e=0;u>e;e++)t(n[e],e,n);else{var i=h.keys(n);for(e=0,u=i.length;u>e;e++)t(n[i[e]],i[e],n)}return n},h.map=h.collect=function(n,t,r){if(null==n)return[];t=h.iteratee(t,r);for(var e,u=n.length!==+n.length&&h.keys(n),i=(u||n).length,a=Array(i),o=0;i>o;o++)e=u?u[o]:o,a[o]=t(n[e],e,n);return a};var v="Reduce of empty array with no initial value";h.reduce=h.foldl=h.inject=function(n,t,r,e){null==n&&(n=[]),t=g(t,e,4);var u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length,o=0;if(arguments.length<3){if(!a)throw new TypeError(v);r=n[i?i[o++]:o++]}for(;a>o;o++)u=i?i[o]:o,r=t(r,n[u],u,n);return r},h.reduceRight=h.foldr=function(n,t,r,e){null==n&&(n=[]),t=g(t,e,4);var u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length;if(arguments.length<3){if(!a)throw new TypeError(v);r=n[i?i[--a]:--a]}for(;a--;)u=i?i[a]:a,r=t(r,n[u],u,n);return r},h.find=h.detect=function(n,t,r){var e;return t=h.iteratee(t,r),h.some(n,function(n,r,u){return t(n,r,u)?(e=n,!0):void 0}),e},h.filter=h.select=function(n,t,r){var e=[];return null==n?e:(t=h.iteratee(t,r),h.each(n,function(n,r,u){t(n,r,u)&&e.push(n)}),e)},h.reject=function(n,t,r){return h.filter(n,h.negate(h.iteratee(t)),r)},h.every=h.all=function(n,t,r){if(null==n)return!0;t=h.iteratee(t,r);var e,u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length;for(e=0;a>e;e++)if(u=i?i[e]:e,!t(n[u],u,n))return!1;return!0},h.some=h.any=function(n,t,r){if(null==n)return!1;t=h.iteratee(t,r);var e,u,i=n.length!==+n.length&&h.keys(n),a=(i||n).length;for(e=0;a>e;e++)if(u=i?i[e]:e,t(n[u],u,n))return!0;return!1},h.contains=h.include=function(n,t){return null==n?!1:(n.length!==+n.length&&(n=h.values(n)),h.indexOf(n,t)>=0)},h.invoke=function(n,t){var r=a.call(arguments,2),e=h.isFunction(t);return h.map(n,function(n){return(e?t:n[t]).apply(n,r)})},h.pluck=function(n,t){return h.map(n,h.property(t))},h.where=function(n,t){return h.filter(n,h.matches(t))},h.findWhere=function(n,t){return h.find(n,h.matches(t))},h.max=function(n,t,r){var e,u,i=-1/0,a=-1/0;if(null==t&&null!=n){n=n.length===+n.length?n:h.values(n);for(var o=0,l=n.length;l>o;o++)e=n[o],e>i&&(i=e)}else t=h.iteratee(t,r),h.each(n,function(n,r,e){u=t(n,r,e),(u>a||u===-1/0&&i===-1/0)&&(i=n,a=u)});return i},h.min=function(n,t,r){var e,u,i=1/0,a=1/0;if(null==t&&null!=n){n=n.length===+n.length?n:h.values(n);for(var o=0,l=n.length;l>o;o++)e=n[o],i>e&&(i=e)}else t=h.iteratee(t,r),h.each(n,function(n,r,e){u=t(n,r,e),(a>u||1/0===u&&1/0===i)&&(i=n,a=u)});return i},h.shuffle=function(n){for(var t,r=n&&n.length===+n.length?n:h.values(n),e=r.length,u=Array(e),i=0;e>i;i++)t=h.random(0,i),t!==i&&(u[i]=u[t]),u[t]=r[i];return u},h.sample=function(n,t,r){return null==t||r?(n.length!==+n.length&&(n=h.values(n)),n[h.random(n.length-1)]):h.shuffle(n).slice(0,Math.max(0,t))},h.sortBy=function(n,t,r){return t=h.iteratee(t,r),h.pluck(h.map(n,function(n,r,e){return{value:n,index:r,criteria:t(n,r,e)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index-t.index}),"value")};var m=function(n){return function(t,r,e){var u={};return r=h.iteratee(r,e),h.each(t,function(e,i){var a=r(e,i,t);n(u,e,a)}),u}};h.groupBy=m(function(n,t,r){h.has(n,r)?n[r].push(t):n[r]=[t]}),h.indexBy=m(function(n,t,r){n[r]=t}),h.countBy=m(function(n,t,r){h.has(n,r)?n[r]++:n[r]=1}),h.sortedIndex=function(n,t,r,e){r=h.iteratee(r,e,1);for(var u=r(t),i=0,a=n.length;a>i;){var o=i+a>>>1;r(n[o])<u?i=o+1:a=o}return i},h.toArray=function(n){return n?h.isArray(n)?a.call(n):n.length===+n.length?h.map(n,h.identity):h.values(n):[]},h.size=function(n){return null==n?0:n.length===+n.length?n.length:h.keys(n).length},h.partition=function(n,t,r){t=h.iteratee(t,r);var e=[],u=[];return h.each(n,function(n,r,i){(t(n,r,i)?e:u).push(n)}),[e,u]},h.first=h.head=h.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:0>t?[]:a.call(n,0,t)},h.initial=function(n,t,r){return a.call(n,0,Math.max(0,n.length-(null==t||r?1:t)))},h.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:a.call(n,Math.max(n.length-t,0))},h.rest=h.tail=h.drop=function(n,t,r){return a.call(n,null==t||r?1:t)},h.compact=function(n){return h.filter(n,h.identity)};var y=function(n,t,r,e){if(t&&h.every(n,h.isArray))return o.apply(e,n);for(var u=0,a=n.length;a>u;u++){var l=n[u];h.isArray(l)||h.isArguments(l)?t?i.apply(e,l):y(l,t,r,e):r||e.push(l)}return e};h.flatten=function(n,t){return y(n,t,!1,[])},h.without=function(n){return h.difference(n,a.call(arguments,1))},h.uniq=h.unique=function(n,t,r,e){if(null==n)return[];h.isBoolean(t)||(e=r,r=t,t=!1),null!=r&&(r=h.iteratee(r,e));for(var u=[],i=[],a=0,o=n.length;o>a;a++){var l=n[a];if(t)a&&i===l||u.push(l),i=l;else if(r){var c=r(l,a,n);h.indexOf(i,c)<0&&(i.push(c),u.push(l))}else h.indexOf(u,l)<0&&u.push(l)}return u},h.union=function(){return h.uniq(y(arguments,!0,!0,[]))},h.intersection=function(n){if(null==n)return[];for(var t=[],r=arguments.length,e=0,u=n.length;u>e;e++){var i=n[e];if(!h.contains(t,i)){for(var a=1;r>a&&h.contains(arguments[a],i);a++);a===r&&t.push(i)}}return t},h.difference=function(n){var t=y(a.call(arguments,1),!0,!0,[]);return h.filter(n,function(n){return!h.contains(t,n)})},h.zip=function(n){if(null==n)return[];for(var t=h.max(arguments,"length").length,r=Array(t),e=0;t>e;e++)r[e]=h.pluck(arguments,e);return r},h.object=function(n,t){if(null==n)return{};for(var r={},e=0,u=n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},h.indexOf=function(n,t,r){if(null==n)return-1;var e=0,u=n.length;if(r){if("number"!=typeof r)return e=h.sortedIndex(n,t),n[e]===t?e:-1;e=0>r?Math.max(0,u+r):r}for(;u>e;e++)if(n[e]===t)return e;return-1},h.lastIndexOf=function(n,t,r){if(null==n)return-1;var e=n.length;for("number"==typeof r&&(e=0>r?e+r+1:Math.min(e,r+1));--e>=0;)if(n[e]===t)return e;return-1},h.range=function(n,t,r){arguments.length<=1&&(t=n||0,n=0),r=r||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=Array(e),i=0;e>i;i++,n+=r)u[i]=n;return u};var d=function(){};h.bind=function(n,t){var r,e;if(p&&n.bind===p)return p.apply(n,a.call(arguments,1));if(!h.isFunction(n))throw new TypeError("Bind must be called on a function");return r=a.call(arguments,2),e=function(){if(!(this instanceof e))return n.apply(t,r.concat(a.call(arguments)));d.prototype=n.prototype;var u=new d;d.prototype=null;var i=n.apply(u,r.concat(a.call(arguments)));return h.isObject(i)?i:u}},h.partial=function(n){var t=a.call(arguments,1);return function(){for(var r=0,e=t.slice(),u=0,i=e.length;i>u;u++)e[u]===h&&(e[u]=arguments[r++]);for(;r<arguments.length;)e.push(arguments[r++]);return n.apply(this,e)}},h.bindAll=function(n){var t,r,e=arguments.length;if(1>=e)throw new Error("bindAll must be passed function names");for(t=1;e>t;t++)r=arguments[t],n[r]=h.bind(n[r],n);return n},h.memoize=function(n,t){var r=function(e){var u=r.cache,i=t?t.apply(this,arguments):e;return h.has(u,i)||(u[i]=n.apply(this,arguments)),u[i]};return r.cache={},r},h.delay=function(n,t){var r=a.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},h.defer=function(n){return h.delay.apply(h,[n,1].concat(a.call(arguments,1)))},h.throttle=function(n,t,r){var e,u,i,a=null,o=0;r||(r={});var l=function(){o=r.leading===!1?0:h.now(),a=null,i=n.apply(e,u),a||(e=u=null)};return function(){var c=h.now();o||r.leading!==!1||(o=c);var f=t-(c-o);return e=this,u=arguments,0>=f||f>t?(clearTimeout(a),a=null,o=c,i=n.apply(e,u),a||(e=u=null)):a||r.trailing===!1||(a=setTimeout(l,f)),i}},h.debounce=function(n,t,r){var e,u,i,a,o,l=function(){var c=h.now()-a;t>c&&c>0?e=setTimeout(l,t-c):(e=null,r||(o=n.apply(i,u),e||(i=u=null)))};return function(){i=this,u=arguments,a=h.now();var c=r&&!e;return e||(e=setTimeout(l,t)),c&&(o=n.apply(i,u),i=u=null),o}},h.wrap=function(n,t){return h.partial(t,n)},h.negate=function(n){return function(){return!n.apply(this,arguments)}},h.compose=function(){var n=arguments,t=n.length-1;return function(){for(var r=t,e=n[t].apply(this,arguments);r--;)e=n[r].call(this,e);return e}},h.after=function(n,t){return function(){return--n<1?t.apply(this,arguments):void 0}},h.before=function(n,t){var r;return function(){return--n>0?r=t.apply(this,arguments):t=null,r}},h.once=h.partial(h.before,2),h.keys=function(n){if(!h.isObject(n))return[];if(s)return s(n);var t=[];for(var r in n)h.has(n,r)&&t.push(r);return t},h.values=function(n){for(var t=h.keys(n),r=t.length,e=Array(r),u=0;r>u;u++)e[u]=n[t[u]];return e},h.pairs=function(n){for(var t=h.keys(n),r=t.length,e=Array(r),u=0;r>u;u++)e[u]=[t[u],n[t[u]]];return e},h.invert=function(n){for(var t={},r=h.keys(n),e=0,u=r.length;u>e;e++)t[n[r[e]]]=r[e];return t},h.functions=h.methods=function(n){var t=[];for(var r in n)h.isFunction(n[r])&&t.push(r);return t.sort()},h.extend=function(n){if(!h.isObject(n))return n;for(var t,r,e=1,u=arguments.length;u>e;e++){t=arguments[e];for(r in t)c.call(t,r)&&(n[r]=t[r])}return n},h.pick=function(n,t,r){var e,u={};if(null==n)return u;if(h.isFunction(t)){t=g(t,r);for(e in n){var i=n[e];t(i,e,n)&&(u[e]=i)}}else{var l=o.apply([],a.call(arguments,1));n=new Object(n);for(var c=0,f=l.length;f>c;c++)e=l[c],e in n&&(u[e]=n[e])}return u},h.omit=function(n,t,r){if(h.isFunction(t))t=h.negate(t);else{var e=h.map(o.apply([],a.call(arguments,1)),String);t=function(n,t){return!h.contains(e,t)}}return h.pick(n,t,r)},h.defaults=function(n){if(!h.isObject(n))return n;for(var t=1,r=arguments.length;r>t;t++){var e=arguments[t];for(var u in e)n[u]===void 0&&(n[u]=e[u])}return n},h.clone=function(n){return h.isObject(n)?h.isArray(n)?n.slice():h.extend({},n):n},h.tap=function(n,t){return t(n),n};var b=function(n,t,r,e){if(n===t)return 0!==n||1/n===1/t;if(null==n||null==t)return n===t;n instanceof h&&(n=n._wrapped),t instanceof h&&(t=t._wrapped);var u=l.call(n);if(u!==l.call(t))return!1;switch(u){case"[object RegExp]":case"[object String]":return""+n==""+t;case"[object Number]":return+n!==+n?+t!==+t:0===+n?1/+n===1/t:+n===+t;case"[object Date]":case"[object Boolean]":return+n===+t}if("object"!=typeof n||"object"!=typeof t)return!1;for(var i=r.length;i--;)if(r[i]===n)return e[i]===t;var a=n.constructor,o=t.constructor;if(a!==o&&"constructor"in n&&"constructor"in t&&!(h.isFunction(a)&&a instanceof a&&h.isFunction(o)&&o instanceof o))return!1;r.push(n),e.push(t);var c,f;if("[object Array]"===u){if(c=n.length,f=c===t.length)for(;c--&&(f=b(n[c],t[c],r,e)););}else{var s,p=h.keys(n);if(c=p.length,f=h.keys(t).length===c)for(;c--&&(s=p[c],f=h.has(t,s)&&b(n[s],t[s],r,e)););}return r.pop(),e.pop(),f};h.isEqual=function(n,t){return b(n,t,[],[])},h.isEmpty=function(n){if(null==n)return!0;if(h.isArray(n)||h.isString(n)||h.isArguments(n))return 0===n.length;for(var t in n)if(h.has(n,t))return!1;return!0},h.isElement=function(n){return!(!n||1!==n.nodeType)},h.isArray=f||function(n){return"[object Array]"===l.call(n)},h.isObject=function(n){var t=typeof n;return"function"===t||"object"===t&&!!n},h.each(["Arguments","Function","String","Number","Date","RegExp"],function(n){h["is"+n]=function(t){return l.call(t)==="[object "+n+"]"}}),h.isArguments(arguments)||(h.isArguments=function(n){return h.has(n,"callee")}),"function"!=typeof/./&&(h.isFunction=function(n){return"function"==typeof n||!1}),h.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},h.isNaN=function(n){return h.isNumber(n)&&n!==+n},h.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"===l.call(n)},h.isNull=function(n){return null===n},h.isUndefined=function(n){return n===void 0},h.has=function(n,t){return null!=n&&c.call(n,t)},h.noConflict=function(){return n._=t,this},h.identity=function(n){return n},h.constant=function(n){return function(){return n}},h.noop=function(){},h.property=function(n){return function(t){return t[n]}},h.matches=function(n){var t=h.pairs(n),r=t.length;return function(n){if(null==n)return!r;n=new Object(n);for(var e=0;r>e;e++){var u=t[e],i=u[0];if(u[1]!==n[i]||!(i in n))return!1}return!0}},h.times=function(n,t,r){var e=Array(Math.max(0,n));t=g(t,r,1);for(var u=0;n>u;u++)e[u]=t(u);return e},h.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))},h.now=Date.now||function(){return(new Date).getTime()};var _={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},w=h.invert(_),j=function(n){var t=function(t){return n[t]},r="(?:"+h.keys(n).join("|")+")",e=RegExp(r),u=RegExp(r,"g");return function(n){return n=null==n?"":""+n,e.test(n)?n.replace(u,t):n}};h.escape=j(_),h.unescape=j(w),h.result=function(n,t){if(null==n)return void 0;var r=n[t];return h.isFunction(r)?n[t]():r};var x=0;h.uniqueId=function(n){var t=++x+"";return n?n+t:t},h.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var A=/(.)^/,k={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},O=/\\|'|\r|\n|\u2028|\u2029/g,F=function(n){return"\\"+k[n]};h.template=function(n,t,r){!t&&r&&(t=r),t=h.defaults({},t,h.templateSettings);var e=RegExp([(t.escape||A).source,(t.interpolate||A).source,(t.evaluate||A).source].join("|")+"|$","g"),u=0,i="__p+='";n.replace(e,function(t,r,e,a,o){return i+=n.slice(u,o).replace(O,F),u=o+t.length,r?i+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'":e?i+="'+\n((__t=("+e+"))==null?'':__t)+\n'":a&&(i+="';\n"+a+"\n__p+='"),t}),i+="';\n",t.variable||(i="with(obj||{}){\n"+i+"}\n"),i="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+i+"return __p;\n";try{var a=new Function(t.variable||"obj","_",i)}catch(o){throw o.source=i,o}var l=function(n){return a.call(this,n,h)},c=t.variable||"obj";return l.source="function("+c+"){\n"+i+"}",l},h.chain=function(n){var t=h(n);return t._chain=!0,t};var E=function(n){return this._chain?h(n).chain():n};h.mixin=function(n){h.each(h.functions(n),function(t){var r=h[t]=n[t];h.prototype[t]=function(){var n=[this._wrapped];return i.apply(n,arguments),E.call(this,r.apply(h,n))}})},h.mixin(h),h.each(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=r[n];h.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!==n&&"splice"!==n||0!==r.length||delete r[0],E.call(this,r)}}),h.each(["concat","join","slice"],function(n){var t=r[n];h.prototype[n]=function(){return E.call(this,t.apply(this._wrapped,arguments))}}),h.prototype.value=function(){return this._wrapped},"function"==typeof define&&define.amd&&define("underscore",[],function(){return h})}).call(this); | ||
(function(){function n(n){function t(t,r,e,u,i,o){for(;i>=0&&o>i;i+=n){var a=u?u[i]:i;e=r(e,t[a],a,t)}return e}return function(r,e,u,i){e=d(e,i,4);var o=!w(r)&&m.keys(r),a=(o||r).length,c=n>0?0:a-1;return arguments.length<3&&(u=r[o?o[c]:c],c+=n),t(r,e,u,o,c,a)}}function t(n){return function(t,r,e){r=b(r,e);for(var u=null!=t&&t.length,i=n>0?0:u-1;i>=0&&u>i;i+=n)if(r(t[i],i,t))return i;return-1}}function r(n,t){for(var r=F.length,e="function"==typeof n.constructor?a:o;r--;){var u=F[r];("constructor"===u?m.has(n,u):u in n&&n[u]!==e[u]&&!m.contains(t,u))&&t.push(u)}}var e=this,u=e._,i=Array.prototype,o=Object.prototype,a=Function.prototype,c=i.push,f=i.slice,l=o.toString,s=o.hasOwnProperty,p=Array.isArray,h=Object.keys,v=a.bind,g=Object.create,y=function(){},m=function(n){return n instanceof m?n:this instanceof m?void(this._wrapped=n):new m(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=m),exports._=m):e._=m,m.VERSION="1.8.0";var d=function(n,t,r){if(t===void 0)return n;switch(null==r?3:r){case 1:return function(r){return n.call(t,r)};case 2:return function(r,e){return n.call(t,r,e)};case 3:return function(r,e,u){return n.call(t,r,e,u)};case 4:return function(r,e,u,i){return n.call(t,r,e,u,i)}}return function(){return n.apply(t,arguments)}},b=function(n,t,r){return null==n?m.identity:m.isFunction(n)?d(n,t,r):m.isObject(n)?m.matcher(n):m.property(n)};m.iteratee=function(n,t){return b(n,t,1/0)};var x=function(n,t){return function(r){var e=arguments.length;if(2>e||null==r)return r;for(var u=1;e>u;u++)for(var i=arguments[u],o=n(i),a=o.length,c=0;a>c;c++){var f=o[c];t&&r[f]!==void 0||(r[f]=i[f])}return r}},_=function(n){if(!m.isObject(n))return{};if(g)return g(n);y.prototype=n;var t=new y;return y.prototype=null,t},j=Math.pow(2,53)-1,w=function(n){var t=n&&n.length;return"number"==typeof t&&t>=0&&j>=t};m.each=m.forEach=function(n,t,r){t=d(t,r);var e,u;if(w(n))for(e=0,u=n.length;u>e;e++)t(n[e],e,n);else{var i=m.keys(n);for(e=0,u=i.length;u>e;e++)t(n[i[e]],i[e],n)}return n},m.map=m.collect=function(n,t,r){t=b(t,r);for(var e=!w(n)&&m.keys(n),u=(e||n).length,i=Array(u),o=0;u>o;o++){var a=e?e[o]:o;i[o]=t(n[a],a,n)}return i},m.reduce=m.foldl=m.inject=n(1),m.reduceRight=m.foldr=n(-1),m.find=m.detect=function(n,t,r){var e;return e=w(n)?m.findIndex(n,t,r):m.findKey(n,t,r),e!==void 0&&e!==-1?n[e]:void 0},m.filter=m.select=function(n,t,r){var e=[];return t=b(t,r),m.each(n,function(n,r,u){t(n,r,u)&&e.push(n)}),e},m.reject=function(n,t,r){return m.filter(n,m.negate(b(t)),r)},m.every=m.all=function(n,t,r){t=b(t,r);for(var e=!w(n)&&m.keys(n),u=(e||n).length,i=0;u>i;i++){var o=e?e[i]:i;if(!t(n[o],o,n))return!1}return!0},m.some=m.any=function(n,t,r){t=b(t,r);for(var e=!w(n)&&m.keys(n),u=(e||n).length,i=0;u>i;i++){var o=e?e[i]:i;if(t(n[o],o,n))return!0}return!1},m.contains=m.includes=m.include=function(n,t){return w(n)||(n=m.values(n)),m.indexOf(n,t)>=0},m.invoke=function(n,t){var r=f.call(arguments,2),e=m.isFunction(t);return m.map(n,function(n){var u=e?t:n[t];return null==u?u:u.apply(n,r)})},m.pluck=function(n,t){return m.map(n,m.property(t))},m.where=function(n,t){return m.filter(n,m.matcher(t))},m.findWhere=function(n,t){return m.find(n,m.matcher(t))},m.max=function(n,t,r){var e,u,i=-1/0,o=-1/0;if(null==t&&null!=n){n=w(n)?n:m.values(n);for(var a=0,c=n.length;c>a;a++)e=n[a],e>i&&(i=e)}else t=b(t,r),m.each(n,function(n,r,e){u=t(n,r,e),(u>o||u===-1/0&&i===-1/0)&&(i=n,o=u)});return i},m.min=function(n,t,r){var e,u,i=1/0,o=1/0;if(null==t&&null!=n){n=w(n)?n:m.values(n);for(var a=0,c=n.length;c>a;a++)e=n[a],i>e&&(i=e)}else t=b(t,r),m.each(n,function(n,r,e){u=t(n,r,e),(o>u||1/0===u&&1/0===i)&&(i=n,o=u)});return i},m.shuffle=function(n){for(var t,r=w(n)?n:m.values(n),e=r.length,u=Array(e),i=0;e>i;i++)t=m.random(0,i),t!==i&&(u[i]=u[t]),u[t]=r[i];return u},m.sample=function(n,t,r){return null==t||r?(w(n)||(n=m.values(n)),n[m.random(n.length-1)]):m.shuffle(n).slice(0,Math.max(0,t))},m.sortBy=function(n,t,r){return t=b(t,r),m.pluck(m.map(n,function(n,r,e){return{value:n,index:r,criteria:t(n,r,e)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index-t.index}),"value")};var A=function(n){return function(t,r,e){var u={};return r=b(r,e),m.each(t,function(e,i){var o=r(e,i,t);n(u,e,o)}),u}};m.groupBy=A(function(n,t,r){m.has(n,r)?n[r].push(t):n[r]=[t]}),m.indexBy=A(function(n,t,r){n[r]=t}),m.countBy=A(function(n,t,r){m.has(n,r)?n[r]++:n[r]=1}),m.toArray=function(n){return n?m.isArray(n)?f.call(n):w(n)?m.map(n,m.identity):m.values(n):[]},m.size=function(n){return null==n?0:w(n)?n.length:m.keys(n).length},m.partition=function(n,t,r){t=b(t,r);var e=[],u=[];return m.each(n,function(n,r,i){(t(n,r,i)?e:u).push(n)}),[e,u]},m.first=m.head=m.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:m.initial(n,n.length-t)},m.initial=function(n,t,r){return f.call(n,0,Math.max(0,n.length-(null==t||r?1:t)))},m.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:m.rest(n,Math.max(0,n.length-t))},m.rest=m.tail=m.drop=function(n,t,r){return f.call(n,null==t||r?1:t)},m.compact=function(n){return m.filter(n,m.identity)};var k=function(n,t,r,e){for(var u=[],i=0,o=e||0,a=n&&n.length;a>o;o++){var c=n[o];if(w(c)&&(m.isArray(c)||m.isArguments(c))){t||(c=k(c,t,r));var f=0,l=c.length;for(u.length+=l;l>f;)u[i++]=c[f++]}else r||(u[i++]=c)}return u};m.flatten=function(n,t){return k(n,t,!1)},m.without=function(n){return m.difference(n,f.call(arguments,1))},m.uniq=m.unique=function(n,t,r,e){if(null==n)return[];m.isBoolean(t)||(e=r,r=t,t=!1),null!=r&&(r=b(r,e));for(var u=[],i=[],o=0,a=n.length;a>o;o++){var c=n[o],f=r?r(c,o,n):c;t?(o&&i===f||u.push(c),i=f):r?m.contains(i,f)||(i.push(f),u.push(c)):m.contains(u,c)||u.push(c)}return u},m.union=function(){return m.uniq(k(arguments,!0,!0))},m.intersection=function(n){if(null==n)return[];for(var t=[],r=arguments.length,e=0,u=n.length;u>e;e++){var i=n[e];if(!m.contains(t,i)){for(var o=1;r>o&&m.contains(arguments[o],i);o++);o===r&&t.push(i)}}return t},m.difference=function(n){var t=k(arguments,!0,!0,1);return m.filter(n,function(n){return!m.contains(t,n)})},m.zip=function(){return m.unzip(arguments)},m.unzip=function(n){for(var t=n&&m.max(n,"length").length||0,r=Array(t),e=0;t>e;e++)r[e]=m.pluck(n,e);return r},m.object=function(n,t){for(var r={},e=0,u=n&&n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},m.indexOf=function(n,t,r){var e=0,u=n&&n.length;if("number"==typeof r)e=0>r?Math.max(0,u+r):r;else if(r&&u)return e=m.sortedIndex(n,t),n[e]===t?e:-1;if(t!==t)return m.findIndex(f.call(n,e),m.isNaN);for(;u>e;e++)if(n[e]===t)return e;return-1},m.lastIndexOf=function(n,t,r){var e=n?n.length:0;if("number"==typeof r&&(e=0>r?e+r+1:Math.min(e,r+1)),t!==t)return m.findLastIndex(f.call(n,0,e),m.isNaN);for(;--e>=0;)if(n[e]===t)return e;return-1},m.findIndex=t(1),m.findLastIndex=t(-1),m.sortedIndex=function(n,t,r,e){r=b(r,e,1);for(var u=r(t),i=0,o=n.length;o>i;){var a=Math.floor((i+o)/2);r(n[a])<u?i=a+1:o=a}return i},m.range=function(n,t,r){arguments.length<=1&&(t=n||0,n=0),r=r||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=Array(e),i=0;e>i;i++,n+=r)u[i]=n;return u};var O=function(n,t,r,e,u){if(!(e instanceof t))return n.apply(r,u);var i=_(n.prototype),o=n.apply(i,u);return m.isObject(o)?o:i};m.bind=function(n,t){if(v&&n.bind===v)return v.apply(n,f.call(arguments,1));if(!m.isFunction(n))throw new TypeError("Bind must be called on a function");var r=f.call(arguments,2);return function e(){return O(n,e,t,this,r.concat(f.call(arguments)))}},m.partial=function(n){var t=f.call(arguments,1);return function r(){for(var e=0,u=t.length,i=Array(u),o=0;u>o;o++)i[o]=t[o]===m?arguments[e++]:t[o];for(;e<arguments.length;)i.push(arguments[e++]);return O(n,r,this,this,i)}},m.bindAll=function(n){var t,r,e=arguments.length;if(1>=e)throw new Error("bindAll must be passed function names");for(t=1;e>t;t++)r=arguments[t],n[r]=m.bind(n[r],n);return n},m.memoize=function(n,t){var r=function(e){var u=r.cache,i=""+(t?t.apply(this,arguments):e);return m.has(u,i)||(u[i]=n.apply(this,arguments)),u[i]};return r.cache={},r},m.delay=function(n,t){var r=f.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},m.defer=m.partial(m.delay,m,1),m.throttle=function(n,t,r){var e,u,i,o=null,a=0;r||(r={});var c=function(){a=r.leading===!1?0:m.now(),o=null,i=n.apply(e,u),o||(e=u=null)};return function(){var f=m.now();a||r.leading!==!1||(a=f);var l=t-(f-a);return e=this,u=arguments,0>=l||l>t?(o&&(clearTimeout(o),o=null),a=f,i=n.apply(e,u),o||(e=u=null)):o||r.trailing===!1||(o=setTimeout(c,l)),i}},m.debounce=function(n,t,r){var e,u,i,o,a,c=function(){var f=m.now()-o;t>f&&f>=0?e=setTimeout(c,t-f):(e=null,r||(a=n.apply(i,u),e||(i=u=null)))};return function(){i=this,u=arguments,o=m.now();var f=r&&!e;return e||(e=setTimeout(c,t)),f&&(a=n.apply(i,u),i=u=null),a}},m.wrap=function(n,t){return m.partial(t,n)},m.negate=function(n){return function(){return!n.apply(this,arguments)}},m.compose=function(){var n=arguments,t=n.length-1;return function(){for(var r=t,e=n[t].apply(this,arguments);r--;)e=n[r].call(this,e);return e}},m.after=function(n,t){return function(){return--n<1?t.apply(this,arguments):void 0}},m.before=function(n,t){var r;return function(){return--n>0&&(r=t.apply(this,arguments)),1>=n&&(t=null),r}},m.once=m.partial(m.before,2);var S=!{toString:null}.propertyIsEnumerable("toString"),F=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"];m.keys=function(n){if(!m.isObject(n))return[];if(h)return h(n);var t=[];for(var e in n)m.has(n,e)&&t.push(e);return S&&r(n,t),t},m.allKeys=function(n){if(!m.isObject(n))return[];var t=[];for(var e in n)t.push(e);return S&&r(n,t),t},m.values=function(n){for(var t=m.keys(n),r=t.length,e=Array(r),u=0;r>u;u++)e[u]=n[t[u]];return e},m.mapObject=function(n,t,r){t=b(t,r);for(var e,u=m.keys(n),i=u.length,o={},a=0;i>a;a++)e=u[a],o[e]=t(n[e],e,n);return o},m.pairs=function(n){for(var t=m.keys(n),r=t.length,e=Array(r),u=0;r>u;u++)e[u]=[t[u],n[t[u]]];return e},m.invert=function(n){for(var t={},r=m.keys(n),e=0,u=r.length;u>e;e++)t[n[r[e]]]=r[e];return t},m.functions=m.methods=function(n){var t=[];for(var r in n)m.isFunction(n[r])&&t.push(r);return t.sort()},m.extend=x(m.allKeys),m.extendOwn=x(m.keys),m.findKey=function(n,t,r){t=b(t,r);for(var e,u=m.keys(n),i=0,o=u.length;o>i;i++)if(e=u[i],t(n[e],e,n))return e},m.pick=function(n,t,r){var e,u={};if(null==n)return u;if(m.isFunction(t)){t=d(t,r);for(e in n){var i=n[e];t(i,e,n)&&(u[e]=i)}}else{var o=k(arguments,!1,!1,1);n=new Object(n);for(var a=0,c=o.length;c>a;a++)e=o[a],e in n&&(u[e]=n[e])}return u},m.omit=function(n,t,r){if(m.isFunction(t))t=m.negate(t);else{var e=m.map(k(arguments,!1,!1,1),String);t=function(n,t){return!m.contains(e,t)}}return m.pick(n,t,r)},m.defaults=x(m.allKeys,!0),m.clone=function(n){return m.isObject(n)?m.isArray(n)?n.slice():m.extend({},n):n},m.tap=function(n,t){return t(n),n},m.isMatch=function(n,t){var r=m.keys(t),e=r.length;if(null==n)return!e;for(var u=Object(n),i=0;e>i;i++){var o=r[i];if(t[o]!==u[o]||!(o in u))return!1}return!0};var E=function(n,t,r,e){if(n===t)return 0!==n||1/n===1/t;if(null==n||null==t)return n===t;n instanceof m&&(n=n._wrapped),t instanceof m&&(t=t._wrapped);var u=l.call(n);if(u!==l.call(t))return!1;switch(u){case"[object RegExp]":case"[object String]":return""+n==""+t;case"[object Number]":return+n!==+n?+t!==+t:0===+n?1/+n===1/t:+n===+t;case"[object Date]":case"[object Boolean]":return+n===+t}var i="[object Array]"===u;if(!i){if("object"!=typeof n||"object"!=typeof t)return!1;var o=n.constructor,a=t.constructor;if(o!==a&&!(m.isFunction(o)&&o instanceof o&&m.isFunction(a)&&a instanceof a)&&"constructor"in n&&"constructor"in t)return!1}r=r||[],e=e||[];for(var c=r.length;c--;)if(r[c]===n)return e[c]===t;if(r.push(n),e.push(t),i){if(c=n.length,c!==t.length)return!1;for(;c--;)if(!E(n[c],t[c],r,e))return!1}else{var f,s=m.keys(n);if(c=s.length,m.keys(t).length!==c)return!1;for(;c--;)if(f=s[c],!m.has(t,f)||!E(n[f],t[f],r,e))return!1}return r.pop(),e.pop(),!0};m.isEqual=function(n,t){return E(n,t)},m.isEmpty=function(n){return null==n?!0:w(n)&&(m.isArray(n)||m.isString(n)||m.isArguments(n))?0===n.length:0===m.keys(n).length},m.isElement=function(n){return!(!n||1!==n.nodeType)},m.isArray=p||function(n){return"[object Array]"===l.call(n)},m.isObject=function(n){var t=typeof n;return"function"===t||"object"===t&&!!n},m.each(["Arguments","Function","String","Number","Date","RegExp","Error"],function(n){m["is"+n]=function(t){return l.call(t)==="[object "+n+"]"}}),m.isArguments(arguments)||(m.isArguments=function(n){return m.has(n,"callee")}),"function"!=typeof/./&&"object"!=typeof Int8Array&&(m.isFunction=function(n){return"function"==typeof n||!1}),m.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},m.isNaN=function(n){return m.isNumber(n)&&n!==+n},m.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"===l.call(n)},m.isNull=function(n){return null===n},m.isUndefined=function(n){return n===void 0},m.has=function(n,t){return null!=n&&s.call(n,t)},m.noConflict=function(){return e._=u,this},m.identity=function(n){return n},m.constant=function(n){return function(){return n}},m.noop=function(){},m.property=function(n){return function(t){return null==t?void 0:t[n]}},m.propertyOf=function(n){return null==n?function(){}:function(t){return n[t]}},m.matcher=m.matches=function(n){return n=m.extendOwn({},n),function(t){return m.isMatch(t,n)}},m.times=function(n,t,r){var e=Array(Math.max(0,n));t=d(t,r,1);for(var u=0;n>u;u++)e[u]=t(u);return e},m.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))},m.now=Date.now||function(){return(new Date).getTime()};var M={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},N=m.invert(M),I=function(n){var t=function(t){return n[t]},r="(?:"+m.keys(n).join("|")+")",e=RegExp(r),u=RegExp(r,"g");return function(n){return n=null==n?"":""+n,e.test(n)?n.replace(u,t):n}};m.escape=I(M),m.unescape=I(N),m.result=function(n,t,r){var e=null==n?void 0:n[t];return e===void 0&&(e=r),m.isFunction(e)?e.call(n):e};var B=0;m.uniqueId=function(n){var t=++B+"";return n?n+t:t},m.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var T=/(.)^/,R={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},q=/\\|'|\r|\n|\u2028|\u2029/g,z=function(n){return"\\"+R[n]};m.template=function(n,t,r){!t&&r&&(t=r),t=m.defaults({},t,m.templateSettings);var e=RegExp([(t.escape||T).source,(t.interpolate||T).source,(t.evaluate||T).source].join("|")+"|$","g"),u=0,i="__p+='";n.replace(e,function(t,r,e,o,a){return i+=n.slice(u,a).replace(q,z),u=a+t.length,r?i+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'":e?i+="'+\n((__t=("+e+"))==null?'':__t)+\n'":o&&(i+="';\n"+o+"\n__p+='"),t}),i+="';\n",t.variable||(i="with(obj||{}){\n"+i+"}\n"),i="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+i+"return __p;\n";try{var o=new Function(t.variable||"obj","_",i)}catch(a){throw a.source=i,a}var c=function(n){return o.call(this,n,m)},f=t.variable||"obj";return c.source="function("+f+"){\n"+i+"}",c},m.chain=function(n){var t=m(n);return t._chain=!0,t};var K=function(n,t){return n._chain?m(t).chain():t};m.mixin=function(n){m.each(m.functions(n),function(t){var r=m[t]=n[t];m.prototype[t]=function(){var n=[this._wrapped];return c.apply(n,arguments),K(this,r.apply(m,n))}})},m.mixin(m),m.each(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=i[n];m.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!==n&&"splice"!==n||0!==r.length||delete r[0],K(this,r)}}),m.each(["concat","join","slice"],function(n){var t=i[n];m.prototype[n]=function(){return K(this,t.apply(this._wrapped,arguments))}}),m.prototype.value=function(){return this._wrapped},m.prototype.valueOf=m.prototype.toJSON=m.prototype.value,m.prototype.toString=function(){return""+this._wrapped},"function"==typeof define&&define.amd&&define("underscore",[],function(){return m})}).call(this); | ||
//# sourceMappingURL=underscore-min.map |
@@ -1,4 +0,4 @@ | ||
// Underscore.js 1.7.0 | ||
// Underscore.js 1.8.0 | ||
// http://underscorejs.org | ||
// (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
// (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
// Underscore may be freely distributed under the MIT license. | ||
@@ -24,3 +24,2 @@ | ||
slice = ArrayProto.slice, | ||
concat = ArrayProto.concat, | ||
toString = ObjProto.toString, | ||
@@ -34,4 +33,8 @@ hasOwnProperty = ObjProto.hasOwnProperty; | ||
nativeKeys = Object.keys, | ||
nativeBind = FuncProto.bind; | ||
nativeBind = FuncProto.bind, | ||
nativeCreate = Object.create; | ||
// Reusable constructor function for prototype setting. | ||
var Ctor = function(){}; | ||
// Create a safe reference to the Underscore object for use below. | ||
@@ -57,3 +60,3 @@ var _ = function(obj) { | ||
// Current version. | ||
_.VERSION = '1.7.0'; | ||
_.VERSION = '1.8.0'; | ||
@@ -63,3 +66,3 @@ // Internal function that returns an efficient (for current engines) version | ||
// functions. | ||
var createCallback = function(func, context, argCount) { | ||
var optimizeCb = function(func, context, argCount) { | ||
if (context === void 0) return func; | ||
@@ -88,9 +91,49 @@ switch (argCount == null ? 3 : argCount) { | ||
// identity, an arbitrary callback, a property matcher, or a property accessor. | ||
_.iteratee = function(value, context, argCount) { | ||
var cb = function(value, context, argCount) { | ||
if (value == null) return _.identity; | ||
if (_.isFunction(value)) return createCallback(value, context, argCount); | ||
if (_.isObject(value)) return _.matches(value); | ||
if (_.isFunction(value)) return optimizeCb(value, context, argCount); | ||
if (_.isObject(value)) return _.matcher(value); | ||
return _.property(value); | ||
}; | ||
_.iteratee = function(value, context) { | ||
return cb(value, context, Infinity); | ||
}; | ||
// An internal function for creating assigner functions. | ||
var createAssigner = function(keysFunc, undefinedOnly) { | ||
return function(obj) { | ||
var length = arguments.length; | ||
if (length < 2 || obj == null) return obj; | ||
for (var index = 1; index < length; index++) { | ||
var source = arguments[index], | ||
keys = keysFunc(source), | ||
l = keys.length; | ||
for (var i = 0; i < l; i++) { | ||
var key = keys[i]; | ||
if (!undefinedOnly || obj[key] === void 0) obj[key] = source[key]; | ||
} | ||
} | ||
return obj; | ||
}; | ||
}; | ||
// An internal function for creating a new object that inherits from another. | ||
var baseCreate = function(prototype) { | ||
if (!_.isObject(prototype)) return {}; | ||
if (nativeCreate) return nativeCreate(prototype); | ||
Ctor.prototype = prototype; | ||
var result = new Ctor; | ||
Ctor.prototype = null; | ||
return result; | ||
}; | ||
// Helper for collection methods to determine whether a collection | ||
// should be iterated as an array or as an object | ||
// Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength | ||
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1; | ||
var isArrayLike = function(collection) { | ||
var length = collection && collection.length; | ||
return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX; | ||
}; | ||
// Collection Functions | ||
@@ -103,7 +146,6 @@ // -------------------- | ||
_.each = _.forEach = function(obj, iteratee, context) { | ||
if (obj == null) return obj; | ||
iteratee = createCallback(iteratee, context); | ||
var i, length = obj.length; | ||
if (length === +length) { | ||
for (i = 0; i < length; i++) { | ||
iteratee = optimizeCb(iteratee, context); | ||
var i, length; | ||
if (isArrayLike(obj)) { | ||
for (i = 0, length = obj.length; i < length; i++) { | ||
iteratee(obj[i], i, obj); | ||
@@ -122,10 +164,8 @@ } | ||
_.map = _.collect = function(obj, iteratee, context) { | ||
if (obj == null) return []; | ||
iteratee = _.iteratee(iteratee, context); | ||
var keys = obj.length !== +obj.length && _.keys(obj), | ||
iteratee = cb(iteratee, context); | ||
var keys = !isArrayLike(obj) && _.keys(obj), | ||
length = (keys || obj).length, | ||
results = Array(length), | ||
currentKey; | ||
results = Array(length); | ||
for (var index = 0; index < length; index++) { | ||
currentKey = keys ? keys[index] : index; | ||
var currentKey = keys ? keys[index] : index; | ||
results[index] = iteratee(obj[currentKey], currentKey, obj); | ||
@@ -136,52 +176,44 @@ } | ||
var reduceError = 'Reduce of empty array with no initial value'; | ||
// Create a reducing function iterating left or right. | ||
function createReduce(dir) { | ||
// Optimized iterator function as using arguments.length | ||
// in the main function will deoptimize the, see #1991. | ||
function iterator(obj, iteratee, memo, keys, index, length) { | ||
for (; index >= 0 && index < length; index += dir) { | ||
var currentKey = keys ? keys[index] : index; | ||
memo = iteratee(memo, obj[currentKey], currentKey, obj); | ||
} | ||
return memo; | ||
} | ||
return function(obj, iteratee, memo, context) { | ||
iteratee = optimizeCb(iteratee, context, 4); | ||
var keys = !isArrayLike(obj) && _.keys(obj), | ||
length = (keys || obj).length, | ||
index = dir > 0 ? 0 : length - 1; | ||
// Determine the initial value if none is provided. | ||
if (arguments.length < 3) { | ||
memo = obj[keys ? keys[index] : index]; | ||
index += dir; | ||
} | ||
return iterator(obj, iteratee, memo, keys, index, length); | ||
}; | ||
} | ||
// **Reduce** builds up a single result from a list of values, aka `inject`, | ||
// or `foldl`. | ||
_.reduce = _.foldl = _.inject = function(obj, iteratee, memo, context) { | ||
if (obj == null) obj = []; | ||
iteratee = createCallback(iteratee, context, 4); | ||
var keys = obj.length !== +obj.length && _.keys(obj), | ||
length = (keys || obj).length, | ||
index = 0, currentKey; | ||
if (arguments.length < 3) { | ||
if (!length) throw new TypeError(reduceError); | ||
memo = obj[keys ? keys[index++] : index++]; | ||
} | ||
for (; index < length; index++) { | ||
currentKey = keys ? keys[index] : index; | ||
memo = iteratee(memo, obj[currentKey], currentKey, obj); | ||
} | ||
return memo; | ||
}; | ||
_.reduce = _.foldl = _.inject = createReduce(1); | ||
// The right-associative version of reduce, also known as `foldr`. | ||
_.reduceRight = _.foldr = function(obj, iteratee, memo, context) { | ||
if (obj == null) obj = []; | ||
iteratee = createCallback(iteratee, context, 4); | ||
var keys = obj.length !== + obj.length && _.keys(obj), | ||
index = (keys || obj).length, | ||
currentKey; | ||
if (arguments.length < 3) { | ||
if (!index) throw new TypeError(reduceError); | ||
memo = obj[keys ? keys[--index] : --index]; | ||
} | ||
while (index--) { | ||
currentKey = keys ? keys[index] : index; | ||
memo = iteratee(memo, obj[currentKey], currentKey, obj); | ||
} | ||
return memo; | ||
}; | ||
_.reduceRight = _.foldr = createReduce(-1); | ||
// Return the first value which passes a truth test. Aliased as `detect`. | ||
_.find = _.detect = function(obj, predicate, context) { | ||
var result; | ||
predicate = _.iteratee(predicate, context); | ||
_.some(obj, function(value, index, list) { | ||
if (predicate(value, index, list)) { | ||
result = value; | ||
return true; | ||
} | ||
}); | ||
return result; | ||
var key; | ||
if (isArrayLike(obj)) { | ||
key = _.findIndex(obj, predicate, context); | ||
} else { | ||
key = _.findKey(obj, predicate, context); | ||
} | ||
if (key !== void 0 && key !== -1) return obj[key]; | ||
}; | ||
@@ -193,4 +225,3 @@ | ||
var results = []; | ||
if (obj == null) return results; | ||
predicate = _.iteratee(predicate, context); | ||
predicate = cb(predicate, context); | ||
_.each(obj, function(value, index, list) { | ||
@@ -204,3 +235,3 @@ if (predicate(value, index, list)) results.push(value); | ||
_.reject = function(obj, predicate, context) { | ||
return _.filter(obj, _.negate(_.iteratee(predicate)), context); | ||
return _.filter(obj, _.negate(cb(predicate)), context); | ||
}; | ||
@@ -211,9 +242,7 @@ | ||
_.every = _.all = function(obj, predicate, context) { | ||
if (obj == null) return true; | ||
predicate = _.iteratee(predicate, context); | ||
var keys = obj.length !== +obj.length && _.keys(obj), | ||
length = (keys || obj).length, | ||
index, currentKey; | ||
for (index = 0; index < length; index++) { | ||
currentKey = keys ? keys[index] : index; | ||
predicate = cb(predicate, context); | ||
var keys = !isArrayLike(obj) && _.keys(obj), | ||
length = (keys || obj).length; | ||
for (var index = 0; index < length; index++) { | ||
var currentKey = keys ? keys[index] : index; | ||
if (!predicate(obj[currentKey], currentKey, obj)) return false; | ||
@@ -227,9 +256,7 @@ } | ||
_.some = _.any = function(obj, predicate, context) { | ||
if (obj == null) return false; | ||
predicate = _.iteratee(predicate, context); | ||
var keys = obj.length !== +obj.length && _.keys(obj), | ||
length = (keys || obj).length, | ||
index, currentKey; | ||
for (index = 0; index < length; index++) { | ||
currentKey = keys ? keys[index] : index; | ||
predicate = cb(predicate, context); | ||
var keys = !isArrayLike(obj) && _.keys(obj), | ||
length = (keys || obj).length; | ||
for (var index = 0; index < length; index++) { | ||
var currentKey = keys ? keys[index] : index; | ||
if (predicate(obj[currentKey], currentKey, obj)) return true; | ||
@@ -241,6 +268,5 @@ } | ||
// Determine if the array or object contains a given value (using `===`). | ||
// Aliased as `include`. | ||
_.contains = _.include = function(obj, target) { | ||
if (obj == null) return false; | ||
if (obj.length !== +obj.length) obj = _.values(obj); | ||
// Aliased as `includes` and `include`. | ||
_.contains = _.includes = _.include = function(obj, target) { | ||
if (!isArrayLike(obj)) obj = _.values(obj); | ||
return _.indexOf(obj, target) >= 0; | ||
@@ -254,3 +280,4 @@ }; | ||
return _.map(obj, function(value) { | ||
return (isFunc ? method : value[method]).apply(value, args); | ||
var func = isFunc ? method : value[method]; | ||
return func == null ? func : func.apply(value, args); | ||
}); | ||
@@ -267,3 +294,3 @@ }; | ||
_.where = function(obj, attrs) { | ||
return _.filter(obj, _.matches(attrs)); | ||
return _.filter(obj, _.matcher(attrs)); | ||
}; | ||
@@ -274,3 +301,3 @@ | ||
_.findWhere = function(obj, attrs) { | ||
return _.find(obj, _.matches(attrs)); | ||
return _.find(obj, _.matcher(attrs)); | ||
}; | ||
@@ -283,3 +310,3 @@ | ||
if (iteratee == null && obj != null) { | ||
obj = obj.length === +obj.length ? obj : _.values(obj); | ||
obj = isArrayLike(obj) ? obj : _.values(obj); | ||
for (var i = 0, length = obj.length; i < length; i++) { | ||
@@ -292,3 +319,3 @@ value = obj[i]; | ||
} else { | ||
iteratee = _.iteratee(iteratee, context); | ||
iteratee = cb(iteratee, context); | ||
_.each(obj, function(value, index, list) { | ||
@@ -310,3 +337,3 @@ computed = iteratee(value, index, list); | ||
if (iteratee == null && obj != null) { | ||
obj = obj.length === +obj.length ? obj : _.values(obj); | ||
obj = isArrayLike(obj) ? obj : _.values(obj); | ||
for (var i = 0, length = obj.length; i < length; i++) { | ||
@@ -319,3 +346,3 @@ value = obj[i]; | ||
} else { | ||
iteratee = _.iteratee(iteratee, context); | ||
iteratee = cb(iteratee, context); | ||
_.each(obj, function(value, index, list) { | ||
@@ -335,3 +362,3 @@ computed = iteratee(value, index, list); | ||
_.shuffle = function(obj) { | ||
var set = obj && obj.length === +obj.length ? obj : _.values(obj); | ||
var set = isArrayLike(obj) ? obj : _.values(obj); | ||
var length = set.length; | ||
@@ -352,3 +379,3 @@ var shuffled = Array(length); | ||
if (n == null || guard) { | ||
if (obj.length !== +obj.length) obj = _.values(obj); | ||
if (!isArrayLike(obj)) obj = _.values(obj); | ||
return obj[_.random(obj.length - 1)]; | ||
@@ -361,3 +388,3 @@ } | ||
_.sortBy = function(obj, iteratee, context) { | ||
iteratee = _.iteratee(iteratee, context); | ||
iteratee = cb(iteratee, context); | ||
return _.pluck(_.map(obj, function(value, index, list) { | ||
@@ -384,3 +411,3 @@ return { | ||
var result = {}; | ||
iteratee = _.iteratee(iteratee, context); | ||
iteratee = cb(iteratee, context); | ||
_.each(obj, function(value, index) { | ||
@@ -413,15 +440,2 @@ var key = iteratee(value, index, obj); | ||
// Use a comparator function to figure out the smallest index at which | ||
// an object should be inserted so as to maintain order. Uses binary search. | ||
_.sortedIndex = function(array, obj, iteratee, context) { | ||
iteratee = _.iteratee(iteratee, context, 1); | ||
var value = iteratee(obj); | ||
var low = 0, high = array.length; | ||
while (low < high) { | ||
var mid = low + high >>> 1; | ||
if (iteratee(array[mid]) < value) low = mid + 1; else high = mid; | ||
} | ||
return low; | ||
}; | ||
// Safely create a real, live array from anything iterable. | ||
@@ -431,3 +445,3 @@ _.toArray = function(obj) { | ||
if (_.isArray(obj)) return slice.call(obj); | ||
if (obj.length === +obj.length) return _.map(obj, _.identity); | ||
if (isArrayLike(obj)) return _.map(obj, _.identity); | ||
return _.values(obj); | ||
@@ -439,3 +453,3 @@ }; | ||
if (obj == null) return 0; | ||
return obj.length === +obj.length ? obj.length : _.keys(obj).length; | ||
return isArrayLike(obj) ? obj.length : _.keys(obj).length; | ||
}; | ||
@@ -446,3 +460,3 @@ | ||
_.partition = function(obj, predicate, context) { | ||
predicate = _.iteratee(predicate, context); | ||
predicate = cb(predicate, context); | ||
var pass = [], fail = []; | ||
@@ -464,4 +478,3 @@ _.each(obj, function(value, key, obj) { | ||
if (n == null || guard) return array[0]; | ||
if (n < 0) return []; | ||
return slice.call(array, 0, n); | ||
return _.initial(array, array.length - n); | ||
}; | ||
@@ -471,4 +484,3 @@ | ||
// the arguments object. Passing **n** will return all the values in | ||
// the array, excluding the last N. The **guard** check allows it to work with | ||
// `_.map`. | ||
// the array, excluding the last N. | ||
_.initial = function(array, n, guard) { | ||
@@ -479,7 +491,7 @@ return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n))); | ||
// Get the last element of an array. Passing **n** will return the last N | ||
// values in the array. The **guard** check allows it to work with `_.map`. | ||
// values in the array. | ||
_.last = function(array, n, guard) { | ||
if (array == null) return void 0; | ||
if (n == null || guard) return array[array.length - 1]; | ||
return slice.call(array, Math.max(array.length - n, 0)); | ||
return _.rest(array, Math.max(0, array.length - n)); | ||
}; | ||
@@ -489,4 +501,3 @@ | ||
// Especially useful on the arguments object. Passing an **n** will return | ||
// the rest N values in the array. The **guard** | ||
// check allows it to work with `_.map`. | ||
// the rest N values in the array. | ||
_.rest = _.tail = _.drop = function(array, n, guard) { | ||
@@ -502,14 +513,16 @@ return slice.call(array, n == null || guard ? 1 : n); | ||
// Internal implementation of a recursive `flatten` function. | ||
var flatten = function(input, shallow, strict, output) { | ||
if (shallow && _.every(input, _.isArray)) { | ||
return concat.apply(output, input); | ||
} | ||
for (var i = 0, length = input.length; i < length; i++) { | ||
var flatten = function(input, shallow, strict, startIndex) { | ||
var output = [], idx = 0; | ||
for (var i = startIndex || 0, length = input && input.length; i < length; i++) { | ||
var value = input[i]; | ||
if (!_.isArray(value) && !_.isArguments(value)) { | ||
if (!strict) output.push(value); | ||
} else if (shallow) { | ||
push.apply(output, value); | ||
} else { | ||
flatten(value, shallow, strict, output); | ||
if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) { | ||
//flatten current level of array or arguments object | ||
if (!shallow) value = flatten(value, shallow, strict); | ||
var j = 0, len = value.length; | ||
output.length += len; | ||
while (j < len) { | ||
output[idx++] = value[j++]; | ||
} | ||
} else if (!strict) { | ||
output[idx++] = value; | ||
} | ||
@@ -522,3 +535,3 @@ } | ||
_.flatten = function(array, shallow) { | ||
return flatten(array, shallow, false, []); | ||
return flatten(array, shallow, false); | ||
}; | ||
@@ -541,17 +554,17 @@ | ||
} | ||
if (iteratee != null) iteratee = _.iteratee(iteratee, context); | ||
if (iteratee != null) iteratee = cb(iteratee, context); | ||
var result = []; | ||
var seen = []; | ||
for (var i = 0, length = array.length; i < length; i++) { | ||
var value = array[i]; | ||
var value = array[i], | ||
computed = iteratee ? iteratee(value, i, array) : value; | ||
if (isSorted) { | ||
if (!i || seen !== value) result.push(value); | ||
seen = value; | ||
if (!i || seen !== computed) result.push(value); | ||
seen = computed; | ||
} else if (iteratee) { | ||
var computed = iteratee(value, i, array); | ||
if (_.indexOf(seen, computed) < 0) { | ||
if (!_.contains(seen, computed)) { | ||
seen.push(computed); | ||
result.push(value); | ||
} | ||
} else if (_.indexOf(result, value) < 0) { | ||
} else if (!_.contains(result, value)) { | ||
result.push(value); | ||
@@ -566,3 +579,3 @@ } | ||
_.union = function() { | ||
return _.uniq(flatten(arguments, true, true, [])); | ||
return _.uniq(flatten(arguments, true, true)); | ||
}; | ||
@@ -590,3 +603,3 @@ | ||
_.difference = function(array) { | ||
var rest = flatten(slice.call(arguments, 1), true, true, []); | ||
var rest = flatten(arguments, true, true, 1); | ||
return _.filter(array, function(value){ | ||
@@ -599,10 +612,16 @@ return !_.contains(rest, value); | ||
// an index go together. | ||
_.zip = function(array) { | ||
if (array == null) return []; | ||
var length = _.max(arguments, 'length').length; | ||
var results = Array(length); | ||
for (var i = 0; i < length; i++) { | ||
results[i] = _.pluck(arguments, i); | ||
_.zip = function() { | ||
return _.unzip(arguments); | ||
}; | ||
// Complement of _.zip. Unzip accepts an array of arrays and groups | ||
// each array's elements on shared indices | ||
_.unzip = function(array) { | ||
var length = array && _.max(array, 'length').length || 0; | ||
var result = Array(length); | ||
for (var index = 0; index < length; index++) { | ||
result[index] = _.pluck(array, index); | ||
} | ||
return results; | ||
return result; | ||
}; | ||
@@ -614,5 +633,4 @@ | ||
_.object = function(list, values) { | ||
if (list == null) return {}; | ||
var result = {}; | ||
for (var i = 0, length = list.length; i < length; i++) { | ||
for (var i = 0, length = list && list.length; i < length; i++) { | ||
if (values) { | ||
@@ -632,12 +650,12 @@ result[list[i]] = values[i]; | ||
_.indexOf = function(array, item, isSorted) { | ||
if (array == null) return -1; | ||
var i = 0, length = array.length; | ||
if (isSorted) { | ||
if (typeof isSorted == 'number') { | ||
i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted; | ||
} else { | ||
i = _.sortedIndex(array, item); | ||
return array[i] === item ? i : -1; | ||
} | ||
var i = 0, length = array && array.length; | ||
if (typeof isSorted == 'number') { | ||
i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted; | ||
} else if (isSorted && length) { | ||
i = _.sortedIndex(array, item); | ||
return array[i] === item ? i : -1; | ||
} | ||
if (item !== item) { | ||
return _.findIndex(slice.call(array, i), _.isNaN); | ||
} | ||
for (; i < length; i++) if (array[i] === item) return i; | ||
@@ -648,7 +666,9 @@ return -1; | ||
_.lastIndexOf = function(array, item, from) { | ||
if (array == null) return -1; | ||
var idx = array.length; | ||
var idx = array ? array.length : 0; | ||
if (typeof from == 'number') { | ||
idx = from < 0 ? idx + from + 1 : Math.min(idx, from + 1); | ||
} | ||
if (item !== item) { | ||
return _.findLastIndex(slice.call(array, 0, idx), _.isNaN); | ||
} | ||
while (--idx >= 0) if (array[idx] === item) return idx; | ||
@@ -658,2 +678,33 @@ return -1; | ||
// Generator function to create the findIndex and findLastIndex functions | ||
function createIndexFinder(dir) { | ||
return function(array, predicate, context) { | ||
predicate = cb(predicate, context); | ||
var length = array != null && array.length; | ||
var index = dir > 0 ? 0 : length - 1; | ||
for (; index >= 0 && index < length; index += dir) { | ||
if (predicate(array[index], index, array)) return index; | ||
} | ||
return -1; | ||
}; | ||
} | ||
// Returns the first index on an array-like that passes a predicate test | ||
_.findIndex = createIndexFinder(1); | ||
_.findLastIndex = createIndexFinder(-1); | ||
// Use a comparator function to figure out the smallest index at which | ||
// an object should be inserted so as to maintain order. Uses binary search. | ||
_.sortedIndex = function(array, obj, iteratee, context) { | ||
iteratee = cb(iteratee, context, 1); | ||
var value = iteratee(obj); | ||
var low = 0, high = array.length; | ||
while (low < high) { | ||
var mid = Math.floor((low + high) / 2); | ||
if (iteratee(array[mid]) < value) low = mid + 1; else high = mid; | ||
} | ||
return low; | ||
}; | ||
// Generate an integer Array containing an arithmetic progression. A port of | ||
@@ -682,4 +733,11 @@ // the native Python `range()` function. See | ||
// Reusable constructor function for prototype setting. | ||
var Ctor = function(){}; | ||
// Determines whether to execute a function as a constructor | ||
// or a normal function with the provided arguments | ||
var executeBound = function(sourceFunc, boundFunc, context, callingContext, args) { | ||
if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args); | ||
var self = baseCreate(sourceFunc.prototype); | ||
var result = sourceFunc.apply(self, args); | ||
if (_.isObject(result)) return result; | ||
return self; | ||
}; | ||
@@ -690,16 +748,8 @@ // Create a function bound to a given object (assigning `this`, and arguments, | ||
_.bind = function(func, context) { | ||
var args, bound; | ||
if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); | ||
if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function'); | ||
args = slice.call(arguments, 2); | ||
bound = function() { | ||
if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments))); | ||
Ctor.prototype = func.prototype; | ||
var self = new Ctor; | ||
Ctor.prototype = null; | ||
var result = func.apply(self, args.concat(slice.call(arguments))); | ||
if (_.isObject(result)) return result; | ||
return self; | ||
var args = slice.call(arguments, 2); | ||
return function bound() { | ||
return executeBound(func, bound, context, this, args.concat(slice.call(arguments))); | ||
}; | ||
return bound; | ||
}; | ||
@@ -712,10 +762,10 @@ | ||
var boundArgs = slice.call(arguments, 1); | ||
return function() { | ||
var position = 0; | ||
var args = boundArgs.slice(); | ||
for (var i = 0, length = args.length; i < length; i++) { | ||
if (args[i] === _) args[i] = arguments[position++]; | ||
return function bound() { | ||
var position = 0, length = boundArgs.length; | ||
var args = Array(length); | ||
for (var i = 0; i < length; i++) { | ||
args[i] = boundArgs[i] === _ ? arguments[position++] : boundArgs[i]; | ||
} | ||
while (position < arguments.length) args.push(arguments[position++]); | ||
return func.apply(this, args); | ||
return executeBound(func, bound, this, this, args); | ||
}; | ||
@@ -741,3 +791,3 @@ }; | ||
var cache = memoize.cache; | ||
var address = hasher ? hasher.apply(this, arguments) : key; | ||
var address = '' + (hasher ? hasher.apply(this, arguments) : key); | ||
if (!_.has(cache, address)) cache[address] = func.apply(this, arguments); | ||
@@ -761,5 +811,3 @@ return cache[address]; | ||
// cleared. | ||
_.defer = function(func) { | ||
return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1))); | ||
}; | ||
_.defer = _.partial(_.delay, _, 1); | ||
@@ -789,4 +837,6 @@ // Returns a function, that, when invoked, will only be triggered at most once | ||
if (remaining <= 0 || remaining > wait) { | ||
clearTimeout(timeout); | ||
timeout = null; | ||
if (timeout) { | ||
clearTimeout(timeout); | ||
timeout = null; | ||
} | ||
previous = now; | ||
@@ -812,3 +862,3 @@ result = func.apply(context, args); | ||
if (last < wait && last > 0) { | ||
if (last < wait && last >= 0) { | ||
timeout = setTimeout(later, wait - last); | ||
@@ -866,3 +916,3 @@ } else { | ||
// Returns a function that will only be executed after being called N times. | ||
// Returns a function that will only be executed on and after the Nth call. | ||
_.after = function(times, func) { | ||
@@ -876,3 +926,3 @@ return function() { | ||
// Returns a function that will only be executed before being called N times. | ||
// Returns a function that will only be executed up to (but not including) the Nth call. | ||
_.before = function(times, func) { | ||
@@ -883,5 +933,4 @@ var memo; | ||
memo = func.apply(this, arguments); | ||
} else { | ||
func = null; | ||
} | ||
if (times <= 1) func = null; | ||
return memo; | ||
@@ -898,3 +947,21 @@ }; | ||
// Retrieve the names of an object's properties. | ||
// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed. | ||
var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString'); | ||
var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString', | ||
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; | ||
function collectNonEnumProps(obj, keys) { | ||
var nonEnumIdx = nonEnumerableProps.length; | ||
var proto = typeof obj.constructor === 'function' ? FuncProto : ObjProto; | ||
while (nonEnumIdx--) { | ||
var prop = nonEnumerableProps[nonEnumIdx]; | ||
if (prop === 'constructor' ? _.has(obj, prop) : prop in obj && | ||
obj[prop] !== proto[prop] && !_.contains(keys, prop)) { | ||
keys.push(prop); | ||
} | ||
} | ||
} | ||
// Retrieve the names of an object's own properties. | ||
// Delegates to **ECMAScript 5**'s native `Object.keys` | ||
@@ -906,5 +973,17 @@ _.keys = function(obj) { | ||
for (var key in obj) if (_.has(obj, key)) keys.push(key); | ||
// Ahem, IE < 9. | ||
if (hasEnumBug) collectNonEnumProps(obj, keys); | ||
return keys; | ||
}; | ||
// Retrieve all the property names of an object. | ||
_.allKeys = function(obj) { | ||
if (!_.isObject(obj)) return []; | ||
var keys = []; | ||
for (var key in obj) keys.push(key); | ||
// Ahem, IE < 9. | ||
if (hasEnumBug) collectNonEnumProps(obj, keys); | ||
return keys; | ||
}; | ||
// Retrieve the values of an object's properties. | ||
@@ -921,2 +1000,17 @@ _.values = function(obj) { | ||
// Returns the results of applying the iteratee to each element of the object | ||
// In contrast to _.map it returns an object | ||
_.mapObject = function(obj, iteratee, context) { | ||
iteratee = cb(iteratee, context); | ||
var keys = _.keys(obj), | ||
length = keys.length, | ||
results = {}, | ||
currentKey; | ||
for (var index = 0; index < length; index++) { | ||
currentKey = keys[index]; | ||
results[currentKey] = iteratee(obj[currentKey], currentKey, obj); | ||
} | ||
return results; | ||
}; | ||
// Convert an object into a list of `[key, value]` pairs. | ||
@@ -954,14 +1048,16 @@ _.pairs = function(obj) { | ||
// Extend a given object with all the properties in passed-in object(s). | ||
_.extend = function(obj) { | ||
if (!_.isObject(obj)) return obj; | ||
var source, prop; | ||
for (var i = 1, length = arguments.length; i < length; i++) { | ||
source = arguments[i]; | ||
for (prop in source) { | ||
if (hasOwnProperty.call(source, prop)) { | ||
obj[prop] = source[prop]; | ||
} | ||
} | ||
_.extend = createAssigner(_.allKeys); | ||
// Assigns a given object with all the own properties in the passed-in object(s) | ||
// (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) | ||
_.extendOwn = createAssigner(_.keys); | ||
// Returns the first key on an object that passes a predicate test | ||
_.findKey = function(obj, predicate, context) { | ||
predicate = cb(predicate, context); | ||
var keys = _.keys(obj), key; | ||
for (var i = 0, length = keys.length; i < length; i++) { | ||
key = keys[i]; | ||
if (predicate(obj[key], key, obj)) return key; | ||
} | ||
return obj; | ||
}; | ||
@@ -974,3 +1070,3 @@ | ||
if (_.isFunction(iteratee)) { | ||
iteratee = createCallback(iteratee, context); | ||
iteratee = optimizeCb(iteratee, context); | ||
for (key in obj) { | ||
@@ -981,3 +1077,3 @@ var value = obj[key]; | ||
} else { | ||
var keys = concat.apply([], slice.call(arguments, 1)); | ||
var keys = flatten(arguments, false, false, 1); | ||
obj = new Object(obj); | ||
@@ -997,3 +1093,3 @@ for (var i = 0, length = keys.length; i < length; i++) { | ||
} else { | ||
var keys = _.map(concat.apply([], slice.call(arguments, 1)), String); | ||
var keys = _.map(flatten(arguments, false, false, 1), String); | ||
iteratee = function(value, key) { | ||
@@ -1007,12 +1103,3 @@ return !_.contains(keys, key); | ||
// Fill in a given object with default properties. | ||
_.defaults = function(obj) { | ||
if (!_.isObject(obj)) return obj; | ||
for (var i = 1, length = arguments.length; i < length; i++) { | ||
var source = arguments[i]; | ||
for (var prop in source) { | ||
if (obj[prop] === void 0) obj[prop] = source[prop]; | ||
} | ||
} | ||
return obj; | ||
}; | ||
_.defaults = createAssigner(_.allKeys, true); | ||
@@ -1033,2 +1120,15 @@ // Create a (shallow-cloned) duplicate of an object. | ||
// Returns whether an object has a given set of `key:value` pairs. | ||
_.isMatch = function(object, attrs) { | ||
var keys = _.keys(attrs), length = keys.length; | ||
if (object == null) return !length; | ||
var obj = Object(object); | ||
for (var i = 0; i < length; i++) { | ||
var key = keys[i]; | ||
if (attrs[key] !== obj[key] || !(key in obj)) return false; | ||
} | ||
return true; | ||
}; | ||
// Internal recursive comparison function for `isEqual`. | ||
@@ -1068,5 +1168,23 @@ var eq = function(a, b, aStack, bStack) { | ||
} | ||
if (typeof a != 'object' || typeof b != 'object') return false; | ||
var areArrays = className === '[object Array]'; | ||
if (!areArrays) { | ||
if (typeof a != 'object' || typeof b != 'object') return false; | ||
// Objects with different constructors are not equivalent, but `Object`s or `Array`s | ||
// from different frames are. | ||
var aCtor = a.constructor, bCtor = b.constructor; | ||
if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor && | ||
_.isFunction(bCtor) && bCtor instanceof bCtor) | ||
&& ('constructor' in a && 'constructor' in b)) { | ||
return false; | ||
} | ||
} | ||
// Assume equality for cyclic structures. The algorithm for detecting cyclic | ||
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. | ||
// Initializing stack of traversed objects. | ||
// It's done here since we only need them for objects and arrays comparison. | ||
aStack = aStack || []; | ||
bStack = bStack || []; | ||
var length = aStack.length; | ||
@@ -1078,28 +1196,15 @@ while (length--) { | ||
} | ||
// Objects with different constructors are not equivalent, but `Object`s | ||
// from different frames are. | ||
var aCtor = a.constructor, bCtor = b.constructor; | ||
if ( | ||
aCtor !== bCtor && | ||
// Handle Object.create(x) cases | ||
'constructor' in a && 'constructor' in b && | ||
!(_.isFunction(aCtor) && aCtor instanceof aCtor && | ||
_.isFunction(bCtor) && bCtor instanceof bCtor) | ||
) { | ||
return false; | ||
} | ||
// Add the first object to the stack of traversed objects. | ||
aStack.push(a); | ||
bStack.push(b); | ||
var size, result; | ||
// Recursively compare objects and arrays. | ||
if (className === '[object Array]') { | ||
if (areArrays) { | ||
// Compare array lengths to determine if a deep comparison is necessary. | ||
size = a.length; | ||
result = size === b.length; | ||
if (result) { | ||
// Deep compare the contents, ignoring non-numeric properties. | ||
while (size--) { | ||
if (!(result = eq(a[size], b[size], aStack, bStack))) break; | ||
} | ||
length = a.length; | ||
if (length !== b.length) return false; | ||
// Deep compare the contents, ignoring non-numeric properties. | ||
while (length--) { | ||
if (!eq(a[length], b[length], aStack, bStack)) return false; | ||
} | ||
@@ -1109,11 +1214,9 @@ } else { | ||
var keys = _.keys(a), key; | ||
size = keys.length; | ||
length = keys.length; | ||
// Ensure that both objects contain the same number of properties before comparing deep equality. | ||
result = _.keys(b).length === size; | ||
if (result) { | ||
while (size--) { | ||
// Deep compare each member | ||
key = keys[size]; | ||
if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break; | ||
} | ||
if (_.keys(b).length !== length) return false; | ||
while (length--) { | ||
// Deep compare each member | ||
key = keys[length]; | ||
if (!(_.has(b, key) && eq(a[key], b[key], aStack, bStack))) return false; | ||
} | ||
@@ -1124,3 +1227,3 @@ } | ||
bStack.pop(); | ||
return result; | ||
return true; | ||
}; | ||
@@ -1130,3 +1233,3 @@ | ||
_.isEqual = function(a, b) { | ||
return eq(a, b, [], []); | ||
return eq(a, b); | ||
}; | ||
@@ -1138,5 +1241,4 @@ | ||
if (obj == null) return true; | ||
if (_.isArray(obj) || _.isString(obj) || _.isArguments(obj)) return obj.length === 0; | ||
for (var key in obj) if (_.has(obj, key)) return false; | ||
return true; | ||
if (isArrayLike(obj) && (_.isArray(obj) || _.isString(obj) || _.isArguments(obj))) return obj.length === 0; | ||
return _.keys(obj).length === 0; | ||
}; | ||
@@ -1161,4 +1263,4 @@ | ||
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp. | ||
_.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) { | ||
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError. | ||
_.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function(name) { | ||
_['is' + name] = function(obj) { | ||
@@ -1169,3 +1271,3 @@ return toString.call(obj) === '[object ' + name + ']'; | ||
// Define a fallback version of the method in browsers (ahem, IE), where | ||
// Define a fallback version of the method in browsers (ahem, IE < 9), where | ||
// there isn't any inspectable "Arguments" type. | ||
@@ -1178,4 +1280,5 @@ if (!_.isArguments(arguments)) { | ||
// Optimize `isFunction` if appropriate. Work around an IE 11 bug. | ||
if (typeof /./ !== 'function') { | ||
// Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8, | ||
// IE 11 (#1621), and in Safari 8 (#1929). | ||
if (typeof /./ != 'function' && typeof Int8Array != 'object') { | ||
_.isFunction = function(obj) { | ||
@@ -1232,2 +1335,3 @@ return typeof obj == 'function' || false; | ||
// Predicate-generating functions. Often useful outside of Underscore. | ||
_.constant = function(value) { | ||
@@ -1243,2 +1347,9 @@ return function() { | ||
return function(obj) { | ||
return obj == null ? void 0 : obj[key]; | ||
}; | ||
}; | ||
// Generates a function for a given object that returns a given property. | ||
_.propertyOf = function(obj) { | ||
return obj == null ? function(){} : function(key) { | ||
return obj[key]; | ||
@@ -1248,13 +1359,8 @@ }; | ||
// Returns a predicate for checking whether an object has a given set of `key:value` pairs. | ||
_.matches = function(attrs) { | ||
var pairs = _.pairs(attrs), length = pairs.length; | ||
// Returns a predicate for checking whether an object has a given set of | ||
// `key:value` pairs. | ||
_.matcher = _.matches = function(attrs) { | ||
attrs = _.extendOwn({}, attrs); | ||
return function(obj) { | ||
if (obj == null) return !length; | ||
obj = new Object(obj); | ||
for (var i = 0; i < length; i++) { | ||
var pair = pairs[i], key = pair[0]; | ||
if (pair[1] !== obj[key] || !(key in obj)) return false; | ||
} | ||
return true; | ||
return _.isMatch(obj, attrs); | ||
}; | ||
@@ -1266,3 +1372,3 @@ }; | ||
var accum = Array(Math.max(0, n)); | ||
iteratee = createCallback(iteratee, context, 1); | ||
iteratee = optimizeCb(iteratee, context, 1); | ||
for (var i = 0; i < n; i++) accum[i] = iteratee(i); | ||
@@ -1316,6 +1422,8 @@ return accum; | ||
// `object` as context; otherwise, return it. | ||
_.result = function(object, property) { | ||
if (object == null) return void 0; | ||
var value = object[property]; | ||
return _.isFunction(value) ? object[property]() : value; | ||
_.result = function(object, property, fallback) { | ||
var value = object == null ? void 0 : object[property]; | ||
if (value === void 0) { | ||
value = fallback; | ||
} | ||
return _.isFunction(value) ? value.call(object) : value; | ||
}; | ||
@@ -1435,4 +1543,4 @@ | ||
// Helper function to continue chaining intermediate results. | ||
var result = function(obj) { | ||
return this._chain ? _(obj).chain() : obj; | ||
var result = function(instance, obj) { | ||
return instance._chain ? _(obj).chain() : obj; | ||
}; | ||
@@ -1447,3 +1555,3 @@ | ||
push.apply(args, arguments); | ||
return result.call(this, func.apply(_, args)); | ||
return result(this, func.apply(_, args)); | ||
}; | ||
@@ -1463,3 +1571,3 @@ }); | ||
if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0]; | ||
return result.call(this, obj); | ||
return result(this, obj); | ||
}; | ||
@@ -1472,3 +1580,3 @@ }); | ||
_.prototype[name] = function() { | ||
return result.call(this, method.apply(this._wrapped, arguments)); | ||
return result(this, method.apply(this._wrapped, arguments)); | ||
}; | ||
@@ -1482,2 +1590,10 @@ }); | ||
// Provide unwrapping proxy for some methods used in engine operations | ||
// such as arithmetic and JSON stringification. | ||
_.prototype.valueOf = _.prototype.toJSON = _.prototype.value; | ||
_.prototype.toString = function() { | ||
return '' + this._wrapped; | ||
}; | ||
// AMD registration happens at the end for compatibility with AMD loaders | ||
@@ -1484,0 +1600,0 @@ // that may not enforce next-turn semantics on modules. Even though general |
Sorry, the diff of this file is not supported yet
99416
6
1422
6