From 763e8e761ae60193b9a067087e848d51c9613497 Mon Sep 17 00:00:00 2001 From: iSkore Date: Tue, 11 Jul 2017 18:35:42 -0400 Subject: [PATCH] updated to ES6 typed --- .gitignore | 497 +++++++++++++++++++++++++++++++++++++++++++++++++++ .jshintrc | 32 ++++ index.js | 85 ++++----- package.json | 3 + test.js | 13 +- 5 files changed, 585 insertions(+), 45 deletions(-) create mode 100644 .gitignore create mode 100644 .jshintrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e78d372 --- /dev/null +++ b/.gitignore @@ -0,0 +1,497 @@ +# code coverage +coverage +lib-cov +test-results.xml +clover.xml + +# editor and that .tmp file +.idea +.tmp +.tags +.tags1 +*.ss* +<<<<<<< HEAD +*idea* +*.idea* +======= +>>>>>>> f68bbb5... First Commit - Build Successful + +# Node logs +npm-debug.log* +logs +*.log +pids +*.pid +*.seed + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +# Yeoman/bow/&c. +bower_components/ +build/ +dist/ + +# Linux ignores +*~ +.fuse_hidden +.directory +.Trash-* + +## JetBrains file-based project format: +*.iws + +# perl, you crazy old thing, you... +/blib/ +/.build/ +_build/ +cover_db/ +inc/ +Build +!Build/ +Build.bat +.last_cover_stats +/Makefile +/Makefile.old +/MANIFEST.bak +/META.yml +/META.json +/MYMETA.* +nytprof.out +/pm_to_blib +*.o +*.bs +/_eumm/ + +# SASS +.sass-cache/ +*.css.map + +# Unity 3D +/[Ll]ibrary/ +/[Tt]emp/ +/[Oo]bj/ +/[Bb]uild/ +/[Bb]uilds/ +/Assets/AssetStoreTools* + +# Autogenerated VS/MD solution and project files +ExportedObj/ +*.csproj +*.unityproj +*.sln +*.suo +*.tmp +*.user +*.userprefs +*.pidb +*.booproj +*.svd + + +# Unity3D generated meta files +*.pidb.meta + +# Unity3D Generated File On Crash Reports +sysinfo.txt + +# Builds +*.apk +*.unitypackage + +### OSX ### +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# MonoDevelop +# User Specific +*.userprefs +*.usertasks + +# Mono Project Files +*.pidb +*.resources +test-results/ + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xccheckout +*.xcscmblueprint + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Object files +*.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Debug files +*.dSYM/ +*.su + +# Misc. detritus +.svn/ +/.tgitconfig +.vscode + +# All Visual Studio from here on down. Typical. +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +*.sln.iml + + diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..26d409e --- /dev/null +++ b/.jshintrc @@ -0,0 +1,32 @@ +{ + "mocha": true, + "freeze": true, + "browserify": true, + "strict": true, + "worker": true, + "scripturl": true, + "latedef": "nofunc", + "onevar": true, + "node": true, + "maxstatements": 25, + "futurehostile": true, + "noarg": true, + "unused": true, + "esnext": true, + "eqeqeq": true, + "nocomma": false, + "devel": true, + "maxdepth": 5, + "jquery": true, + "browser": true, + "debug": true, + "maxparams": 5, + "undef": true, + "globalstrict": true, + "maxcomplexity": 20, + "typed": true, + "nonew": true, + "forin": false, + "shadow": true, + "-W018": false +} diff --git a/index.js b/index.js index 4f7d2b8..f96b3bc 100644 --- a/index.js +++ b/index.js @@ -1,40 +1,45 @@ -var os = require('os'); -function getMyIP(version,internal){ - version = version || 'IPv4'; - internal = internal || false; - var interfaces = os.networkInterfaces(); - for(var key in interfaces){ - var addresses = interfaces[key]; - for(var i = 0; i < addresses.length; i++){ - var address = addresses[i]; - if(address.internal === internal && address.family === version){ - return address.address; - }; - }; - }; - return 'localhost' -}; - -if(!module.parent){ - version = 'IPv4'; - internal = false; - var argv = process.argv; - var length = argv.length; - if(length >= 3){ - for(var i = 2; i < length; i++){ - switch(argv[i]){ - case '--version6': - case '-v6': - version = 'IPv6' - break; - case '--internal': - case '-i': - internal = true; - break; - }; - }; - }; - console.log(getMyIP(version,internal)); -}else{ - module.exports = getMyIP; -}; +'use strict'; + +const + os = require( 'os' ), + interfaces = os.networkInterfaces(); + +let version, internal; + +function getMyIP( version, internal ) { + version = version || 'IPv4'; + internal = internal || false; + + for( const key in interfaces ) { + const addresses = interfaces[ key ]; + for( let i = 0; i < addresses.length; i++ ) { + const address = addresses[ i ]; + + if( address.internal === internal && address.family === version ) { + return address.address; + } + } + } + return 'localhost'; +} + +if( !module.parent ) { + version = 'IPv4'; + internal = false; + let + argv = process.argv, + length = argv.length; + + if( length >= 3 ) { + for( let i = 2; i < length; i++ ) { + if( argv[ i ] === '--version6' || argv[ i ] === '-v6' ) + version = 'IPv6'; + else if( argv[ i ] === '--internal' || argv[ i ] === '-i' ) + internal = true; + } + } + + return getMyIP( version, internal ); +} else { + module.exports = getMyIP; +} \ No newline at end of file diff --git a/package.json b/package.json index dc155f2..ec9729f 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,9 @@ "localhost" ], "author": "AtuyL", + "contributors": [ + "Parellin Technologies LLC" + ], "license": "BSD-2-Clause", "bugs": { "url": "https://github.com/AtuyL/my-ip/issues" diff --git a/test.js b/test.js index 5107d37..2524f0d 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,8 @@ -myIP = require('./'); -console.dir(myIP());// return external IPv4 -console.dir(myIP('IPv6'));// return external IPv6 -console.dir(myIP(null,true));// return internal IPv4 -console.dir(myIP('IPv6',true));// return internal IPv6 \ No newline at end of file +'use strict'; + +const myIP = require( './' ); + +console.dir( myIP() ); // return external IPv4 +console.dir( myIP( 'IPv6' ) ); // return external IPv6 +console.dir( myIP( null, true ) ); // return internal IPv4 +console.dir( myIP( 'IPv6', true ) ); // return internal IPv6 \ No newline at end of file