Comparing version 3.3.2 to 3.3.3
@@ -1,23 +0,66 @@ | ||
declare module sift { | ||
export interface ISiftQueries { | ||
export type SupportedTypes = Array<string | { [index: string]: any } | number | null>; | ||
} | ||
export type Query<T> = { | ||
$eq?: T; | ||
$ne?: T; | ||
$or?: Array<Partial<T>>; | ||
$gt?: T; | ||
$gte?: T; | ||
$lt?: T; | ||
$lte?: T; | ||
$mod?: number[]; | ||
$in?: Array<Partial<T>>; | ||
$nin?: Array<T>; | ||
$not?: Query<T>; | ||
$type?: any; | ||
$all?: Array<T>; | ||
$size?: number; | ||
$nor?: Array<Partial<T>>; | ||
$and?: Array<Partial<T>>; | ||
$regex?: RegExp | string; | ||
$elemMatch?: { [index: string]: Query<T> }; | ||
$exists?: boolean; | ||
$options?: "i" | "g" | "m" | "u"; | ||
} | ||
export interface ISifter<T> extends Function { | ||
export interface InternalQuery<T extends SupportedTypes> extends Query<T[0]> { | ||
$where?: string | WhereFn<T>; | ||
} | ||
} | ||
export type ExternalQuery<T extends SupportedTypes> = { | ||
[P in keyof T[0]]?: InternalQuery<T>; | ||
} | ||
export type ISiftQuery = RegExp|ISiftQueries; | ||
export type WhereFn<T extends SupportedTypes> = (this: T[0], value: T[0], index: number, array: T) => boolean; | ||
interface Sift { | ||
<T>(query: T): ISifter<T>; | ||
<T>(query: ISiftQuery, target?: T, rawSelector?: any): T; | ||
indexOf(query: any, target: any, rawSelector: any): any; | ||
use(options: any): any; | ||
} | ||
export type FilterFn = <T>(value: T, index?: number, array?: T[]) => boolean; | ||
export type SiftQuery<T extends SupportedTypes> = ExternalQuery<T> | InternalQuery<T>; | ||
export type SiftQueryNumber = Query<number>; | ||
export type SiftQueryString = Query<string>; | ||
export type PluginDefinition<T = any> = { | ||
[index: string]: (a: T, b: T) => boolean | number; | ||
} | ||
declare module "sift" { | ||
var f: sift.Sift; | ||
export = f; | ||
export type PluginFunction<T> = (sift: Sift) => PluginDefinition<T>; | ||
export type Exec = <T extends SupportedTypes>(array: T) => T; | ||
export interface Sift { | ||
<T extends SupportedTypes>(query: RegExp, target: T, rawSelector?: any): T; | ||
<T = any>(query: SiftQuery<any>, rawSelector: (item: T) => boolean): Exec; | ||
<T extends SupportedTypes = any[]>(query: SiftQuery<T>): FilterFn; | ||
(query: SiftQueryString, target: string[], rawSelector?: any): string[]; | ||
(query: SiftQueryNumber, target: number[], rawSelector?: any): number[]; | ||
<T extends SupportedTypes>(query: SiftQuery<T>, target: T, rawSelector?: any): T; | ||
indexOf<T extends SupportedTypes>(query: SiftQuery<T>, target: T, rawSelector?: any): number; | ||
use<K = any>(plugin: PluginFunction<K> | PluginDefinition<K>): void; | ||
compare<T, K>(a: T, b: K): 0 | -1 | 1; | ||
} | ||
declare global { | ||
const sift: Sift | ||
} | ||
export default Sift |
{ | ||
"name": "sift", | ||
"description": "mongodb query style array filtering", | ||
"version": "3.3.2", | ||
"version": "3.3.3", | ||
"repository": "crcn/sift.js", | ||
@@ -6,0 +6,0 @@ "author": { |
12
sift.js
@@ -161,2 +161,14 @@ /* | ||
} | ||
/* | ||
Handles documents that are undefined, whilst also | ||
having a 'null' element in the parameters to $in. | ||
*/ | ||
if (typeof comparableB == 'undefined') { | ||
for (var i = a.length; i--;) { | ||
if (a[i] == null) { | ||
return true; | ||
} | ||
} | ||
} | ||
return !!~a.indexOf(comparable(b)); | ||
@@ -163,0 +175,0 @@ } |
@@ -1,1 +0,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():n instanceof Array?n.map(r):n}function e(n){return function(r,e){if(!t(e))return n(r,e);for(var u=0,o=e.length;o>u;u++)if(n(r,e[u]))return!0;return!1}}function u(n){return function(r,e){if(!t(e))return n(r,e);for(var u=0,o=e.length;o>u;u++)if(!n(r,e[u]))return!1;return!0}}function o(n,t){return n.v(n.a,t)}function i(n,t){for(var r=0;r<n.length;r++)if(o(t,n[r]))return r;return-1}function f(n,t){return{a:n,v:t}}function c(n,t){var r=[];return a(t,n.k,0,r),1===r.length?o(n.nv,r[0]):!!~i(r,n.nv)}function a(n,r,e,u){if(e===r.length||void 0==n)return void u.push(n);if(t(n))for(var o=0,i=n.length;i>o;o++)a(n[o],r,e,u);else a(n[r[e]],r,e+1,u)}function $(n,t){return{a:{k:n,nv:t},v:c}}function l(n){n=r(n),(!n||"Object"!==n.constructor.toString()&&"functionObject(){[nativecode]}"!==n.constructor.toString().replace(/\n/g,"").replace(/ /g,""))&&(n={$eq:n});var t=[];for(var e in n){var u=n[e];if(s[e])d[e]&&(u=d[e](u)),t.push(f(r(u),s[e]));else{if(36===e.charCodeAt(0))throw new Error("Unknown operation "+e);t.push($(e.split("."),l(u)))}}return 1===t.length?t[0]:f(t,s.$and)}function p(n,t){var r=l(n);return t&&(r={a:r,v:function(n,r){return o(n,t(r))}}),r}function v(t,r,e){function u(n){return o(i,n)}n(r)&&(e=r,r=void 0);var i=p(t,e);return r?r.filter(u):u}var s={$eq:e(function(n,t){return n(t)}),$ne:u(function(n,t){return!n(t)}),$or:function(n,t){for(var r=0,e=n.length;e>r;r++)if(o(n[r],t))return!0;return!1},$gt:e(function(n,t){return typeof r(t)==typeof n&&r(t)>n}),$gte:e(function(n,t){return typeof r(t)==typeof n&&r(t)>=n}),$lt:e(function(n,t){return typeof r(t)==typeof n&&r(t)<n}),$lte:e(function(n,t){return typeof r(t)==typeof n&&r(t)<=n}),$mod:e(function(n,t){return t%n[0]==n[1]}),$in:function(n,t){if(!(t instanceof Array))return!!~n.indexOf(r(t));for(var e=t.length;e--;)if(~n.indexOf(r(t[e])))return!0;return!1},$nin:function(n,t){return!s.$in(n,t)},$not:function(n,t){return!o(n,t)},$type:function(n,t){return void 0!=t?t instanceof n||t.constructor==n:!1},$all:function(n,t){t||(t=[]);for(var e=n.length;e--;)if(!~r(t).indexOf(n[e]))return!1;return!0},$size:function(n,t){return t?n===t.length:!1},$nor:function(n,t){for(var r=0,e=n.length;e>r;r++)if(o(n[r],t))return!1;return!0},$and:function(n,t){for(var r=0,e=n.length;e>r;r++)if(!o(n[r],t))return!1;return!0},$regex:function(n,t){return n.test(t)},$where:function(n,t){return n.call(t,t)},$elemMatch:function(n,r){return t(r)?!!~i(r,n):o(n,r)},$exists:function(n,t){return void 0!=t===n}},d={$eq:function(n){return n instanceof RegExp?function(t){return n.test(r(t))}:n instanceof Function?n:function(t){return n===r(t)}},$ne:function(n){return d.$eq(n)},$and:function(n){return n.map(l)},$or:function(n){return n.map(l)},$nor:function(n){return n.map(l)},$not:function(n){return l(n)},$regex:function(n){return new RegExp(n)},$where:function(n){return"string"==typeof n?new Function("obj","return "+n):n},$elemMatch:function(n){return l(n)},$exists:function(n){return!!n}};v.use=function(t){if(n(t))return t(v);for(var r in t)36===r.charCodeAt(0)&&(s[r]=t[r])},v.indexOf=function(n,t,r){return i(t,p(n,r))},"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=v:"undefined"!=typeof window&&(window.sift=v)}(); | ||
!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():n instanceof Array?n.map(r):n}function e(n,t){return n.get?n.get(t):n[t]}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){return n.v(n.a,t)}function f(n,t){for(var r=0;r<n.length;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=[];return l(t,n.k,0,r),1===r.length?i(n.nv,r[0]):!!~f(r,n.nv)}function l(n,r,u,o){if(u===r.length||void 0==n)return void o.push(n);var i=e(r,u);if(t(n)&&isNaN(Number(i)))for(var f=0,c=n.length;f<c;f++)l(e(n,f),r,u,o);else l(e(n,i),r,u+1,o)}function $(n,t){return{a:{k:n,nv:t},v:a}}function g(n){return"Object"===String(n.constructor)||"functionObject(){[nativecode]}"===String(n.constructor).replace(/[\r\n\s\t]/g,"")}function p(n){n=r(n),n&&g(n)||(n={$eq:n});var t=[];for(var e in n){var u=n[e];if("$options"!==e)if(d[e])h[e]&&(u=h[e](u,n)),t.push(c(r(u),d[e]));else{if(36===e.charCodeAt(0))throw new Error("Unknown operation "+e);t.push($(e.split("."),p(u)))}}return 1===t.length?t[0]:c(t,d.$and)}function s(n,t){var r=p(n);return t&&(r={a:r,v:function(n,r){return i(n,t(r))}}),r}function v(t,r,e){function u(n){return i(o,n)}n(r)&&(e=r,r=void 0);var o=s(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)}),$or:function(n,t){for(var r=0,u=n.length;r<u;r++)if(i(e(n,r),t))return!0;return!1},$gt:u(function(n,t){return v.compare(r(t),n)>0}),$gte:u(function(n,t){return v.compare(r(t),n)>=0}),$lt:u(function(n,t){return v.compare(r(t),n)<0}),$lte:u(function(n,t){return v.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;return!!~n.indexOf(r(t))}for(var o=t.length;o--;)if(~n.indexOf(r(e(t,o))))return!0;return!1},$nin:function(n,t){return!d.$in(n,t)},$not:function(n,t){return!i(n,t)},$type:function(n,t){return void 0!=t&&(t instanceof n||t.constructor==n)},$all:function(n,t){return d.$and(n,t)},$size:function(n,t){return!!t&&n===t.length},$nor:function(n,t){for(var r=0,u=n.length;r<u;r++)if(i(e(n,r),t))return!1;return!0},$and:function(n,t){t||(t=[]);for(var r=0,u=n.length;r<u;r++)if(!i(e(n,r),t))return!1;return!0},$regex:u(function(n,t){return"string"==typeof t&&n.test(t)}),$where:function(n,t){return n.call(t,t)},$elemMatch:function(n,r){return t(r)?!!~f(r,n):i(n,r)},$exists:function(n,t){return void 0!=t===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===v.compare(r(t),n)}},$ne:function(n){return h.$eq(n)},$and:function(n){return n.map(p)},$all:function(n){return h.$and(n)},$or:function(n){return n.map(p)},$nor:function(n){return n.map(p)},$not:function(n){return p(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 p(n)},$exists:function(n){return!!n}};v.use=function(t){if(n(t))return t(v);for(var r in t)36===r.charCodeAt(0)&&(d[r]=t[r])},v.indexOf=function(n,t,r){return f(t,s(n,r))},v.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&&(module.exports=v),"undefined"!=typeof window&&(window.sift=v)}(); |
@@ -77,2 +77,4 @@ var assert = require('assert'); | ||
[{$nin:[new Date(1)]},[new Date(1), new Date(2)],[new Date(2)]], | ||
[{"root.notDefined": {$nin: [1, 2, 3]}}, [{"root": {"defined": 1337}}], [{"root": {"defined": 1337}}]], | ||
[{"root.notDefined": {$nin: [1, 2, 3, null]}}, [{"root": {"defined": 1337}}], []], | ||
@@ -79,0 +81,0 @@ // $not |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
142211
1928