{"version":3,"sources":["ip.js"],"names":["_normalizeFamily","family","toLowerCase","priority","name","startsWith","isLoopback","addr","test","isPrivate","isPublic","loopback","Error","address","interfaces","os","networkInterfaces","all","res","filter","details","itemFamily","length","undefined","sortedInterfaces","Object","keys","sort","a","b","map","nic","addresses","Boolean"],"mappings":";;;;;;AAEA;;;;AAEA,SAASA,gBAAT,CAA0BC,MAA1B,EAAkC;AAChC,SAAOA,SAASA,OAAOC,WAAPD,EAATA,GAAgC,MAAvC;AACF;;AAEA,SAASE,QAAT,CAAkBC,IAAlB,EAAwB;AACtB,MAAIA,KAAKC,UAALD,CAAgB,IAAhBA,KAAyBA,KAAKC,UAALD,CAAgB,KAAhBA,CAA7B,EAAqD;AACnD,WAAO,CAAP;AACF;AACA,MAAIA,KAAKC,UAALD,CAAgB,MAAhBA,CAAJ,EAA6B;AAC3B,WAAO,CAAP;AACF;;AAEA,SAAO,CAAP;AACF;;AAEA,SAASE,UAAT,CAAoBC,IAApB,EAA0B;AACxB,SACE,4DAA2DC,IAA3D,CAAgED,IAAhE,KACA,YAAYC,IAAZ,CAAiBD,IAAjB,CADA,IAEA,QAAQC,IAAR,CAAaD,IAAb,CAFA,IAGA,OAAOC,IAAP,CAAYD,IAAZ;AAJF;AAMF;;AAEA,SAASE,SAAT,CAAmBF,IAAnB,EAAyB;AACvB,SACE,6DAA4DC,IAA5D,CAAiED,IAAjE,KACA,oDAAoDC,IAApD,CAAyDD,IAAzD,CADA,IAEA,mEAAmEC,IAAnE,CAAwED,IAAxE,CAFA,IAGA,6DAA6DC,IAA7D,CAAkED,IAAlE,CAHA,IAIA,oDAAoDC,IAApD,CAAyDD,IAAzD,CAJA,IAKA,sBAAsBC,IAAtB,CAA2BD,IAA3B,CALA,IAMA,UAAUC,IAAV,CAAeD,IAAf,CANA,IAOA,QAAQC,IAAR,CAAaD,IAAb,CAPA,IAQA,OAAOC,IAAP,CAAYD,IAAZ;AATF;AAWF;;AAEA,SAASG,QAAT,CAAkBH,IAAlB,E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GAAiBA,QAAQnB,MAARmB,CAAelB,WAAfkB,EAAjBA;AACA,UAAIA,QAAQnB,MAARmB,KAAmBnB,MAAnBmB,IAA6Bd,WAAWc,QAAQP,OAAnBP,CAAjC,EAA8D;AAC5D,eAAO,KAAP;AACF,OAFA,MAEO,IAAI,CAACF,IAAL,EAAW;AAChB,eAAO,IAAP;AACF;;AAEA,aAAOA,SAAS,QAATA,GAAoBK,UAAUW,QAAQP,OAAlBJ,CAApBL,GAAiDM,SAASU,QAAQP,OAAjBH,CAAxD;AACD,KATeI,CAAhB;;AAWA,WAAOkB,UAAUV,MAAVU,GAAmBA,UAAU,CAAVA,EAAanB,OAAhCmB,GAA0CT,SAAjD;AACD,GAlBOC,EAmBPL,MAnBOK,CAmBAS,OAnBAT,CAAV;;AAqBA,SAAO,CAACP,IAAIK,MAAL,GAAcX,SAASV,MAATU,CAAd,GAAiCM,IAAI,CAAJA,CAAxC;AACF;;kBAEe;AACbJ;AADa,C","file":"../ip.js","sourcesContent":["/* @flow */\n\nimport os from 'os';\n\nfunction _normalizeFamily(family) {\n return family ? family.toLowerCase() : 'ipv4';\n}\n\nfunction priority(name) {\n if (name.startsWith('en') || name.startsWith('eth')) {\n return 0;\n }\n if (name.startsWith('wlan')) {\n return 1;\n }\n\n return 2;\n}\n\nfunction isLoopback(addr) {\n return (\n /^(::f{4}:)?127\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})/.test(addr) ||\n /^fe80::1$/.test(addr) ||\n /^::1$/.test(addr) ||\n /^::$/.test(addr)\n );\n}\n\nfunction isPrivate(addr) {\n return (\n /^(::f{4}:)?10\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$/i.test(addr) ||\n /^(::f{4}:)?192\\.168\\.([0-9]{1,3})\\.([0-9]{1,3})$/i.test(addr) ||\n /^(::f{4}:)?172\\.(1[6-9]|2\\d|30|31)\\.([0-9]{1,3})\\.([0-9]{1,3})$/i.test(addr) ||\n /^(::f{4}:)?127\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})$/i.test(addr) ||\n /^(::f{4}:)?169\\.254\\.([0-9]{1,3})\\.([0-9]{1,3})$/i.test(addr) ||\n /^f[cd][0-9a-f]{2}:/i.test(addr) ||\n /^fe80:/i.test(addr) ||\n /^::1$/.test(addr) ||\n /^::$/.test(addr)\n );\n}\n\nfunction isPublic(addr) {\n return !isPrivate(addr);\n}\n\nfunction loopback(family) {\n //\n // Default to `ipv4`\n //\n family = _normalizeFamily(family);\n\n if (family !== 'ipv4' && family !== 'ipv6') {\n throw new Error('family must be ipv4 or ipv6');\n }\n\n return family === 'ipv4' ? '127.0.0.1' : 'fe80::1';\n}\n\nfunction address(name, family) {\n var interfaces = os.networkInterfaces();\n var all;\n\n // Default to `ipv4`\n //\n family = _normalizeFamily(family);\n\n // If a specific network interface has been named,\n // return the address.\n //\n if (name && name !== 'private' && name !== 'public') {\n var res = interfaces[name].filter(function(details) {\n var itemFamily = details.family.toLowerCase();\n return itemFamily === family;\n });\n if (res.length === 0) {\n return undefined;\n }\n\n return res[0].address;\n }\n\n var sortedInterfaces = Object.keys(interfaces).sort(function(a, b) {\n return priority(a) - priority(b);\n });\n\n var all = sortedInterfaces\n .map(function(nic) {\n //\n // Note: name will only be `public` or `private`\n // when this is called.\n //\n var addresses = interfaces[nic].filter(function(details) {\n details.family = details.family.toLowerCase();\n if (details.family !== family || isLoopback(details.address)) {\n return false;\n } else if (!name) {\n return true;\n }\n\n return name === 'public' ? isPrivate(details.address) : isPublic(details.address);\n });\n\n return addresses.length ? addresses[0].address : undefined;\n })\n .filter(Boolean);\n\n return !all.length ? loopback(family) : all[0];\n}\n\nexport default {\n address,\n};\n"],"sourceRoot":"/xdl/src"}