comparisons
Advanced tools
Comparing version 2.2.8 to 2.2.9
@@ -22,3 +22,3 @@ const sift = require('sift').default; | ||
age: 21, | ||
language: 'en', | ||
language: ['en', 'es'], | ||
bestFriend: { | ||
@@ -62,2 +62,7 @@ name: 'Jon', | ||
describe('query', () => { | ||
it('should return truthy on dynamic matching', () => | ||
expect( | ||
new Comparison(['dynamic={{age}}']).query(stub), | ||
).toMatchObject({})); | ||
it('should return as mongo query', () => | ||
@@ -64,0 +69,0 @@ expect(new Comparison(exp).query(stub)).toMatchObject({ |
@@ -107,5 +107,17 @@ const flat = require('flat'); | ||
query() { | ||
query(obj = {}) { | ||
return { | ||
$and: this.eligible.reduce((a, [key, value, fn]) => { | ||
$and: this.eligible.reduce((a, params) => { | ||
let key; | ||
let value; | ||
let fn; | ||
if (Array.isArray(params)) { | ||
[key, value, fn] = params; | ||
} else if (isFn(params)) { | ||
[key, value, fn] = params(obj); | ||
} else { | ||
return a; | ||
} | ||
const v = isSerialized(value) ? value.split(',') : value; | ||
@@ -128,3 +140,3 @@ const name = Array.isArray(v) ? 'in' : fn.name; | ||
return isFn(validator) | ||
? validator(flat(obj)[key], value, this.locale) | ||
? validator(flat(obj, { safe: true })[key], value, this.locale) | ||
: false; | ||
@@ -131,0 +143,0 @@ }); |
@@ -79,3 +79,7 @@ const moment = require('moment'); | ||
const equals = (a, b, locale) => { | ||
const comp = (v) => runCompare(a, v, locale) === 0; | ||
const comp = (input) => { | ||
const exec = (value) => runCompare(value, input, locale) === 0; | ||
return Array.isArray(a) ? a.some(exec) : exec(a); | ||
}; | ||
if (b === '*') return a !== '' && a !== undefined && a !== null; | ||
@@ -82,0 +86,0 @@ if (typeof b === 'string' && b.includes(',')) |
{ | ||
"name": "comparisons", | ||
"version": "2.2.8", | ||
"version": "2.2.9", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
17966
434