UNPKG

geoip-lite2

Version:

A light weight native JavaScript implementation of GeoIP API from MaxMind. Improved and faster version by Sefinek.

1 lines 1.3 kB
const t=module.exports={};t.aton4=t=>(t=t.split(/\./),(parseInt(t[0],10)<<24>>>0)+(parseInt(t[1],10)<<16>>>0)+(parseInt(t[2],10)<<8>>>0)+(parseInt(t[3],10)>>>0)),t.aton6=t=>{const n=(t=t.replace(/"/g,'').split(/:/)).length-1;let r;if(''===t[n]&&(t[n]=0),n<7)for(t.length=8,r=n;r>=0&&''!==t[r];r--)t[7-n+r]=t[r];for(r=0;r<8;r++)t[r]?t[r]=parseInt(t[r],16):t[r]=0;const e=[];for(r=0;r<4;r++)e.push((t[2*r]<<16)+t[2*r+1]>>>0);return e},t.cmp=(t,n)=>'number'==typeof t&&'number'==typeof n?t<n?-1:t>n?1:0:t instanceof Array&&n instanceof Array?this.cmp6(t,n):null,t.cmp6=(t,n)=>{for(let r=0;r<2;r++){if(t[r]<n[r])return-1;if(t[r]>n[r])return 1}return 0},t.isPrivateIP=t=>null!=(t=t.toString()).match(/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^172\.16\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/)||null!=t.match(/^fc00:/)||null!=t.match(/^fe80:/),t.ntoa4=t=>((t=t.toString())>>>24&255)+'.'+(t>>>16&255)+'.'+(t>>>8&255)+'.'+(255&t),t.ntoa6=t=>{let n='[';for(let r=0;r<t.length;r++)n+=(t[r]>>>16).toString(16)+':',n+=(65535&t[r]).toString(16)+':';return n=n.replace(/:$/,']').replace(/:0+/g,':').replace(/::+/,'::'),n};