syriastreet.com/assets/js/lib/underscore.js

1 line
14 KiB
JavaScript
Raw Normal View History

2023-07-19 13:53:58 +00:00
(function(){var n=this,t=n._,r={},e=Array.prototype,i=Object.prototype,u=Function.prototype,o=e.push,a=e.slice,c=e.concat,l=i.toString,f=i.hasOwnProperty,s=e.forEach,p=e.map,h=e.reduce,v=e.reduceRight,y=e.filter,d=e.every,g=e.some,m=e.indexOf,b=e.lastIndexOf,x=Array.isArray,w=Object.keys,_=u.bind,j=function(n){return n instanceof j?n:this instanceof j?void(this._wrapped=n):new j(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=j),exports._=j):n._=j,j.VERSION="1.6.0";var A=j.each=j.forEach=function(n,t,e){if(null==n)return n;if(s&&n.forEach===s)n.forEach(t,e);else if(n.length===+n.length){for(var i=0,u=n.length;i<u;i++)if(t.call(e,n[i],i,n)===r)return}else for(var o=j.keys(n),i=0,u=o.length;i<u;i++)if(t.call(e,n[o[i]],o[i],n)===r)return;return n};j.map=j.collect=function(n,t,r){var e=[];return null==n?e:p&&n.map===p?n.map(t,r):(A(n,function(n,i,u){e.push(t.call(r,n,i,u))}),e)};var O="Reduce of empty array with no initial value";j.reduce=j.foldl=j.inject=function(n,t,r,e){var i=arguments.length>2;if(null==n&&(n=[]),h&&n.reduce===h)return e&&(t=j.bind(t,e)),i?n.reduce(t,r):n.reduce(t);if(A(n,function(n,u,o){i?r=t.call(e,r,n,u,o):(r=n,i=!0)}),!i)throw new TypeError(O);return r},j.reduceRight=j.foldr=function(n,t,r,e){var i=arguments.length>2;if(null==n&&(n=[]),v&&n.reduceRight===v)return e&&(t=j.bind(t,e)),i?n.reduceRight(t,r):n.reduceRight(t);var u=n.length;if(u!==+u){var o=j.keys(n);u=o.length}if(A(n,function(a,c,l){c=o?o[--u]:--u,i?r=t.call(e,r,n[c],c,l):(r=n[c],i=!0)}),!i)throw new TypeError(O);return r},j.find=j.detect=function(n,t,r){var e;return k(n,function(n,i,u){if(t.call(r,n,i,u))return e=n,!0}),e},j.filter=j.select=function(n,t,r){var e=[];return null==n?e:y&&n.filter===y?n.filter(t,r):(A(n,function(n,i,u){t.call(r,n,i,u)&&e.push(n)}),e)},j.reject=function(n,t,r){return j.filter(n,function(n,e,i){return!t.call(r,n,e,i)},r)},j.every=j.all=function(n,t,e){t||(t=j.identity);var i=!0;return null==n?i:d&&n.every===d?n.every(t,e):(A(n,function(n,u,o){if(!(i=i&&t.call(e,n,u,o)))return r}),!!i)};var k=j.some=j.any=function(n,t,e){t||(t=j.identity);var i=!1;return null==n?i:g&&n.some===g?n.some(t,e):(A(n,function(n,u,o){if(i||(i=t.call(e,n,u,o)))return r}),!!i)};j.contains=j.include=function(n,t){return null!=n&&(m&&n.indexOf===m?n.indexOf(t)!=-1:k(n,function(n){return n===t}))},j.invoke=function(n,t){var r=a.call(arguments,2),e=j.isFunction(t);return j.map(n,function(n){return(e?t:n[t]).apply(n,r)})},j.pluck=function(n,t){return j.map(n,j.property(t))},j.where=function(n,t){return j.filter(n,j.matches(t))},j.findWhere=function(n,t){return j.find(n,j.matches(t))},j.max=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.max.apply(Math,n);var e=-(1/0),i=-(1/0);return A(n,function(n,u,o){var a=t?t.call(r,n,u,o):n;a>i&&(e=n,i=a)}),e},j.min=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.min.apply(Math,n);var e=1/0,i=1/0;return A(n,function(n,u,o){var a=t?t.call(r,n,u,o):n;a<i&&(e=n,i=a)}),e},j.shuffle=function(n){var t,r=0,e=[];return A(n,function(n){t=j.random(r++),e[r-1]=e[t],e[t]=n}),e},j.sample=function(n,t,r){return null==t||r?(n.length!==+n.length&&(n=j.values(n)),n[j.random(n.length-1)]):j.shuffle(n).slice(0,Math.max(0,t))};var E=function(n){return null==n?j.identity:j.isFunction(n)?n:j.property(n)};j.sortBy=function(n,t,r){return t=E(t),j.pluck(j.map(n,function(n,e,i){return{value:n,index:e,criteria:t.call(r,n,e,i)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||void 0===r)return 1;if(r<e||void 0===e)return-1}return n.index-t.index}),"value")};var F=function(n){return function(t,r,e){var i={};return r=E(r),A(t,function(u,o){var a=r.call(e,u,o,t);n(i,a,u)}),i}};j.groupBy=F(function(n,t,r){j.has(n,t)?n[t].push(r):n[t]=[r]}),j.indexBy=F(function(n,t,r){n[t]=r}),j.countBy=F(function(n,t){j.has(n,t)?n[t]++:n[t]=1}),j.sortedIndex=function(n,t,r,e){r=E(r);for(var i=r.call(e,t),u=0,o=n.length;u<o;){var a=u+o>>>1;r.call(e,n[a])<i?u=a+1:o=a}return u},j.toArray=function(n){return n?j.isArray(n)?a.ca