1- []
1+ [
2+ " Boolean checks" ,
3+ {
4+ "description" : " true is true, and uses the then" ,
5+ "rule" : { "if" : [true , " apple" , " banana" ] },
6+ "data" : null ,
7+ "result" : " apple"
8+ },
9+ {
10+ "description" : " false is false, and uses the fallback" ,
11+ "rule" : { "if" : [false , " apple" , " banana" ] },
12+ "data" : null ,
13+ "result" : " banana"
14+ },
15+ " Null check" ,
16+ {
17+ "description" : " null is falsy" ,
18+ "rule" : { "if" : [[], " apple" , " banana" ] },
19+ "data" : null ,
20+ "result" : " banana"
21+ },
22+ " Object checks" ,
23+ {
24+ "description" : " Objects are always truthy, even without keys." ,
25+ "rule" : { "if" : [{}, " apple" , " banana" ] },
26+ "data" : null ,
27+ "result" : " apple"
28+ },
29+ {
30+ "description" : " Objects are always truthy, with keys defined" ,
31+ "rule" : { "if" : [{ "val" : [] }, " apple" , " banana" ] },
32+ "data" : { "some" : " value" },
33+ "result" : " apple"
34+ },
35+ " Array checks" ,
36+ {
37+ "description" : " Empty array is falsy" ,
38+ "rule" : { "if" : [[], " apple" , " banana" ] },
39+ "data" : null ,
40+ "result" : " banana"
41+ },
42+ {
43+ "description" : " Array with single element is truthy" ,
44+ "rule" : { "if" : [[1 ], " apple" , " banana" ] },
45+ "data" : null ,
46+ "result" : " apple"
47+ },
48+ {
49+ "description" : " Array with multiple elements is truthy" ,
50+ "rule" : { "if" : [[1 , 2 , 3 , 4 ], " apple" , " banana" ] },
51+ "data" : null ,
52+ "result" : " apple"
53+ },
54+ " String checks" ,
55+ {
56+ "description" : " Empty string is falsy" ,
57+ "rule" : { "if" : [" " , " apple" , " banana" ] },
58+ "data" : null ,
59+ "result" : " banana"
60+ },
61+ {
62+ "description" : " Any non-empty string is truthy" ,
63+ "rule" : { "if" : [" zucchini" , " apple" , " banana" ] },
64+ "data" : null ,
65+ "result" : " apple"
66+ },
67+ {
68+ "description" : " Any non-empty string is truthy, even 0" ,
69+ "rule" : { "if" : [" 0" , " apple" , " banana" ] },
70+ "data" : null ,
71+ "result" : " apple"
72+ },
73+ " Too few arguments" ,
74+ {
75+ "description" : " No arguments is just null." ,
76+ "rule" : { "if" : [] },
77+ "data" : null ,
78+ "result" : null
79+ },
80+ {
81+ "description" : " If no then is defined when true, it'll just return null." ,
82+ "rule" : { "if" : [true ] },
83+ "data" : null ,
84+ "result" : true
85+ },
86+ {
87+ "description" : " If no fallback is defined when falsy, it'll just return null." ,
88+ "rule" : { "if" : [false ] },
89+ "data" : null ,
90+ "result" : false
91+ },
92+ {
93+ "description" : " If no then is defined when truthy, it'll just return null." ,
94+ "rule" : { "if" : [" apple" ] },
95+ "data" : null ,
96+ "result" : " apple"
97+ },
98+ {
99+ "description" : " When truthy, it'll return the 'then' even if no fallback is defined." ,
100+ "rule" : { "if" : [true , " apple" ] },
101+ "data" : null ,
102+ "result" : " apple"
103+ },
104+ {
105+ "description" : " When falsy, it'll return null if the fallback is not defined, even if the 'then' is defined." ,
106+ "rule" : { "if" : [false , " apple" ] },
107+ "data" : null ,
108+ "result" : null
109+ },
110+ " Variadic Tests" ,
111+ {
112+ "description" : " Returns the first truthy if condition" ,
113+ "rule" : { "if" : [true , " apple" , false , " banana" ] },
114+ "data" : null ,
115+ "result" : " apple"
116+ },
117+ {
118+ "description" : " Returns the first truthy then condition, even if multiple conditions are true" ,
119+ "rule" : { "if" : [true , " apple" , true , " banana" ] },
120+ "data" : null ,
121+ "result" : " apple"
122+ },
123+ {
124+ "description" : " Retuns the first truthy condition, with the fallback defined." ,
125+ "rule" : { "if" : [true , " apple" , false , " banana" , " carrot" ] },
126+ "data" : null ,
127+ "result" : " apple"
128+ },
129+ {
130+ "description" : " Returns the first truthy condition, with the fallback defined; multiple true conditions." ,
131+ "rule" : { "if" : [true , " apple" , true , " banana" , " carrot" ] },
132+ "data" : null ,
133+ "result" : " apple"
134+ },
135+ {
136+ "description" : " Returns the first truthy condition, with the first condition falsy. Fallback defined." ,
137+ "rule" : { "if" : [false , " apple" , true , " banana" , " carrot" ] },
138+ "data" : null ,
139+ "result" : " banana"
140+ },
141+ {
142+ "description" : " Returns the first truthy condition, in this case it's the 2nd one." ,
143+ "rule" : { "if" : [false , " apple" , true , " banana" ] },
144+ "data" : null ,
145+ "result" : " banana"
146+ },
147+ {
148+ "description" : " When none of the conditions are true, it returns the fallback." ,
149+ "rule" : { "if" : [false , " apple" , false , " banana" , " carrot" ] },
150+ "data" : null ,
151+ "result" : " carrot"
152+ },
153+ {
154+ "description" : " When none of the conditions are true, it returns the fallback. In this case the fallback is not defined, so it is null." ,
155+ "rule" : { "if" : [false , " apple" , false , " banana" ] },
156+ "data" : null ,
157+ "result" : null
158+ },
159+ {
160+ "description" : " 3 Conditions, all falsy. Returns fallback." ,
161+ "rule" : { "if" : [false , " apple" , false , " banana" , false , " carrot" , " date" ] },
162+ "data" : null ,
163+ "result" : " date"
164+ },
165+ {
166+ "description" : " 3 Conditions, all falsy, no fallback defined. Returns null." ,
167+ "rule" : { "if" : [false , " apple" , false , " banana" , false , " carrot" ] },
168+ "data" : null ,
169+ "result" : null
170+ },
171+ {
172+ "description" : " First condition truthy, 3 conditions." ,
173+ "rule" : { "if" : [true , " apple" , false , " banana" , false , " carrot" , " date" ] },
174+ "data" : null ,
175+ "result" : " apple"
176+ },
177+
178+ {
179+ "description" : " 2nd Condition is Truthy" ,
180+ "rule" : { "if" : [false , " apple" , true , " banana" , false , " carrot" , " date" ] },
181+ "data" : null ,
182+ "result" : " banana"
183+ },
184+ {
185+ "description" : " Third Condition is Truthy" ,
186+ "rule" : { "if" : [false , " apple" , false , " banana" , true , " carrot" , " date" ] },
187+ "data" : null ,
188+ "result" : " carrot"
189+ },
190+ {
191+ "description" : " Returns first truthy value, some conditions truthy" ,
192+ "rule" : { "if" : [false , " apple" , true , " banana" , true , " carrot" , " date" ] },
193+ "data" : null ,
194+ "result" : " banana"
195+ },
196+ {
197+ "description" : " Returns first truthy value, some conditions truthy (2)" ,
198+ "rule" : { "if" : [true , " apple" , false , " banana" , true , " carrot" , " date" ] },
199+ "data" : null ,
200+ "result" : " apple"
201+ },
202+ {
203+ "description" : " Returns first truthy value, some conditions truthy (3)" ,
204+ "rule" : { "if" : [true , " apple" , true , " banana" , false , " carrot" , " date" ] },
205+ "data" : null ,
206+ "result" : " apple"
207+ },
208+ {
209+ "description" : " Returns first truthy value, all conditions truthy" ,
210+ "rule" : { "if" : [true , " apple" , true , " banana" , true , " carrot" , " date" ] },
211+ "data" : null ,
212+ "result" : " apple"
213+ },
214+ " Some Variadic Checks with Other Types" ,
215+ {
216+ "description" : " Returns first truthy value, some conditions truthy (4)" ,
217+ "rule" : { "if" : [false , " apple" , [1 ], " banana" , true , " carrot" , " date" ] },
218+ "data" : null ,
219+ "result" : " banana"
220+ },
221+ {
222+ "description" : " Returns first truthy value, some conditions truthy (5)" ,
223+ "rule" : { "if" : [false , " apple" , " This is true" , " banana" , true , " carrot" , " date" ] },
224+ "data" : null ,
225+ "result" : " banana"
226+ },
227+ {
228+ "description" : " Returns first truthy value, some conditions truthy (6)" ,
229+ "rule" : { "if" : [null , " apple" , 0 , " banana" , 7 , " carrot" , " date" ] },
230+ "data" : null ,
231+ "result" : " carrot"
232+ },
233+ {
234+ "description" : " Returns first truthy value, some conditions truthy (7)" ,
235+ "rule" : { "if" : [" 0" , " apple" , 0 , " banana" , 7 , " carrot" , " date" ] },
236+ "data" : null ,
237+ "result" : " apple"
238+ },
239+ {
240+ "description" : " Returns first truthy value, some conditions truthy (8)" ,
241+ "rule" : { "if" : [{}, " apple" , 0 , " banana" , 7 , " carrot" , " date" ] },
242+ "data" : null ,
243+ "result" : " apple"
244+ }
245+ ]
0 commit comments