@@ -84,8 +84,6 @@ const defaultMethods = {
84
84
max : ( data ) => Math . max ( ...data ) ,
85
85
min : ( data ) => Math . min ( ...data ) ,
86
86
in : ( [ item , array ] ) => ( array || [ ] ) . includes ( item ) ,
87
- '>' : ( [ a , b ] ) => a > b ,
88
- '<' : ( [ a , b , c ] ) => ( c === undefined ? a < b : a < b && b < c ) ,
89
87
preserve : {
90
88
traverse : false ,
91
89
method : declareSync ( ( i ) => i , true ) ,
@@ -150,14 +148,66 @@ const defaultMethods = {
150
148
} ,
151
149
traverse : false
152
150
} ,
153
- '<=' : ( [ a , b , c ] ) => ( c === undefined ? a <= b : a <= b && b <= c ) ,
154
- '>=' : ( [ a , b ] ) => a >= b ,
155
- // eslint-disable-next-line eqeqeq
156
- '==' : ( [ a , b ] ) => a == b ,
157
- '===' : ( [ a , b ] ) => a === b ,
158
- // eslint-disable-next-line eqeqeq
159
- '!=' : ( [ a , b ] ) => a != b ,
160
- '!==' : ( [ a , b ] ) => a !== b ,
151
+ '<' : ( args ) => {
152
+ if ( args . length === 2 ) return args [ 0 ] < args [ 1 ]
153
+ for ( let i = 1 ; i < args . length ; i ++ ) {
154
+ if ( args [ i - 1 ] >= args [ i ] ) return false
155
+ }
156
+ return true
157
+ } ,
158
+ '<=' : ( args ) => {
159
+ if ( args . length === 2 ) return args [ 0 ] <= args [ 1 ]
160
+ for ( let i = 1 ; i < args . length ; i ++ ) {
161
+ if ( args [ i - 1 ] > args [ i ] ) return false
162
+ }
163
+ return true
164
+ } ,
165
+ '>' : ( args ) => {
166
+ if ( args . length === 2 ) return args [ 0 ] > args [ 1 ]
167
+ for ( let i = 1 ; i < args . length ; i ++ ) {
168
+ if ( args [ i - 1 ] <= args [ i ] ) return false
169
+ }
170
+ return true
171
+ } ,
172
+ '>=' : ( args ) => {
173
+ if ( args . length === 2 ) return args [ 0 ] >= args [ 1 ]
174
+ for ( let i = 1 ; i < args . length ; i ++ ) {
175
+ if ( args [ i - 1 ] < args [ i ] ) return false
176
+ }
177
+ return true
178
+ } ,
179
+ '==' : ( args ) => {
180
+ // eslint-disable-next-line eqeqeq
181
+ if ( args . length === 2 ) return args [ 0 ] == args [ 1 ]
182
+ for ( let i = 1 ; i < args . length ; i ++ ) {
183
+ // eslint-disable-next-line eqeqeq
184
+ if ( args [ i - 1 ] != args [ i ] ) return false
185
+ }
186
+ return true
187
+ } ,
188
+ '===' : ( args ) => {
189
+ if ( args . length === 2 ) return args [ 0 ] === args [ 1 ]
190
+ for ( let i = 1 ; i < args . length ; i ++ ) {
191
+ if ( args [ i - 1 ] !== args [ i ] ) return false
192
+ }
193
+ return true
194
+ } ,
195
+ '!=' : ( args ) => {
196
+ // eslint-disable-next-line eqeqeq
197
+ if ( args . length === 2 ) return args [ 0 ] != args [ 1 ]
198
+ for ( let i = 1 ; i < args . length ; i ++ ) {
199
+ // eslint-disable-next-line eqeqeq
200
+ if ( args [ i - 1 ] == args [ i ] ) return false
201
+ }
202
+ return true
203
+ } ,
204
+ '!==' : ( args ) => {
205
+ if ( args . length === 2 ) return args [ 0 ] !== args [ 1 ]
206
+ for ( let i = 1 ; i < args . length ; i ++ ) {
207
+ if ( args [ i - 1 ] === args [ i ] ) return false
208
+ }
209
+ return true
210
+ } ,
161
211
xor : ( [ a , b ] ) => a ^ b ,
162
212
// Why "executeInLoop"? Because if it needs to execute to get an array, I do not want to execute the arguments,
163
213
// Both for performance and safety reasons.
@@ -671,16 +721,18 @@ Object.keys(defaultMethods).forEach((item) => {
671
721
// @ts -ignore Allow custom attribute
672
722
defaultMethods [ '<' ] . compile = function ( data , buildState ) {
673
723
if ( ! Array . isArray ( data ) ) return false
674
- if ( data . length === 2 ) return buildState . compile `(${ data [ 0 ] } < ${ data [ 1 ] } )`
675
- if ( data . length === 3 ) return buildState . compile `(${ data [ 0 ] } < ${ data [ 1 ] } && ${ data [ 1 ] } < ${ data [ 2 ] } )`
676
- return false
724
+ if ( data . length < 2 ) return false
725
+ let res = buildState . compile `(${ data [ 0 ] } < ${ data [ 1 ] } )`
726
+ for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && ${ data [ i - 1 ] } < ${ data [ i ] } )`
727
+ return res
677
728
}
678
729
// @ts -ignore Allow custom attribute
679
730
defaultMethods [ '<=' ] . compile = function ( data , buildState ) {
680
731
if ( ! Array . isArray ( data ) ) return false
681
- if ( data . length === 2 ) return buildState . compile `(${ data [ 0 ] } <= ${ data [ 1 ] } )`
682
- if ( data . length === 3 ) return buildState . compile `(${ data [ 0 ] } <= ${ data [ 1 ] } && ${ data [ 1 ] } <= ${ data [ 2 ] } )`
683
- return false
732
+ if ( data . length < 2 ) return false
733
+ let res = buildState . compile `(${ data [ 0 ] } <= ${ data [ 1 ] } )`
734
+ for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && ${ data [ i - 1 ] } <= ${ data [ i ] } )`
735
+ return res
684
736
}
685
737
// @ts -ignore Allow custom attribute
686
738
defaultMethods . min . compile = function ( data , buildState ) {
@@ -699,26 +751,34 @@ defaultMethods.max.compile = function (data, buildState) {
699
751
// @ts -ignore Allow custom attribute
700
752
defaultMethods [ '>' ] . compile = function ( data , buildState ) {
701
753
if ( ! Array . isArray ( data ) ) return false
702
- if ( data . length !== 2 ) return false
703
- return buildState . compile `(${ data [ 0 ] } > ${ data [ 1 ] } )`
754
+ if ( data . length < 2 ) return false
755
+ let res = buildState . compile `(${ data [ 0 ] } > ${ data [ 1 ] } )`
756
+ for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && ${ data [ i - 1 ] } > ${ data [ i ] } )`
757
+ return res
704
758
}
705
759
// @ts -ignore Allow custom attribute
706
760
defaultMethods [ '>=' ] . compile = function ( data , buildState ) {
707
761
if ( ! Array . isArray ( data ) ) return false
708
- if ( data . length !== 2 ) return false
709
- return buildState . compile `(${ data [ 0 ] } >= ${ data [ 1 ] } )`
762
+ if ( data . length < 2 ) return false
763
+ let res = buildState . compile `(${ data [ 0 ] } >= ${ data [ 1 ] } )`
764
+ for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && ${ data [ i - 1 ] } >= ${ data [ i ] } )`
765
+ return res
710
766
}
711
767
// @ts -ignore Allow custom attribute
712
768
defaultMethods [ '==' ] . compile = function ( data , buildState ) {
713
769
if ( ! Array . isArray ( data ) ) return false
714
- if ( data . length !== 2 ) return false
715
- return buildState . compile `(${ data [ 0 ] } == ${ data [ 1 ] } )`
770
+ if ( data . length < 2 ) return false
771
+ let res = buildState . compile `(${ data [ 0 ] } == ${ data [ 1 ] } )`
772
+ for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && ${ data [ i - 1 ] } == ${ data [ i ] } )`
773
+ return res
716
774
}
717
775
// @ts -ignore Allow custom attribute
718
776
defaultMethods [ '!=' ] . compile = function ( data , buildState ) {
719
777
if ( ! Array . isArray ( data ) ) return false
720
- if ( data . length !== 2 ) return false
721
- return buildState . compile `(${ data [ 0 ] } != ${ data [ 1 ] } )`
778
+ if ( data . length < 2 ) return false
779
+ let res = buildState . compile `(${ data [ 0 ] } != ${ data [ 1 ] } )`
780
+ for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && ${ data [ i - 1 ] } != ${ data [ i ] } )`
781
+ return res
722
782
}
723
783
// @ts -ignore Allow custom attribute
724
784
defaultMethods . if . compile = function ( data , buildState ) {
@@ -741,8 +801,10 @@ defaultMethods.if.compile = function (data, buildState) {
741
801
// @ts -ignore Allow custom attribute
742
802
defaultMethods [ '===' ] . compile = function ( data , buildState ) {
743
803
if ( ! Array . isArray ( data ) ) return false
744
- if ( data . length !== 2 ) return false
745
- return buildState . compile `(${ data [ 0 ] } === ${ data [ 1 ] } )`
804
+ if ( data . length < 2 ) return false
805
+ let res = buildState . compile `(${ data [ 0 ] } === ${ data [ 1 ] } )`
806
+ for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && ${ data [ i - 1 ] } === ${ data [ i ] } )`
807
+ return res
746
808
}
747
809
// @ts -ignore Allow custom attribute
748
810
defaultMethods [ '+' ] . compile = function ( data , buildState ) {
0 commit comments