@36node/query-normalizr
Version:
A module boilerplate for nodejs and web.
3 lines (2 loc) • 977 B
JavaScript
import{isNil as e,isArray as t,set as r}from"lodash";function o(o){var n=o._limit,i=o._offset,u=o._sort,s=o._populate,c=o._select,f=o._group,a=function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&-1===t.indexOf(o)&&(r[o]=e[o]);return r}(o,["_limit","_offset","_sort","_populate","_select","_group"]);return{limit:n,offset:i,sort:u,populate:s,select:c,group:f,filter:Object.keys(a).reduce(function(o,n){var i=a[n],u="id"===n?"_id":[n],s=!1,c=/(.+)_(like|not)/.exec(n);return c&&(u=[c[1]],s=!0),(c=/(.+)_(gt|lt|gte|lte|ne|not)$/.exec(n))&&(u=[c[1],"$"+c[2]]),"q"===n&&(u="$text",i={$search:i}),r(o,u,function r(o,n){if(t(o))return{$in:o.map(function(e){return r(e,n)})};if(e(o)||"string"!=typeof o)return o;if((o=o.trim())&&n)return new RegExp(o.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),"i");switch(o.toLowerCase()){case"*":o={$ne:[]};break;case"none":o={$eq:[]}}return o}(i,s))},{})}}export{o as toMongooseQuery};
//# sourceMappingURL=index.m.js.map