UNPKG

@ucast/js

Version:

git@github.com:stalniy/ucast.git

3 lines (2 loc) 3.7 kB
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@ucast/core")):"function"==typeof define&&define.amd?define(["exports","@ucast/core"],n):n(((r=r||self).ucast=r.ucast||{},r.ucast.js={}),r.ucast.core)}(this,(function(r,n){"use strict";function t(r,n,t){for(var u=0,e=r.length;u<e;u++)if(0===t(r[u],n))return!0;return!1}function u(r,n){return Array.isArray(r)&&Number.isNaN(Number(n))}function e(r,n,t){if(!u(r,n))return t(r,n);for(var e=[],o=0;o<r.length;o++){var i=t(r[o],n);void 0!==i&&(e=e.concat(i))}return e}function o(r){return function(n,t,u){var e=u.get(t,n.field);return Array.isArray(e)?e.some((function(t){return r(n,t,u)})):r(n,e,u)}}function i(){return(i=Object.assign||function(r){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var u in t)Object.prototype.hasOwnProperty.call(t,u)&&(r[u]=t[u])}return r}).apply(this,arguments)}var f=function(r,n){return r[n]};function c(r,n,t){var u=n.lastIndexOf(".");return-1===u?[r,n]:[t(r,n.slice(0,u)),n.slice(u+1)]}function a(r,t,u){if(void 0===u&&(u=f),t===n.ITSELF)return r;if(!r)throw new Error('Unable to get field "'+t+'" out of '+String(r)+".");return function(r,n,t){if(-1===n.indexOf("."))return e(r,n,t);for(var u=n.split("."),o=r,i=0,f=u.length;i<f;i++)if(!(o=e(o,u[i],t))||"object"!=typeof o)return o;return o}(r,t,u)}function v(r,n){return r===n?0:r>n?1:-1}function l(r,t){return void 0===t&&(t={}),n.createInterpreter(r,i({get:a,compare:v},t))}var s=function(r,n,t){var u=t.interpret;return r.value.some((function(r){return u(r,n)}))},d=function(r,n,t){return!s(r,n,t)},y=function(r,n,t){var u=t.interpret;return r.value.every((function(r){return u(r,n)}))},p=function(r,n,t){return!(0,t.interpret)(r.value[0],n)},b=function(r,n,u){var e=u.compare,o=(0,u.get)(n,r.field);return Array.isArray(o)&&!Array.isArray(r.value)?t(o,r.value,e):0===e(o,r.value)},g=function(r,n,t){return!b(r,n,t)},m=o((function(r,n,t){var u=t.compare(n,r.value);return 0===u||-1===u})),A=o((function(r,n,t){return-1===t.compare(n,r.value)})),h=o((function(r,n,t){return 1===t.compare(n,r.value)})),j=o((function(r,n,t){var u=t.compare(n,r.value);return 0===u||1===u})),_=function(r,t,e){var o=e.get;if(r.field===n.ITSELF)return void 0!==t;var i=c(t,r.field,o),f=i[0],a=i[1],v=function(n){return null==n?Boolean(n)===r.value:n.hasOwnProperty(a)===r.value};return u(f,a)?f.some(v):v(f)},x=o((function(r,n){return"number"==typeof n&&n%r.value[0]===r.value[1]})),w=function(r,t,e){var o=e.get,i=c(t,r.field,o),f=i[0],a=i[1],v=function(n){var t=o(n,a);return Array.isArray(t)&&t.length===r.value};return r.field!==n.ITSELF&&u(f,a)?f.some(v):v(f)},O=o((function(r,n){return"string"==typeof n&&r.value.test(n)})),q=o((function(r,n,u){var e=u.compare;return t(r.value,n,e)})),M=function(r,n,t){return!q(r,n,t)},N=function(r,n,u){var e=u.compare,o=(0,u.get)(n,r.field);return Array.isArray(o)&&r.value.every((function(r){return t(o,r,e)}))},z=function(r,n,t){var u=t.interpret,e=(0,t.get)(n,r.field);return Array.isArray(e)&&e.some((function(n){return u(r.value,n)}))},B=function(r,n){return r.value.call(n)},E=i({},Object.freeze({__proto__:null,or:s,nor:d,and:y,not:p,eq:b,ne:g,lte:m,lt:A,gt:h,gte:j,exists:_,mod:x,size:w,regex:O,within:q,nin:M,all:N,elemMatch:z,where:B}),{in:q}),S=l(E);r.all=N,r.allInterpreters=E,r.and=y,r.compare=v,r.createGetter=function(r){return function(n,t){return a(n,t,r)}},r.createJsInterpreter=l,r.elemMatch=z,r.eq=b,r.exists=_,r.getObjectField=a,r.getObjectFieldCursor=c,r.gt=h,r.gte=j,r.interpret=S,r.lt=A,r.lte=m,r.mod=x,r.ne=g,r.nin=M,r.nor=d,r.not=p,r.or=s,r.regex=O,r.size=w,r.where=B,r.within=q,Object.defineProperty(r,"__esModule",{value:!0})})); //# sourceMappingURL=index.js.map