Skip to content

Commit 2c869a8

Browse files
committed
Add the null == and != comparison to the main branch with
optimizations & compilation
1 parent e98ed76 commit 2c869a8

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

optimizer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function checkIdioms (logic, engine, above) {
144144
const comparisonFunc = comparison.length === 3
145145
? _comparisonFunc
146146
: function comparisonFunc (a, b) {
147-
if (typeof a === 'string' && typeof b === 'string') return _comparisonFunc(a, b)
147+
if ((typeof a === 'string' || a === null) && (typeof b === 'string' || b === null)) return _comparisonFunc(a, b)
148148
if (Number.isNaN(+precoerceNumber(a))) throw NaN
149149
if (Number.isNaN(+precoerceNumber(b)) && a !== null) throw NaN
150150
return _comparisonFunc(+a, +b)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-logic-engine",
3-
"version": "5.0.3",
3+
"version": "5.0.4",
44
"description": "Construct complex rules with JSON & process them.",
55
"main": "./dist/cjs/index.js",
66
"module": "./dist/esm/index.js",

utilities/downgrade.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ export function assertAllowedDepth (item, depthAllowed = 0) {
5959
* @returns {number}
6060
*/
6161
export function compareCheck (item, prev, strict) {
62-
if (strict || (typeof item === 'string' && typeof prev === 'string')) return item
63-
62+
if (strict || ((typeof item === 'string' || item === null) && (typeof prev === 'string' || prev === null))) return item
6463
if (Number.isNaN(+precoerceNumber(item)) && prev !== null) throw NaN
6564
if (Number.isNaN(+precoerceNumber(prev))) throw NaN
6665

0 commit comments

Comments
 (0)