All files / src/entities utils.ts

100% Statements 11/11
100% Branches 4/4
100% Functions 1/1
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2118x   18x   18x 126x 53x   73x 73x 73x   2x   71x     18x      
import { z } from "zod";
 
const DEFAULT_NULL = process.env.DEFAULT_NULL === "true";
 
export const flexibleBoolean = z.preprocess(val => {
  if (typeof val === "boolean") {
    return val;
  }
  let result = "false";
  try {
    result = String(val).toLowerCase();
  } catch {
    return false;
  }
  return ["true", "t", "1"].includes(result);
}, z.boolean());
 
export const flexibleBooleanNullable = DEFAULT_NULL
  ? flexibleBoolean.nullable().default(null)
  : flexibleBoolean.nullable();