util-helpers
Version:
33 lines (32 loc) • 1.05 kB
TypeScript
/**
* 检测值是否为url
*
* @alias module:Validator.isUrl
* @since 3.4.0
* @see {@link https://zh.wikipedia.org/wiki/统一资源定位符 统一资源定位符}
* @param {*} value 要检测的值
* @returns {boolean} 值是否为url
* @example
*
* isUrl(''); // false
* isUrl('/foo/bar'); // false
*
* isUrl('8.8.8.8'); // true
* isUrl('example.com'); // true
* isUrl('http://example.com'); // true
* isUrl('https://example.com:8080'); // true
* isUrl('https://www.example.com/test/123'); // true
* isUrl('https://www.example.com/test/123?foo=bar'); // true
* isUrl('https://www.example.com/test/123?foo=中文#id'); // true
* isUrl('https://www.example.com/test/123?foo=中文#测试'); // true
* isUrl('ftp://127.0.0.1:8080/测试.tar'); // true
* isUrl('a.b'); // true
* isUrl('a.b:8080'); // true
* isUrl('p://a.b'); // true
* isUrl('p://a.b:8888'); // true
* isUrl('中文域名.中文后缀'); // true
* isUrl('中文域名.cn'); // true
*
*/
declare function isUrl(value: any): boolean;
export default isUrl;