UNPKG

haw-utils

Version:

一个基于业务场景的工具方法库

76 lines (74 loc) 2.63 kB
(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.isIPv6 = 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; // ipv6正则 var reg = /^((([0-9A-F]{1,4}:){7}([0-9A-F]{1,4}|:))|(([0-9A-F]{1,4}:){6}(:[0-9A-F]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){5}(((:[0-9A-F]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3})|:))|(([0-9A-F]{1,4}:){4}(((:[0-9A-F]{1,4}){1,3})|((:[0-9A-F]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){3}(((:[0-9A-F]{1,4}){1,4})|((:[0-9A-F]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){2}(((:[0-9A-F]{1,4}){1,5})|((:[0-9A-F]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(([0-9A-F]{1,4}:){1}(((:[0-9A-F]{1,4}){1,6})|((:[0-9A-F]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:))|(:(((:[0-9A-F]{1,4}){1,7})|((:[0-9A-F]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|\d{1,2})(\.(25[0-5]|2[0-4]\d|1\d\d|\d{1,2})){3}))|:)))(%.+)?$/i; /** * 检测值是否为ipv6 * * @static * @alias module:Validator.isIPv6 * @since 1.1.0 * @param {String} value 要检测的值 * @returns {Boolean} 值是否为ipv6 * @example * * // 冒分十六进制表示法 * isIPv6('2001:0DB8:0000:0023:0008:0800:200C:417A'); * // => true * * // 前导0省略 * isIPv6('2001:DB8:0:23:8:800:200C:417A'); * // => true * * isIPv6('FF01:0:0:0:0:0:0:1101'); * // => true * * // 0位压缩表示法 * isIPv6('FF01::1101'); * // => true * * isIPv6('::1'); * // => true * * isIPv6('::'); * // => true * * isIPv6('0:0:0:0:0:0:0:1'); * // => true * * isIPv6('0:0:0:0:0:0:0:0'); * // => true * * // 内嵌IPv4地址表示法 * isIPv6('::192.168.1.1'); * // => true * * isIPv6('::FFFF:192.168.1.1'); * // => true * * isIPv6('192.168.1.1'); * // => false * */ function isIPv6(value) { return reg.test(value); } var _default = isIPv6; _exports["default"] = _default; });