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