Added jsTruthy flag to constuctor in order to enable JS style truthiness evaluation

This commit is contained in:
Amit Gupta
2020-10-08 12:43:37 +08:00
committed by Jun Yang
parent b11df79b91
commit 02bfed1c57
10 changed files with 89 additions and 17 deletions
+13 -4
View File
@@ -1,6 +1,15 @@
export function isTruthy (val: any): boolean {
return !isFalsy(val)
import { Context } from '../context/context'
export function isTruthy (val: any, ctx: Context): boolean {
if ((val === null) && ctx && ctx.opts && ctx.opts.jsTruthy ) return false;
return !isFalsy(val, ctx)
}
export function isFalsy (val: any): boolean {
return val === false || undefined === val || val === null
export function isFalsy (val: any, ctx: Context): boolean {
if(ctx && ctx.opts && ctx.opts.jsTruthy) {
return val == false
}
else {
return val === false || undefined === val || val === null
}
}