* Creates a boolean representation of this evaluated expression. * @returns {boolean | undefined} true: truthy, false: falsy, undefined: unknown
()
| 239 | * @returns {boolean | undefined} true: truthy, false: falsy, undefined: unknown |
| 240 | */ |
| 241 | asBool() { |
| 242 | if (this.truthy) return true; |
| 243 | if (this.falsy || this.nullish) return false; |
| 244 | if (this.isBoolean()) return this.bool; |
| 245 | if (this.isNull()) return false; |
| 246 | if (this.isUndefined()) return false; |
| 247 | if (this.isString()) return this.string !== ""; |
| 248 | if (this.isNumber()) return this.number !== 0; |
| 249 | if (this.isBigInt()) return this.bigint !== BigInt(0); |
| 250 | if (this.isRegExp()) return true; |
| 251 | if (this.isArray()) return true; |
| 252 | if (this.isConstArray()) return true; |
| 253 | if (this.isWrapped()) { |
| 254 | return (this.prefix && this.prefix.asBool()) || |
| 255 | (this.postfix && this.postfix.asBool()) |
| 256 | ? true |
| 257 | : undefined; |
| 258 | } |
| 259 | if (this.isTemplateString()) { |
| 260 | const str = this.asString(); |
| 261 | if (typeof str === "string") return str !== ""; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Creates a nullish coalescing representation of this evaluated expression. |
no test coverage detected