Skip to content

Commit 950bdd9

Browse files
committed
Mildly optimize truthiness check, add a commented out line of code that will make it easy to switch to empty object is falsy if the community votes for that.
1 parent e48cd7d commit 950bdd9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

asyncLogic.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ class AsyncLogicEngine {
5555
* @returns
5656
*/
5757
truthy (value) {
58+
if (!value) return value
5859
if (Array.isArray(value) && value.length === 0) return false
59-
if (Number.isNaN(value)) return true
60+
// Uncomment the following line to switch empty object to falsy.
61+
// if (value && typeof value === 'object') return Object.keys(value).length > 0
6062
return value
6163
}
6264

logic.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ class LogicEngine {
4646
* @returns
4747
*/
4848
truthy (value) {
49+
if (!value) return value
4950
if (Array.isArray(value) && value.length === 0) return false
50-
if (Number.isNaN(value)) return true
51+
// Uncomment the following line to switch empty object to falsy.
52+
// if (typeof value === 'object') return Object.keys(value).length > 0
5153
return value
5254
}
5355

0 commit comments

Comments
 (0)