forked from crcn/sift.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sift.min.js
1 lines (1 loc) · 4.12 KB
/
sift.min.js
1
!function(){"use strict";function n(n){return"function"==typeof n}function t(n){return"[object Array]"===Object.prototype.toString.call(n)}function r(n){return n instanceof Date?n.getTime():t(n)?n.map(r):n&&"function"==typeof n.toJSON?n.toJSON():n}function e(t,r){return n(t.get)?t.get(r):t[r]}function u(n){return function(r,u){if(!t(u)||!u.length)return n(r,u);for(var o=0,i=u.length;o<i;o++)if(n(r,e(u,o)))return!0;return!1}}function o(n){return function(r,u){if(!t(u)||!u.length)return n(r,u);for(var o=0,i=u.length;o<i;o++)if(!n(r,e(u,o)))return!1;return!0}}function i(n,t,r,e){return n.v(n.a,t,r,e)}function f(n,t){for(var r=0;r<n.length;r++){e(n,r);if(i(t,e(n,r)))return r}return-1}function c(n,t){return{a:n,v:t}}function a(n,t){var r=[];if(l(t,n.k,0,t,r),1===r.length){var e=r[0];return i(n.nv,e[0],e[1],e[2])}for(var u=0;u<r.length;u++){var o=r[u];if(i(n.nv,o[0],o[1],o[2]))return!0}return!1}function l(n,r,u,o,i){if(u===r.length||void 0==n)return void i.push([n,r[u-1],o]);var f=e(r,u);if(t(n)&&isNaN(Number(f)))for(var c=0,a=n.length;c<a;c++)l(e(n,c),r,u,n,i);else l(e(n,f),r,u+1,n,i)}function p(n,t){return{a:{k:n,nv:t},v:a}}function $(n){return n&&n.constructor===Object}function g(n){n=r(n),n&&$(n)||(n={$eq:n});var t=[];for(var e in n){var u=n[e];"$options"!==e&&(d[e]?(h[e]&&(u=h[e](u,n)),t.push(c(r(u),d[e]))):t.push(p(e.split("."),g(u))))}return 1===t.length?t[0]:c(t,d.$and)}function v(n,t){var r=g(n);return t&&(r={a:r,v:function(n,r,e,u){return i(n,t(r),e,u)}}),r}function s(t,r,e){function u(n,t,r){return i(o,n,t,r)}n(r)&&(e=r,r=void 0);var o=v(t,e);return r?r.filter(u):u}var d={$eq:u(function(n,t){return n(t)}),$ne:o(function(n,t){return!n(t)}),$gt:u(function(n,t){return s.compare(r(t),n)>0}),$gte:u(function(n,t){return s.compare(r(t),n)>=0}),$lt:u(function(n,t){return s.compare(r(t),n)<0}),$lte:u(function(n,t){return s.compare(r(t),n)<=0}),$mod:u(function(n,t){return t%n[0]==n[1]}),$in:function(n,t){if(!(t instanceof Array)){var u=r(t);if(u===t&&"object"==typeof t)for(var o=n.length;o--;)if(String(n[o])===String(t)&&"[object Object]"!==String(t))return!0;if("undefined"==typeof u)for(var o=n.length;o--;)if(null==n[o])return!0;for(var o=n.length;o--;){var f=v(e(n,o),void 0),c=i(f,t,o,n);if(c&&"[object Object]"!==String(c)&&"[object Object]"!==String(t))return!0}return!!~n.indexOf(u)}for(var o=t.length;o--;)if(~n.indexOf(r(e(t,o))))return!0;return!1},$nin:function(n,t,r,e){return!d.$in(n,t,r,e)},$not:function(n,t,r,e){return!i(n,t,r,e)},$type:function(n,t){return void 0!=t&&(t instanceof n||t.constructor==n)},$all:function(n,t,r,e){return d.$and(n,t,r,e)},$size:function(n,t){return!!t&&n===t.length},$or:function(n,t,r,u){for(var o=0,f=n.length;o<f;o++)if(i(e(n,o),t,r,u))return!0;return!1},$nor:function(n,t,r,e){return!d.$or(n,t,r,e)},$and:function(n,t,r,u){for(var o=0,f=n.length;o<f;o++)if(!i(e(n,o),t,r,u))return!1;return!0},$regex:u(function(n,t){return"string"==typeof t&&n.test(t)}),$where:function(n,t,r,e){return n.call(t,t,r,e)},$elemMatch:function(n,r,e,u){return t(r)?!!~f(r,n):i(n,r,e,u)},$exists:function(n,t,r,e){return e.hasOwnProperty(r)===n}},h={$eq:function(n){return n instanceof RegExp?function(t){return"string"==typeof t&&n.test(t)}:n instanceof Function?n:t(n)&&!n.length?function(n){return t(n)&&!n.length}:null===n?function(n){return null==n}:function(t){return 0===s.compare(r(t),n)}},$ne:function(n){return h.$eq(n)},$and:function(n){return n.map(g)},$all:function(n){return h.$and(n)},$or:function(n){return n.map(g)},$nor:function(n){return n.map(g)},$not:function(n){return g(n)},$regex:function(n,t){return new RegExp(n,t.$options)},$where:function(n){return"string"==typeof n?new Function("obj","return "+n):n},$elemMatch:function(n){return g(n)},$exists:function(n){return!!n}};s.use=function(t){if(n(t))return t(s);for(var r in t)36===r.charCodeAt(0)&&(d[r]=t[r])},s.indexOf=function(n,t,r){return f(t,v(n,r))},s.compare=function(n,t){if(n===t)return 0;if(typeof n==typeof t){if(n>t)return 1;if(n<t)return-1}},"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(Object.defineProperty(exports,"__esModule",{value:!0}),module.exports=s,exports["default"]=module.exports["default"]=s),"undefined"!=typeof window&&(window.sift=s)}();