import { type Factory } from './getter/getter'; import { type Maybe, type MaybeNot } from './value/maybe.type'; /** * Type representing whether something is valid. */ export type IsValid = boolean; /** * Type representing whether something is equal to something else. */ export type IsEqual = boolean; /** * Type representing whether something has been modified. */ export type IsModified = boolean; /** * A string that is either 'true' or 'false'. */ export type TrueOrFalseString = 'true' | 'false'; /** * If a non-null boolean value is provided, returns the opposite. * * @dbxUtil * @dbxUtilCategory boolean * @dbxUtilTags boolean, invert, negate, not, maybe, nullish * @dbxUtilRelated reduce-booleans-with-and, reduce-booleans-with-or * * @param x - the boolean value to invert, or a nullish value * @returns the inverted boolean, or the original nullish value if input was null/undefined */ export declare function invertMaybeBoolean(x: true): false; export declare function invertMaybeBoolean(x: false): true; export declare function invertMaybeBoolean(x: boolean): boolean; export declare function invertMaybeBoolean(x: MaybeNot): MaybeNot; export declare function invertMaybeBoolean(x: Maybe): Maybe; /** * Reduces an array of booleans with the logical AND operation. * * @param array - Array of boolean values to reduce. * @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, a TypeError will be thrown. * @returns The result of ANDing all boolean values in the array. * @throws {TypeError} If the array is empty and no emptyArrayValue is provided. * * @dbxUtil * @dbxUtilCategory boolean * @dbxUtilTags boolean, reduce, and, every, all, conjunction, aggregate * @dbxUtilRelated reduce-booleans-with-or, reduce-booleans-with-and-fn * * @example * ```ts * reduceBooleansWithAnd([true, true, true]); // true * reduceBooleansWithAnd([true, false, true]); // false * reduceBooleansWithAnd([], true); // true (emptyArrayValue) * ``` */ export declare function reduceBooleansWithAnd(array: boolean[], emptyArrayValue?: boolean): boolean; /** * Reduces an array of booleans with the logical OR operation. * * @param array - Array of boolean values to reduce. * @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, a TypeError will be thrown. * @returns The result of ORing all boolean values in the array. * @throws {TypeError} If the array is empty and no emptyArrayValue is provided. * * @dbxUtil * @dbxUtilCategory boolean * @dbxUtilTags boolean, reduce, or, some, any, disjunction, aggregate * @dbxUtilRelated reduce-booleans-with-and, reduce-booleans-with-or-fn */ export declare function reduceBooleansWithOr(array: boolean[], emptyArrayValue?: boolean): boolean; /** * Creates a function that reduces an array of booleans with the logical AND operation. * * @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, the returned function will throw a TypeError. * @returns Reducer that yields true only when every entry is truthy (or the fallback for empty input). * * @example * ```ts * const reduceAnd = reduceBooleansWithAndFn(true); * reduceAnd([true, true]); // true * reduceAnd([true, false]); // false * reduceAnd([]); // true (emptyArrayValue) * ``` */ export declare function reduceBooleansWithAndFn(emptyArrayValue?: boolean): (array: boolean[]) => boolean; /** * Creates a function that reduces an array of booleans with the logical OR operation. * * @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, the returned function will throw a TypeError. * @returns Reducer that yields true when any entry is truthy (or the fallback for empty input). * * @example * ```ts * const reduceOr = reduceBooleansWithOrFn(false); * reduceOr([false, true]); // true * reduceOr([false, false]); // false * reduceOr([]); // false (emptyArrayValue) * ``` */ export declare function reduceBooleansWithOrFn(emptyArrayValue?: boolean): (array: boolean[]) => boolean; /** * Creates a function that reduces an array of booleans using a custom reduce function. * * @param reduceFn - Function that takes two boolean values and returns a single boolean. * @param emptyArrayValue - Value to return if the array is empty. If not provided and the array is empty, the returned function will throw a TypeError because `Array.prototype.reduce` on an empty array without an initial value throws. * @returns Reducer that folds the array with `reduceFn`, falling back to `emptyArrayValue` when empty. * * @example * ```ts * const xorReduce = reduceBooleansFn((a, b) => a !== b, false); * xorReduce([true, false]); // true * xorReduce([]); // false (emptyArrayValue) * ``` */ export declare function reduceBooleansFn(reduceFn: (a: boolean, b: boolean) => boolean, emptyArrayValue?: boolean): (array: boolean[]) => boolean; /** * Factory that generates boolean values. */ export type BooleanFactory = Factory; /** * Number from 0.0 to 100.0 used for the chance to return true. * * @semanticType * @semanticTopic percent * @semanticTopic numeric */ export type BooleanTrueChance = number; /** * Configuration for `booleanFactory`. */ export interface BooleanFactoryConfig { /** * Chance of returning true, expressed as a number from 0.0 to 100.0. * For example, a value of 75 means a 75% chance of returning true. */ readonly chance: BooleanTrueChance; } /** * Creates a new BooleanFactory that generates random boolean values based on chance. * * @param config - Configuration for the boolean factory, including the chance of returning true. * @returns A factory function (`BooleanFactory`) that generates random boolean values based on the configured chance. * * @dbxUtil * @dbxUtilCategory boolean * @dbxUtilKind factory * @dbxUtilTags boolean, factory, random, chance, probability, generate * @dbxUtilRelated random-boolean * * @example * ```ts * const alwaysTrue = booleanFactory({ chance: 100 }); * alwaysTrue(); // true * * const coinFlip = booleanFactory({ chance: 50 }); * coinFlip(); // true or false with equal probability * ``` * @__NO_SIDE_EFFECTS__ */ export declare function booleanFactory(config: BooleanFactoryConfig): BooleanFactory; /** * Returns a random boolean based on the specified chance. * * @param chance - Number between 0.0 and 100.0 representing the percentage chance of returning true (default: 50, i.e., 50%). * @returns A random boolean value with the specified probability of being true. * * @dbxUtil * @dbxUtilCategory boolean * @dbxUtilTags boolean, random, chance, probability, coin-flip * @dbxUtilRelated boolean-factory */ export declare function randomBoolean(chance?: BooleanTrueChance): boolean; /** * Converts the input string to a boolean. * * Case-insensitive matches for yes/y/t/true and no/n/f/false. * * @param value - The string to convert to a boolean. * @param defaultValue - The default value to return if the string cannot be converted to a boolean (default: undefined). * @returns The boolean value corresponding to the string, or the default value if the string cannot be converted. * * @dbxUtil * @dbxUtilCategory boolean * @dbxUtilTags boolean, string, parse, convert, true, false, yes, no * @dbxUtilRelated true-or-false-string * * @example * ```ts * stringToBoolean('yes'); // true * stringToBoolean('FALSE'); // false * stringToBoolean('maybe'); // undefined * stringToBoolean('maybe', true); // true (defaultValue) * ``` */ export declare function stringToBoolean(value: Maybe): Maybe; export declare function stringToBoolean(value: Maybe, defaultValue: boolean): boolean; export declare function stringToBoolean(value: Maybe, defaultValue?: Maybe): Maybe; /** * Whether an environment flag is on: `1` or `true`, trimmed and case-insensitive. Anything else — `0`, `yes`, blank, * absent — is off. * * Not {@link stringToBoolean}: a flag that gates billed or destructive work (a live-spec lane) must be opted into * deliberately, so `yes` / `y` / `t` stay off and the conventional `1` is on. * * @param value - The raw environment value. * @returns `true` when the flag is on. * * @dbxUtil * @dbxUtilCategory boolean * @dbxUtilTags boolean, string, env, flag, parse, gate * @dbxUtilRelated string-to-boolean * * @example * ```ts * isEnvFlagEnabled(' TRUE '); // true * isEnvFlagEnabled('1'); // true * isEnvFlagEnabled('yes'); // false * isEnvFlagEnabled(undefined); // false * ``` */ export declare function isEnvFlagEnabled(value: Maybe): boolean; /** * Converts a boolean to its `'true'` or `'false'` string representation. * Returns null/undefined if the input is nullish. * * @dbxUtil * @dbxUtilCategory boolean * @dbxUtilTags boolean, string, convert, serialize, format * @dbxUtilRelated string-to-boolean * * @param value - The boolean value to convert. * @returns The string `'true'` or `'false'`, or the nullish input unchanged. */ export declare function trueOrFalseString(value: boolean): TrueOrFalseString; export declare function trueOrFalseString(value?: MaybeNot): MaybeNot; export declare function trueOrFalseString(value?: Maybe): Maybe;