Skip to content

Commit 5dac1cc

Browse files
committed
Switch from false to null for and/or zero arguments
1 parent 2dce67c commit 5dac1cc

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

defaultMethods.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ const defaultMethods = {
230230
[Sync]: (data, buildState) => isSyncDeep(data, buildState.engine, buildState),
231231
method: (arr, context, above, engine) => {
232232
if (!Array.isArray(arr)) throw INVALID_ARGUMENTS
233-
if (!arr.length) return false
233+
if (!arr.length) return null
234234

235235
let item
236236
for (let i = 0; i < arr.length; i++) {
@@ -242,7 +242,7 @@ const defaultMethods = {
242242
},
243243
asyncMethod: async (arr, _1, _2, engine) => {
244244
if (!Array.isArray(arr)) throw INVALID_ARGUMENTS
245-
if (!arr.length) return false
245+
if (!arr.length) return null
246246

247247
let item
248248
for (let i = 0; i < arr.length; i++) {
@@ -256,7 +256,7 @@ const defaultMethods = {
256256
compile: (data, buildState) => {
257257
let res = buildState.compile``
258258
if (Array.isArray(data)) {
259-
if (!data.length) return buildState.compile`false`
259+
if (!data.length) return buildState.compile`null`
260260
for (let i = 0; i < data.length; i++) res = buildState.compile`${res} engine.truthy(prev = ${data[i]}) ? prev : `
261261
res = buildState.compile`${res} prev`
262262
return res
@@ -388,7 +388,7 @@ const defaultMethods = {
388388
[Sync]: (data, buildState) => isSyncDeep(data, buildState.engine, buildState),
389389
method: (arr, context, above, engine) => {
390390
if (!Array.isArray(arr)) throw INVALID_ARGUMENTS
391-
if (!arr.length) return false
391+
if (!arr.length) return null
392392

393393
let item
394394
for (let i = 0; i < arr.length; i++) {
@@ -399,7 +399,7 @@ const defaultMethods = {
399399
},
400400
asyncMethod: async (arr, _1, _2, engine) => {
401401
if (!Array.isArray(arr)) throw INVALID_ARGUMENTS
402-
if (!arr.length) return false
402+
if (!arr.length) return null
403403
let item
404404
for (let i = 0; i < arr.length; i++) {
405405
item = await engine.run(arr[i], _1, { above: _2 })
@@ -412,7 +412,7 @@ const defaultMethods = {
412412
compile: (data, buildState) => {
413413
let res = buildState.compile``
414414
if (Array.isArray(data)) {
415-
if (!data.length) return buildState.compile`false`
415+
if (!data.length) return buildState.compile`null`
416416
for (let i = 0; i < data.length; i++) res = buildState.compile`${res} !engine.truthy(prev = ${data[i]}) ? prev : `
417417
res = buildState.compile`${res} prev`
418418
return res

suites/control/and.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"description": "And with no arguments should return false",
125125
"rule": { "and": [] },
126126
"data": null,
127-
"result": false
127+
"result": null
128128
},
129129
"Valid Arguments Checks",
130130
{

suites/control/if.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"Null check",
1616
{
1717
"description": "null is falsy",
18-
"rule": { "if": [[], "apple", "banana"] },
18+
"rule": { "if": [null, "apple", "banana"] },
1919
"data": null,
2020
"result": "banana"
2121
},
@@ -78,19 +78,19 @@
7878
"result": null
7979
},
8080
{
81-
"description": "If no then is defined when true, it'll just return null.",
81+
"description": "If no 'then' is defined, it should return the first argument (true)",
8282
"rule": { "if": [true] },
8383
"data": null,
8484
"result": true
8585
},
8686
{
87-
"description": "If no fallback is defined when falsy, it'll just return null.",
87+
"description": "If no 'then' is defined, it should return the first argument (false)",
8888
"rule": { "if": [false] },
8989
"data": null,
9090
"result": false
9191
},
9292
{
93-
"description": "If no then is defined when truthy, it'll just return null.",
93+
"description": "If no 'then' is defined, it should return the first argument (apple string)",
9494
"rule": { "if": ["apple"] },
9595
"data": null,
9696
"result": "apple"

suites/control/or.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"description": "Or with no arguments should return false",
125125
"rule": { "or": [] },
126126
"data": null,
127-
"result": false
127+
"result": null
128128
},
129129
"Valid Arguments Checks",
130130
{

0 commit comments

Comments
 (0)