haw-utils
Version:
一个基于业务场景的工具方法库
56 lines (54 loc) • 1.4 kB
JavaScript
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(["exports"], factory);
} else if (typeof exports !== "undefined") {
factory(exports);
} else {
var mod = {
exports: {}
};
factory(mod.exports);
global.isUrl = mod.exports;
}
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) {
"use strict";
Object.defineProperty(_exports, "__esModule", {
value: true
});
_exports["default"] = void 0;
// url正则
var reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
/**
* 检测值是否为url
*
* @static
* @alias module:Validator.isUrl
* @since 3.4.0
* @param {String} value 要检测的值
* @returns {Boolean} 值是否为url
* @example
*
* isUrl('');
* // => false
*
* isUrl('8.8.8.8');
* // => false
*
* isUrl('http://example.com');
* // => true
*
* isUrl('https://example.com:8080');
* // => true
*
* isUrl('http://www.example.com/test/123');
* // => true
*
* isUrl('http://www.example.com/test/123?foo=bar');
* // => true
*/
function isUrl(value) {
return reg.test(value);
}
var _default = isUrl;
_exports["default"] = _default;
});