Appearance
super-tools-lib - v1.74.0 / Modules / is
Module: is
Table of contents
Functions
- isAndroidMobileDevice
- isAppleMobileDevice
- isArray
- isBase64
- isBasicType
- isConsole
- isDarkMode
- isDate
- isDescendant
- isEmptyArray
- isEmptyObject
- isError
- isEven
- isFunction
- isHexColor
- isImg
- isMap
- isMobile
- isNaN
- isNull
- isNumber
- isObject
- isObjectAbsentKeys
- isObjectExistsKey
- isObjectHasKeysIsValue
- isObjectIncludeSpecifiedKey
- isObjectKeyEqual
- isOdd
- isPointInPolygon
- isPromise
- isRegExp
- isSet
- isString
- isSupportWebP
- isSymbol
- isUndefined
- isUrl
- isValue
- isWeiXin
- returnType
Functions
isAndroidMobileDevice
▸ isAndroidMobileDevice(): boolean
判断是否安卓移动设备访问
Since
1.0.0
Example
ts
import { isAndroidMobileDevice } from 'super-tools-lib'
isAndroidMobileDevice() // true | false
Returns
boolean
返回true | false
isAppleMobileDevice
▸ isAppleMobileDevice(): boolean
判断是否苹果移动设备访问
Since
1.0.0
Example
ts
import { isAppleMobileDevice } from 'super-tools-lib'
isAppleMobileDevice() // true | false
Returns
boolean
返回true | false
isArray
▸ isArray(arr
): boolean
数组类型验证
Since
1.0.0
Example
ts
import { isArray } from 'super-tools-lib'
isArray(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
arr | unknown | 要检查的值 |
Returns
boolean
返回true | false
isBase64
▸ isBase64(base64
): boolean
base64类型验证
Since
1.0.0
Example
ts
import { isBase64 } from 'super-tools-lib'
isBase64(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
base64 | string | 要检查的值 |
Returns
boolean
返回true | false
isBasicType
▸ isBasicType(val
): boolean
判断是否是基本数据类型
Since
1.0.0
Example
ts
import { isBasicType } from 'super-tools-lib'
isBasicType(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
val | unknown | 要检查的值 |
Returns
boolean
返回true | false
isConsole
▸ isConsole(): boolean
检查浏览器是否打开了控制台
Since
1.0.0
Example
ts
import { isConsole } from 'super-tools-lib'
isConsole() // true | false
Returns
boolean
返回是否打开了控制台
isDarkMode
▸ isDarkMode(): boolean
检测暗模式
Since
1.0.0
Example
ts
import { isDarkMode } from 'super-tools-lib'
isDarkMode() // true | false
Returns
boolean
isDate
▸ isDate(o
): boolean
是否时间
Since
1.0.0
Example
ts
import { isDate } from 'super-tools-lib'
isDate(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
o | unknown | 要检查的值 |
Returns
boolean
返回true | false
isDescendant
▸ isDescendant(child
, parent
): boolean
检查某个元素是否是另一个元素的后代
Since
1.62.0
Parameters
Name | Type | Description |
---|---|---|
child | Node | 子级元素 |
parent | Node | 父级元素 |
Returns
boolean
isEmptyArray
▸ isEmptyArray<T
>(arr
): boolean
检查数组是否为空
Since
1.0.0
Example
ts
import { isEmptyArray } from 'super-tools-lib'
isEmptyArray(val) // true | false
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
arr | T [] |
Returns
boolean
返回true | false
isEmptyObject
▸ isEmptyObject(obj
): boolean
判断对象是否为空
Since
1.0.0
Example
ts
import { isEmptyObject } from 'super-tools-lib'
isEmptyObject(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
obj | Record <string , unknown > | 要检查的值 |
Returns
boolean
返回true | false
isError
▸ isError(o
): boolean
是否错误对象
Since
1.0.0
Example
ts
import { isError } from 'super-tools-lib'
isError(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
o | unknown | 要检查的值 |
Returns
boolean
返回true | false
isEven
▸ isEven(v
): boolean
检测数字是否为偶数
Since
1.62.0
Example
ts
import { isEven } from 'super-tools-lib'
isEven(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
v | number | 要检查的值 |
Returns
boolean
返回true | false
isFunction
▸ isFunction(fn
): boolean
函数类型验证
Since
1.0.0
Example
ts
import { isFunction } from 'super-tools-lib'
isFunction(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
fn | unknown | 要检查的值 |
Returns
boolean
返回true | false
isHexColor
▸ isHexColor(color
): boolean
检查字符串是否为十六进制颜色
Since
1.0.0
Example
ts
import { isHexColor } from 'super-tools-lib'
isHexColor(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
color | string | 要检查的值 |
Returns
boolean
返回true | false
isImg
▸ isImg(path
): boolean
判断是否是图片链接
Since
1.0.0
Example
ts
import { isImg } from 'super-tools-lib'
isImg(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
path | string | 要检查的值 |
Returns
boolean
返回true | false
isMap
▸ isMap(v
): boolean
检查是否是Map对象
Since
1.0.0
Example
ts
import { isMap } from 'super-tools-lib'
isMap(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
v | unknown | 要检查的值 |
Returns
boolean
返回true | false
isMobile
▸ isMobile(): boolean
判断是否为移动端
Since
1.0.0
Example
ts
import { isMobile } from 'super-tools-lib'
isMobile() // true | false
Returns
boolean
返回true | false
isNaN
▸ isNaN(value
): boolean
检查 value 是否为NaN
Since
1.72.0
Example
ts
import { isNaN } from 'super-tools-lib'
isNaN(NaN) // true
isNaN(1) // false
Parameters
Name | Type | Description |
---|---|---|
value | unknown | 要检查的值 |
Returns
boolean
true | false
isNull
▸ isNull(o
): boolean
检测是否为null
Since
1.0.0
Example
ts
import { isNull } from 'super-tools-lib'
isNull(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
o | unknown | 要检查的值 |
Returns
boolean
返回true | false
isNumber
▸ isNumber(num
): num is number
数字类型验证
Since
1.0.0
Example
ts
import { isNumber } from 'super-tools-lib'
isNumber(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
num | unknown | 要检查的值 |
Returns
num is number
返回true | false
isObject
▸ isObject(obj
): boolean
对象类型验证
Since
1.0.0
Example
ts
import { isObject } from 'super-tools-lib'
isObject(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
obj | unknown | 要检查的值 |
Returns
boolean
返回true | false
isObjectAbsentKeys
▸ isObjectAbsentKeys<T
>(obj
, keys?
): boolean
检查对象是否缺少指定的键
Since
1.72.0
Example
ts
import { isObjectAbsentKeys } from 'super-tools-lib'
isObjectAbsentKeys({ a: 1, b: 2 }, ['a']) // false
isObjectAbsentKeys({ a: 1, b: 2 }, ['c']) // true
Type parameters
Name |
---|
T |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
obj | Record <string , T > | undefined | 要检查的对象 |
keys? | string [] | [] | 要检查的键 |
Returns
boolean
true | false
isObjectExistsKey
▸ isObjectExistsKey(obj
, key
): boolean
判断一个对象内是否包含指定的键
Since
1.0.0
Example
ts
import { isObjectExistsKey } from 'super-tools-lib'
isObjectExistsKey({a:1},'1') // true
Parameters
Name | Type | Description |
---|---|---|
obj | Record <string , unknown > | 对象 |
key | string | 要检查的值 |
Returns
boolean
返回true | false
isObjectHasKeysIsValue
▸ isObjectHasKeysIsValue<T
>(obj
, keys?
): boolean
检查对象是否有指定的key,并且key对应的value不为null / undefined / NaN / Infinity / -Infinity / ''
Since
1.72.0
Type parameters
Name |
---|
T |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
obj | Record <string , T > | undefined | 要检查的对象 |
keys? | string [] | [] | 要检查的键 |
Returns
boolean
isObjectIncludeSpecifiedKey
▸ isObjectIncludeSpecifiedKey(a
, b
): boolean
判断a对象是否包含b对象的键
Since
1.0.0
Example
ts
import { isObjectIncludeSpecifiedKey } from 'super-tools-lib'
isObjectIncludeSpecifiedKey({a: 1, v: 2}, {v: 1}) // true
Parameters
Name | Type | Description |
---|---|---|
a | Record <string , unknown > | 要检查的值 |
b | Record <string , unknown > | 要检查的值 |
Returns
boolean
返回true | false
isObjectKeyEqual
▸ isObjectKeyEqual(a
, b
): boolean
判断两个对象是否拥有一样的键
Since
1.0.0
Example
ts
import { isObjectKeyEqual } from 'super-tools-lib'
isObjectKeyEqual({a:1}, {a:2}) // true
Parameters
Name | Type | Description |
---|---|---|
a | Record <string , unknown > | 要检查的值 |
b | Record <string , unknown > | 要检查的值 |
Returns
boolean
返回true | false
isOdd
▸ isOdd(v
): boolean
检测数字是否为奇数
Since
1.62.0
Example
ts
import { isOdd } from 'super-tools-lib'
isOdd(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
v | number | 要检查的值 |
Returns
boolean
返回true | false
isPointInPolygon
▸ isPointInPolygon(point
, polygon
): boolean
检查点是否在多边形内
Since
1.72.0
Example
ts
import { isPointInPolygon } from 'super-tools-lib'
isPointInPolygon({ x: 1, y: 1 }, [{ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 2, y: 2 }, { x: 0, y: 2 }]) // true
Parameters
Name | Type | Description |
---|---|---|
point | Point | 点 |
polygon | Polygon | 多边形 |
Returns
boolean
true | false
isPromise
▸ isPromise(o
): boolean
是否Promise对象
Since
1.0.0
Example
ts
import { isPromise } from 'super-tools-lib'
isPromise(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
o | unknown | 要检查的值 |
Returns
boolean
返回true | false
isRegExp
▸ isRegExp(o
): boolean
是否正则
Since
1.0.0
Example
ts
import { isRegExp } from 'super-tools-lib'
isRegExp(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
o | unknown | 要检查的值 |
Returns
boolean
返回true | false
isSet
▸ isSet(v
): boolean
检查是否是Set对象
Since
1.0.0
Example
ts
import { isSet } from 'super-tools-lib'
isSet(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
v | unknown | 要检查的值 |
Returns
boolean
返回true | false
isString
▸ isString(str
): boolean
字符串类型验证
Since
1.0.0
Example
ts
import { isString } from 'super-tools-lib'
isString(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
str | unknown | 要检查的值 |
Returns
boolean
返回true | false
isSupportWebP
▸ isSupportWebP(): boolean
判断浏览器是否支持webP格式图片
Since
1.0.0
Example
ts
import { isSupportWebP } from 'super-tools-lib'
isSupportWebP(val) // true | false
Returns
boolean
返回true | false
isSymbol
▸ isSymbol(o
): boolean
是否Symbol函数
Since
1.0.0
Example
ts
import { isSymbol } from 'super-tools-lib'
isSymbol(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
o | unknown | 要检查的值 |
Returns
boolean
返回true | false
isUndefined
▸ isUndefined(o
): boolean
检测是否undefined
Since
1.0.0
Example
ts
import { isUndefined } from 'super-tools-lib'
isUndefined(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
o | unknown | 要检查的值 |
Returns
boolean
返回true | false
isUrl
▸ isUrl(path
): boolean
判断是否为url链接
Since
1.0.0
Example
ts
import { isUrl } from 'super-tools-lib'
isUrl(val) // true | false
Parameters
Name | Type | Description |
---|---|---|
path | string | 要检查的值 |
Returns
boolean
返回true | false
isValue
▸ isValue(value
): boolean
检查 value 不是 null / undefined / NaN / Infinity / -Infinity / ''
Since
1.72.0
Example
ts
import { isValue } from 'super-tools-lib'
isValue('') // true | false
Parameters
Name | Type | Description |
---|---|---|
value | unknown | 要检查的值 |
Returns
boolean
true | false
isWeiXin
▸ isWeiXin(): boolean
判断是否在微信中打开
Since
1.0.0
Example
ts
import { isWeiXin } from 'super-tools-lib'
isWeiXin() // true | false
Returns
boolean
返回true | false
returnType
▸ returnType(o
): unknown
返回类型
Since
1.0.0
Example
ts
import { returnType } from 'super-tools-lib'
returnType(val) // Boolean | String ...
Parameters
Name | Type | Description |
---|---|---|
o | unknown | 要检查的值 |
Returns
unknown
返回值的类型