index.ts 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // @ts-nocheck
  2. import { isNumber } from '../isNumber'
  3. import { isString } from '../isString'
  4. // 函数重载,定义多个函数签名
  5. // function toBoolean(value : any) : boolean;
  6. // function toBoolean(value : string) : boolean;
  7. // function toBoolean(value : number) : boolean;
  8. // function toBoolean(value : boolean) : boolean;
  9. // #ifdef UNI-APP-X && APP
  10. function toBoolean(value : any | null) : boolean {
  11. // 根据输入值的类型,返回相应的布尔值
  12. // if (isNumber(value)) {
  13. // return (value as number) != 0;
  14. // }
  15. // if (isString(value)) {
  16. // return `${value}`.length > 0;
  17. // }
  18. // if (typeof value == 'boolean') {
  19. // return value as boolean;
  20. // }
  21. // #ifdef APP-IOS
  22. return value != null && value != undefined
  23. // #endif
  24. // #ifdef APP-ANDROID
  25. return value != null
  26. // #endif
  27. }
  28. // #endif
  29. // #ifndef UNI-APP-X && APP
  30. function toBoolean(value : any | null) : value is NonNullable<typeof value> {
  31. return !!value//value !== null && value !== undefined;
  32. }
  33. // #endif
  34. export {
  35. toBoolean
  36. }