diff --git a/dist/itemsjs.js b/dist/itemsjs.js index c745cd0..ce18b27 100644 --- a/dist/itemsjs.js +++ b/dist/itemsjs.js @@ -2452,8 +2452,12 @@ module.exports.aggregation = function (items, input, aggregations) { module.exports.sorted_items = function (items, sort, sortings) { - if (sortings[sort] && sortings[sort].field) { - return _.orderBy(items, [sortings[sort].field], [sortings[sort].order || 'asc']); + if (sortings && sortings[sort]) { + sort = sortings[sort]; + } + + if (sort.field) { + return _.orderBy(items, sort.field, sort.order || 'asc'); } return items; diff --git a/dist/itemsjs.min.js b/dist/itemsjs.min.js index c0eea5a..fc4d8c1 100644 --- a/dist/itemsjs.min.js +++ b/dist/itemsjs.min.js @@ -1 +1 @@ -(function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"==typeof window?"undefined"==typeof global?"undefined"==typeof self?this:self:global:window,t.itemsjs=e()}})(function(){var W,xn=Math.max;return function(){function s(l,e,n){function t(d,r){if(!e[d]){if(!l[d]){var i="function"==typeof require&&require;if(!r&&i)return i(d,!0);if(o)return o(d,!0);var c=new Error("Cannot find module '"+d+"'");throw c.code="MODULE_NOT_FOUND",c}var a=e[d]={exports:{}};l[d][0].call(a.exports,function(e){var o=l[d][1][e];return t(o||e)},a,a.exports,s,l,e,n)}return e[d].exports}for(var o="function"==typeof require&&require,r=0;rn.idx?n=n.next:(o+=t.val*n.val,t=t.next,n=n.next);return o},r.Vector.prototype.similarity=function(e){return this.dot(e)/(this.magnitude()*e.magnitude())},r.SortedSet=function(){this.length=0,this.elements=[]},r.SortedSet.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},r.SortedSet.prototype.add=function(){var e,t;for(e=0;ee&&(n=i),r=n-t,i=t+o(r/2),s=this.elements[i]}return s===e?i:-1},r.SortedSet.prototype.locationFor=function(e){for(var t=0,n=this.elements.length,r=n-t,i=t+o(r/2),s=this.elements[i];1e&&(n=i),r=n-t,i=t+o(r/2),s=this.elements[i];return s>e?i:si-1||o>s-1);){if(l[n]===a[o]){t.add(l[n]),n++,o++;continue}if(l[n]a[o]){o++;continue}}return t},r.SortedSet.prototype.clone=function(){var e=new r.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},r.SortedSet.prototype.union=function(e){var t,n,o;this.length>=e.length?(t=this,n=e):(t=e,n=this),o=t.clone();for(var r=0,i=n.toArray();rn.length)return n;if(A=n.substr(0,1),"y"==A&&(n=A.toUpperCase()+n.substr(1)),w=d,F=c,w.test(n)?n=n.replace(w,"$1$2"):F.test(n)&&(n=n.replace(F,"$1$2")),w=p,F=u,w.test(n)){var E=w.exec(n);w=i,w.test(E[1])&&(w=g,n=n.replace(w,""))}else if(F.test(n)){var E=F.exec(n);o=E[1],F=l,F.test(o)&&(n=o,F=f,z=h,O=y,F.test(n)?n+="e":z.test(n)?(w=g,n=n.replace(w,"")):O.test(n)&&(n+="e"))}if(w=_,w.test(n)){var E=w.exec(n);o=E[1],n=o+"i"}if(w=b,w.test(n)){var E=w.exec(n);o=E[1],r=E[2],w=i,w.test(o)&&(n=o+e[r])}if(w=m,w.test(n)){var E=w.exec(n);o=E[1],r=E[2],w=i,w.test(o)&&(n=o+t[r])}if(w=j,F=k,w.test(n)){var E=w.exec(n);o=E[1],w=s,w.test(o)&&(n=o)}else if(F.test(n)){var E=F.exec(n);o=E[1]+E[2],F=s,F.test(o)&&(n=o)}if(w=x,w.test(n)){var E=w.exec(n);o=E[1],w=s,F=a,z=v,(w.test(o)||F.test(o)&&!z.test(o))&&(n=o)}return w=S,F=s,w.test(n)&&F.test(n)&&(w=g,n=n.replace(w,"")),"y"==A&&(n=A.toLowerCase()+n.substr(1)),n}}(),r.Pipeline.registerFunction(r.stemmer,"stemmer"),r.generateStopWordFilter=function(e){var t=e.reduce(function(e,t){return e[t]=t,e},{});return function(e){if(e&&t[e]!==e)return e}},r.stopWordFilter=r.generateStopWordFilter(["a","able","about","across","after","all","almost","also","am","among","an","and","any","are","as","at","be","because","been","but","by","can","cannot","could","dear","did","do","does","either","else","ever","every","for","from","get","got","had","has","have","he","her","hers","him","his","how","however","i","if","in","into","is","it","its","just","least","let","like","likely","may","me","might","most","must","my","neither","no","nor","not","of","off","often","on","only","or","other","our","own","rather","said","say","says","she","should","since","so","some","than","that","the","their","them","then","there","these","they","this","tis","to","too","twas","us","wants","was","we","were","what","when","where","which","while","who","whom","why","will","with","would","yet","you","your"]),r.Pipeline.registerFunction(r.stopWordFilter,"stopWordFilter"),r.trimmer=function(e){return e.replace(/^\W+/,"").replace(/\W+$/,"")},r.Pipeline.registerFunction(r.trimmer,"trimmer"),r.TokenStore=function(){this.root={docs:{}},this.length=0},r.TokenStore.load=function(e){var t=new this;return t.root=e.root,t.length=e.length,t},r.TokenStore.prototype.add=function(e,t,n){var n=n||this.root,o=e.charAt(0),r=e.slice(1);return o in n||(n[o]={docs:{}}),0===r.length?(n[o].docs[t.ref]=t,void(this.length+=1)):this.add(r,t,n[o])},r.TokenStore.prototype.has=function(e){if(!e)return!1;for(var t=this.root,n=0;n=a&&(c.push(e[d]),c[c.length-1].intersection_length=p.length)}return c=n.orderBy(c,["intersection_length"],["desc"]),{pagination:{per_page:s,page:l,total:c.length},data:{items:c.slice((l-1)*s,l*s)}}}},{"./../vendor/lodash":7,"./fulltext":3,"./helpers":4}],7:[function(e,Fn,zn){(function(En){"use strict";function Tn(e){return Tn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Tn(e)}(function(){function In(n,o){return n.set(o[0],o[1]),n}function t(n,t){return n.add(t),n}function Pn(o,t,e){switch(e.length){case 0:return o.call(t);case 1:return o.call(t,e[0]);case 2:return o.call(t,e[0],e[1]);case 3:return o.call(t,e[0],e[1],e[2]);}return o.apply(t,e)}function Nn(o,t){for(var e=-1,n=null==o?0:o.length;++ea||m&&k&&S&&!x&&!A||f&&k&&S||!g&&S||!_){i=1;break e}if(!f&&!m&&!A&&i=c?i:i*("desc"==d[e]?-1:1);break t}}e=n.b-t.b}return e})}function J(n){return function(t){return L(t,n)}}function q(e){return gn(mt(e,Wt),e+"")}function H(o,i){var e;return un(o,function(s,t,r){return e=i(s,t,r),!e}),!!e}function K(n){if("string"==typeof n)return n;if(vn(n))return c(n,K)+"";if(Ut(n))return ln?ln.call(n):"";var o=n+"";return"0"==o&&1/n==-Gt?"-0":o}function G(e){return wt(e)?e:[]}function Q(n,t){return vn(n)?n:dt(n,t)?[n]:_n(Vt(n))}function X(o,t){if(t)return o.slice();var e=o.length,e=De?De(e):new o.constructor(e);return o.copy(e),e}function Y(n){var t=new n.constructor(n.byteLength);return new Ue(t).set(new Ue(n)),t}function Z(o,t){var e=-1,n=o.length;for(t||(t=Array(n));++ec))return!1;if((u=o.get(l))&&o.get(t))return u==t;var u=-1,a=!0,g=2&d?new j:Kt;for(o.set(l,t),o.set(t,l);++u=e}function Ot(n){var t=Tn(n);return null!=n&&("object"==t||"function"==t)}function Et(e){return null!=e&&"object"==Tn(e)}function It(e){return"string"==typeof e||!vn(e)&&Et(e)&&"[object String]"==N(e)}function Ut(e){return"symbol"==Tn(e)||Et(e)&&"[object Symbol]"==N(e)}function Lt(e){return e?(e=Nt(e),e===Gt||e===-Gt?1.7976931348623157e308*(0>e?-1:1):e===e?e:0):0===e?e:0}function Pt(n){n=Lt(n);var t=n%1;return n===n?t?n-t:n:0}function Nt(n){if("number"==typeof n)return n;if(Ut(n))return Qt;if(Ot(n)&&(n="function"==typeof n.valueOf?n.valueOf():n,n=Ot(n)?n+"":n),"string"!=typeof n)return 0===n?n:+n;n=n.replace(ue,"");var o=fe.test(n);return o||se.test(n)?je(n.slice(2),o?2:8):ae.test(n)?Qt:+n}function Vt(e){return null==e?"":K(e)}function Ct(o,t,e){return o=null==o?Kt:L(o,t),o===Kt?e:o}function Bt(s,t){var e;if(e=null!=s){e=s;var n=Q(t,e);for(var r,i=-1,o=n.length,a=!1;++in)&&(n==t.length-1?t.pop():Ve.call(t,n,1),--this.size,!0)},b.prototype.get=function(n){var t=this.__data__;return n=x(t,n),0>n?Kt:t[n][1]},b.prototype.has=function(e){return-1n?(++this.size,e.push([o,t])):e[n][1]=t,this},m.prototype.clear=function(){this.size=0,this.__data__={hash:new _,map:new(Xe||b),string:new _}},m.prototype.delete=function(e){return e=lt(this,e).delete(e),this.size-=e?1:0,e},m.prototype.get=function(e){return lt(this,e).get(e)},m.prototype.has=function(e){return lt(this,e).has(e)},m.prototype.set=function(o,t){var e=lt(this,o),n=e.size;return e.set(o,t),this.size+=e.size==n?0:1,this},j.prototype.add=j.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},j.prototype.has=function(e){return this.__data__.has(e)},S.prototype.clear=function(){this.__data__=new b,this.size=0},S.prototype.delete=function(n){var t=this.__data__;return n=t.delete(n),this.size=t.size,n},S.prototype.get=function(e){return this.__data__.get(e)},S.prototype.has=function(e){return this.__data__.has(e)},S.prototype.set=function(o,t){var e=this.__data__;if(e instanceof b){var n=e.__data__;if(!Xe||199>n.length)return n.push([o,t]),this.size=++e.size,this;e=this.__data__=new m(n)}return e.set(o,t),this.size=e.size,this};var un=function(i,t){return function(e,n){if(null==e)return e;if(!At(e))return i(e,n);for(var r=e.length,o=t?r:-1,s=Object(e);(t?o--:++oe&&(e=Ke(n+e,0)),It(i)?e<=n&&-1n.idx?n=n.next:(o+=t.val*n.val,t=t.next,n=n.next);return o},r.Vector.prototype.similarity=function(e){return this.dot(e)/(this.magnitude()*e.magnitude())},r.SortedSet=function(){this.length=0,this.elements=[]},r.SortedSet.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},r.SortedSet.prototype.add=function(){var e,t;for(e=0;ee&&(n=i),r=n-t,i=t+o(r/2),s=this.elements[i]}return s===e?i:-1},r.SortedSet.prototype.locationFor=function(e){for(var t=0,n=this.elements.length,r=n-t,i=t+o(r/2),s=this.elements[i];1e&&(n=i),r=n-t,i=t+o(r/2),s=this.elements[i];return s>e?i:si-1||o>s-1);){if(l[n]===a[o]){t.add(l[n]),n++,o++;continue}if(l[n]a[o]){o++;continue}}return t},r.SortedSet.prototype.clone=function(){var e=new r.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},r.SortedSet.prototype.union=function(e){var t,n,o;this.length>=e.length?(t=this,n=e):(t=e,n=this),o=t.clone();for(var r=0,i=n.toArray();rn.length)return n;if(A=n.substr(0,1),"y"==A&&(n=A.toUpperCase()+n.substr(1)),w=d,F=c,w.test(n)?n=n.replace(w,"$1$2"):F.test(n)&&(n=n.replace(F,"$1$2")),w=p,F=u,w.test(n)){var E=w.exec(n);w=i,w.test(E[1])&&(w=g,n=n.replace(w,""))}else if(F.test(n)){var E=F.exec(n);o=E[1],F=l,F.test(o)&&(n=o,F=f,z=h,O=y,F.test(n)?n+="e":z.test(n)?(w=g,n=n.replace(w,"")):O.test(n)&&(n+="e"))}if(w=_,w.test(n)){var E=w.exec(n);o=E[1],n=o+"i"}if(w=b,w.test(n)){var E=w.exec(n);o=E[1],r=E[2],w=i,w.test(o)&&(n=o+e[r])}if(w=m,w.test(n)){var E=w.exec(n);o=E[1],r=E[2],w=i,w.test(o)&&(n=o+t[r])}if(w=j,F=k,w.test(n)){var E=w.exec(n);o=E[1],w=s,w.test(o)&&(n=o)}else if(F.test(n)){var E=F.exec(n);o=E[1]+E[2],F=s,F.test(o)&&(n=o)}if(w=x,w.test(n)){var E=w.exec(n);o=E[1],w=s,F=a,z=v,(w.test(o)||F.test(o)&&!z.test(o))&&(n=o)}return w=S,F=s,w.test(n)&&F.test(n)&&(w=g,n=n.replace(w,"")),"y"==A&&(n=A.toLowerCase()+n.substr(1)),n}}(),r.Pipeline.registerFunction(r.stemmer,"stemmer"),r.generateStopWordFilter=function(e){var t=e.reduce(function(e,t){return e[t]=t,e},{});return function(e){if(e&&t[e]!==e)return e}},r.stopWordFilter=r.generateStopWordFilter(["a","able","about","across","after","all","almost","also","am","among","an","and","any","are","as","at","be","because","been","but","by","can","cannot","could","dear","did","do","does","either","else","ever","every","for","from","get","got","had","has","have","he","her","hers","him","his","how","however","i","if","in","into","is","it","its","just","least","let","like","likely","may","me","might","most","must","my","neither","no","nor","not","of","off","often","on","only","or","other","our","own","rather","said","say","says","she","should","since","so","some","than","that","the","their","them","then","there","these","they","this","tis","to","too","twas","us","wants","was","we","were","what","when","where","which","while","who","whom","why","will","with","would","yet","you","your"]),r.Pipeline.registerFunction(r.stopWordFilter,"stopWordFilter"),r.trimmer=function(e){return e.replace(/^\W+/,"").replace(/\W+$/,"")},r.Pipeline.registerFunction(r.trimmer,"trimmer"),r.TokenStore=function(){this.root={docs:{}},this.length=0},r.TokenStore.load=function(e){var t=new this;return t.root=e.root,t.length=e.length,t},r.TokenStore.prototype.add=function(e,t,n){var n=n||this.root,o=e.charAt(0),r=e.slice(1);return o in n||(n[o]={docs:{}}),0===r.length?(n[o].docs[t.ref]=t,void(this.length+=1)):this.add(r,t,n[o])},r.TokenStore.prototype.has=function(e){if(!e)return!1;for(var t=this.root,n=0;n=a&&(c.push(e[d]),c[c.length-1].intersection_length=p.length)}return c=n.orderBy(c,["intersection_length"],["desc"]),{pagination:{per_page:s,page:l,total:c.length},data:{items:c.slice((l-1)*s,l*s)}}}},{"./../vendor/lodash":7,"./fulltext":3,"./helpers":4}],7:[function(e,Fn,zn){(function(En){"use strict";function Tn(e){return Tn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Tn(e)}(function(){function In(n,o){return n.set(o[0],o[1]),n}function t(n,t){return n.add(t),n}function Pn(o,t,e){switch(e.length){case 0:return o.call(t);case 1:return o.call(t,e[0]);case 2:return o.call(t,e[0],e[1]);case 3:return o.call(t,e[0],e[1],e[2]);}return o.apply(t,e)}function Nn(o,t){for(var e=-1,n=null==o?0:o.length;++ea||m&&k&&S&&!x&&!A||f&&k&&S||!g&&S||!_){i=1;break e}if(!f&&!m&&!A&&i=c?i:i*("desc"==d[e]?-1:1);break t}}e=n.b-t.b}return e})}function J(n){return function(t){return L(t,n)}}function q(e){return gn(mt(e,Wt),e+"")}function H(o,i){var e;return un(o,function(s,t,r){return e=i(s,t,r),!e}),!!e}function K(n){if("string"==typeof n)return n;if(vn(n))return c(n,K)+"";if(Ut(n))return ln?ln.call(n):"";var o=n+"";return"0"==o&&1/n==-Gt?"-0":o}function G(e){return wt(e)?e:[]}function Q(n,t){return vn(n)?n:dt(n,t)?[n]:_n(Vt(n))}function X(o,t){if(t)return o.slice();var e=o.length,e=De?De(e):new o.constructor(e);return o.copy(e),e}function Y(n){var t=new n.constructor(n.byteLength);return new Ue(t).set(new Ue(n)),t}function Z(o,t){var e=-1,n=o.length;for(t||(t=Array(n));++ec))return!1;if((u=o.get(l))&&o.get(t))return u==t;var u=-1,a=!0,g=2&d?new j:Kt;for(o.set(l,t),o.set(t,l);++u=e}function Ot(n){var t=Tn(n);return null!=n&&("object"==t||"function"==t)}function Et(e){return null!=e&&"object"==Tn(e)}function It(e){return"string"==typeof e||!vn(e)&&Et(e)&&"[object String]"==N(e)}function Ut(e){return"symbol"==Tn(e)||Et(e)&&"[object Symbol]"==N(e)}function Lt(e){return e?(e=Nt(e),e===Gt||e===-Gt?1.7976931348623157e308*(0>e?-1:1):e===e?e:0):0===e?e:0}function Pt(n){n=Lt(n);var t=n%1;return n===n?t?n-t:n:0}function Nt(n){if("number"==typeof n)return n;if(Ut(n))return Qt;if(Ot(n)&&(n="function"==typeof n.valueOf?n.valueOf():n,n=Ot(n)?n+"":n),"string"!=typeof n)return 0===n?n:+n;n=n.replace(ue,"");var o=fe.test(n);return o||se.test(n)?je(n.slice(2),o?2:8):ae.test(n)?Qt:+n}function Vt(e){return null==e?"":K(e)}function Ct(o,t,e){return o=null==o?Kt:L(o,t),o===Kt?e:o}function Bt(s,t){var e;if(e=null!=s){e=s;var n=Q(t,e);for(var r,i=-1,o=n.length,a=!1;++in)&&(n==t.length-1?t.pop():Ve.call(t,n,1),--this.size,!0)},b.prototype.get=function(n){var t=this.__data__;return n=x(t,n),0>n?Kt:t[n][1]},b.prototype.has=function(e){return-1n?(++this.size,e.push([o,t])):e[n][1]=t,this},m.prototype.clear=function(){this.size=0,this.__data__={hash:new _,map:new(Xe||b),string:new _}},m.prototype.delete=function(e){return e=lt(this,e).delete(e),this.size-=e?1:0,e},m.prototype.get=function(e){return lt(this,e).get(e)},m.prototype.has=function(e){return lt(this,e).has(e)},m.prototype.set=function(o,t){var e=lt(this,o),n=e.size;return e.set(o,t),this.size+=e.size==n?0:1,this},j.prototype.add=j.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},j.prototype.has=function(e){return this.__data__.has(e)},S.prototype.clear=function(){this.__data__=new b,this.size=0},S.prototype.delete=function(n){var t=this.__data__;return n=t.delete(n),this.size=t.size,n},S.prototype.get=function(e){return this.__data__.get(e)},S.prototype.has=function(e){return this.__data__.has(e)},S.prototype.set=function(o,t){var e=this.__data__;if(e instanceof b){var n=e.__data__;if(!Xe||199>n.length)return n.push([o,t]),this.size=++e.size,this;e=this.__data__=new m(n)}return e.set(o,t),this.size=e.size,this};var un=function(i,t){return function(e,n){if(null==e)return e;if(!At(e))return i(e,n);for(var r=e.length,o=t?r:-1,s=Object(e);(t?o--:++oe&&(e=Ke(n+e,0)),It(i)?e<=n&&-1