@meld-ts/core
    Preparing search index...

    Function toBoolean

    • 将任意值转换为布尔值

      转换规则(按优先级):

      • null / undefinedfalse
      • 布尔值 → 原值
      • 数字 → > 0true,否则 false(含 0、负数、NaN
      • 字符串(不区分大小写):
        • 'true' / 'yes'true
        • 'false' / 'no'false
        • 其他 → 委托 Boolean(val)(非空为 true,空串为 false
      • 其他 → 委托 Boolean(val)

      Parameters

      • val: unknown

        — 任意值

      Returns boolean

      转换后的布尔值

      toBoolean(null);      // false
      toBoolean(1); // true
      toBoolean(0); // false
      toBoolean('true'); // true
      toBoolean('yes'); // true
      toBoolean('false'); // false
      toBoolean('no'); // false
      toBoolean('hello'); // true (非空字符串)
      toBoolean(''); // false (空字符串)
      toBoolean({}); // true