From 0d16860a458b00a2d821bf4463722692e000b574 Mon Sep 17 00:00:00 2001 From: Val Vinder Date: Tue, 2 Aug 2016 12:04:28 -0700 Subject: [PATCH] updates to defaults entities, making sure that node-ipc could be run even if no network interfaces are present --- .npmignore | 3 +++ entities/Defaults.js | 45 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..309b545 --- /dev/null +++ b/.npmignore @@ -0,0 +1,3 @@ +.tags +tags +spec diff --git a/entities/Defaults.js b/entities/Defaults.js index fb016cb..c88cdbd 100644 --- a/entities/Defaults.js +++ b/entities/Defaults.js @@ -1,12 +1,25 @@ 'use strict'; +/*eslint no-magic-numbers: ["error", { "ignore": [ 0] }]*/ + +/** + * @module entities + */ + const os = require('os'); +/** + * @class Defaults + * @description Defaults Entity + */ class Defaults{ + + /** + * @constructor + * @method constructor + * @return {void} + */ constructor(){ - const IPType=os.networkInterfaces()[ - Object.keys(os.networkInterfaces())[0] - ][0].family; Object.defineProperties( this, @@ -24,7 +37,7 @@ class Defaults{ networkHost : { enumerable:true, writable:true, - value:(IPType=='IPv6')? '::1' : '127.0.0.1' + value: '' }, networkPort : { enumerable:true, @@ -89,7 +102,7 @@ class Defaults{ IPType : { enumerable:true, writable:true, - value:IPType + value: getIPType() }, tls : { enumerable:true, @@ -98,7 +111,29 @@ class Defaults{ } } ); + + this.networkHost = (this.IPType == 'IPv6') ? '::1' : '127.0.0.1'; } } +/** + * method to get ip type + * + * @method getIPType + * @return {string} ip type + */ +function getIPType() { + const networkInterfaces = os.networkInterfaces(); + let IPType = ''; + if (networkInterfaces + && Array.isArray(networkInterfaces) + && networkInterfaces.length > 0) { + // getting the family of first network interface available + IPType = networkInterfaces [ + Object.keys( networkInterfaces )[0] + ][0].family; + } + return IPType; +} + module.exports=Defaults;