(api: string)
| 910 | } |
| 911 | |
| 912 | export function isValidApi(api: string) { |
| 913 | if (!api || typeof api !== 'string') { |
| 914 | return false; |
| 915 | } |
| 916 | const idx = api.indexOf('://'); |
| 917 | |
| 918 | // 不允许 :// 结尾 |
| 919 | if (~idx && idx + 3 === api.length) { |
| 920 | return false; |
| 921 | } |
| 922 | |
| 923 | try { |
| 924 | // 不补一个协议,URL 判断为 false |
| 925 | api = (~idx ? '' : `schema://domain${api[0] === '/' ? '' : '/'}`) + api; |
| 926 | new URL(api); |
| 927 | } catch (error) { |
| 928 | return false; |
| 929 | } |
| 930 | return true; |
| 931 | } |
| 932 | |
| 933 | export function isEffectiveApi( |
| 934 | api?: Api, |
no outgoing calls
no test coverage detected