UNPKG

webpack-tool-x

Version:

webpack build and webpack build result web view

38 lines (32 loc) 858 B
'use strict'; const os = require('os'); const utils = {}; utils.getIp = position => { const interfaces = os.networkInterfaces(); const ips = []; if (interfaces.en0) { for (let i = 0; i < interfaces.en0.length; i++) { if (interfaces.en0[i].family === 'IPv4') { ips.push(interfaces.en0[i].address); } } } if (interfaces.en1) { for (let i = 0; i < interfaces.en1.length; i++) { if (interfaces.en1[i].family === 'IPv4') { ips.push(interfaces.en1[i].address); } } } if (position > 0 && position <= ips.length) { return ips[position - 1]; } else if (ips.length) { return ips[0]; } return '127.0.0.1'; }; // judge a obj's type utils.type = obj => { return Object.prototype.toString.call(obj).replace('[object ', '').replace(']', '').toLowerCase(); } module.exports = utils;