Files
LitePan/core/utils.py
T
2026-05-26 09:10:51 +08:00

19 lines
463 B
Python

"""通用工具函数。"""
from typing import Any
def normalize_bool(value: Any, default: bool) -> bool:
if value is None:
return default
if isinstance(value, bool):
return value
if isinstance(value, (int, float)):
return bool(value)
text = str(value).strip().lower()
if text in ("0", "false", "no", "off", ""):
return False
if text in ("1", "true", "yes", "on"):
return True
return default