Skip to content

Commit

Permalink
Reduce usage of lodash to fix high severity vulnerability.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwippermann committed Nov 25, 2018
1 parent 9b638b5 commit 60f9d6d
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 65 deletions.
9 changes: 4 additions & 5 deletions examples/customizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const fs = require('fs');

const express = require('express');
const kue = require('kue');
const _ = require('lodash');
const optimist = require('optimist');


Expand All @@ -25,7 +24,7 @@ const i18n = new vbus.I18N('en');

let reportProgress = (message) => {
let line;
if (_.isString(message)) {
if (typeof message === 'string') {
line = message;
} else if (message.message === 'OPTIMIZING_VALUES') {
line = i18n.sprintf('Optimizing set of values for round %d', message.round);
Expand All @@ -43,7 +42,7 @@ let reportProgress = (message) => {
line = i18n.sprintf('%s: %s', message.message, JSON.stringify(message));
}

if (_.isNumber(message.round)) {
if (typeof message.round === 'number') {
line = i18n.sprintf('[%d] %s', message.round, line);
}

Expand Down Expand Up @@ -164,7 +163,7 @@ const serve = async () => {

const app = express();
app.get('/config', (req, res) => {
const jsonConfig = _.reduce(context.currentConfig, (memo, value) => {
const jsonConfig = context.currentConfig.reduce((memo, value) => {
if (!value.ignored) {
memo [value.valueId] = value.value;
}
Expand Down Expand Up @@ -271,7 +270,7 @@ const runSingleShot = async (argv) => {
savedConfig = loadedConfig;
}

let jsonConfig = _.reduce(savedConfig, (memo, value) => {
let jsonConfig = savedConfig.reduce((memo, value) => {
if (!value.ignored) {
memo [value.valueId] = value.value;
}
Expand Down
22 changes: 11 additions & 11 deletions examples/json-live-data-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const os = require('os');


const express = require('express');
const _ = require('lodash');
const winston = require('winston');


Expand All @@ -25,11 +24,14 @@ const config = require('./config');



const logger = new winston.Logger({
const logger = winston.createLogger({
transports: [
new winston.transports.Console({
level: 'info',
colorize: true,
level: 'debug',
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
),
}),
],
});
Expand All @@ -50,7 +52,7 @@ const headerSet = new HeaderSet();
const generateJsonData = async function() {
const packetFields = spec.getPacketFieldsForHeaders(headerSet.getSortedHeaders());

const data = _.map(packetFields, (pf) => {
const data = packetFields.map((pf) => {
return {
id: pf.id,
name: pf.name,
Expand Down Expand Up @@ -126,16 +128,14 @@ const main = async () => {

await connection.connect();

const ifaces = os.networkInterfaces();

logger.info('Ready to serve from the following URLs:');
_.forEach(ifaces, (ifaceConfigs, ifaceName) => {
_.forEach(ifaceConfigs, (ifaceConfig) => {
for (const iface of Object.values(os.networkInterfaces())) {
for (const ifaceConfig of iface) {
if (ifaceConfig.family === 'IPv4') {
logger.info(' - http://' + ifaceConfig.address + ':' + config.httpPort + '/api/v1/live-data' + (ifaceConfig.internal ? ' (internal)' : ''));
}
});
});
}
}

hsc.startTimer();

Expand Down

0 comments on commit 60f9d6d

Please sign in to comment.