/** * utilities for working with JS booleans * * @module */ import * as Either from "effect/Either"; import { type Codec } from "./Codec.js"; /** * non-strict boolean codec, takes any truthy value as true. * Useful for DOM related operations */ export const contentAttribute__boolean: Codec = { encode: (value: boolean | undefined) => Either.right(value ? "" : undefined), decode: (value: unknown) => Either.right(value === "" ? true : !!value), }; /** * nearly the same as {@see contentAttribute__boolean} except * for that it transforms to "true" or "false" and only interprets * the string "true" as true. */ export const ariaAttribute__boolean: Codec = { encode: (value: boolean) => Either.right(String(value)), decode: (value: unknown) => Either.right( typeof value === "boolean" ? value : value === "true" ? true : false, ), };