Skip to content

Home > @zero-dim/utils > isExternal

isExternal() function

判断字符串是否为外部链接(http:,https:,mailto:,tel:开头)

Signature:

typescript
export declare function isExternal(val: any): boolean;

Parameters

Parameter

Type

Description

val

any

要检查的字符串

**Returns:**

boolean

如果是外部链接则返回true,否则返回false

Remarks

支持的协议: - http: - https: - mailto: - tel:

Example

ts
isExternal('https://example.com')     // true
isExternal('mailto:test@test.com')    // true
isExternal('tel:123456789')           // true
isExternal('/path/to/file')           // false