foxts
Version:
Opinionated collection of common TypeScript utils by @SukkaW
1 lines • 549 B
JavaScript
;function t(t){const r=t.length;if(r<7||r>15)return!1;let e=0;for(let o=0;o<r;o+=1){const r=t.charCodeAt(o);if(46===r)e+=1;else if(r<48||r>57)return!1}return 3===e&&46!==t.charCodeAt(0)&&46!==t.charCodeAt(r-1)}function r(t){const r=t.length;if(r<3)return!1;let e=+("["===t[0]),o=r;if("]"===t[o-1]&&(o-=1),o-e>39)return!1;let n=!1;for(;e<o;e+=1){const r=t.charCodeAt(e);if(58===r)n=!0;else if((r<48||r>57)&&(r<97||r>102)&&(r<65||r>90))return!1}return n}exports.isProbablyIp=e=>t(e)||r(e),exports.isProbablyIpv4=t,exports.isProbablyIpv6=r;