UNPKG

foxts

Version:

Opinionated collection of common TypeScript utils by @SukkaW

2 lines (1 loc) 555 B
Object.defineProperty(exports,"__esModule",{value:!0}),exports.isProbablyIpv4=function(e){if(e.length<7||e.length>15)return!1;let t=0;for(let r=0;r<e.length;r+=1){let l=e.charCodeAt(r);if(46===l)t+=1;else if(l<48||l>57)return!1}return 3===t&&46!==e.charCodeAt(0)&&46!==e.charCodeAt(e.length-1)},exports.isProbablyIpv6=function(e){if(e.length<3)return!1;let t=+("["===e[0]),r=e.length;if("]"===e[r-1]&&(r-=1),r-t>39)return!1;let l=!1;for(;t<r;t+=1){let r=e.charCodeAt(t);if(58===r)l=!0;else if((r<48||r>57)&&(r<97||r>102)&&(r<65||r>90))return!1}return l};