Skip to content

Commit 2f801d6

Browse files
refactor($libraries): Removed lodash and console calls
Replaced all lodash calls with methods that don't depend on the lodash library. Also removed console.log expressions that were used for testing.
1 parent 2825cae commit 2f801d6

2 files changed

Lines changed: 4 additions & 14 deletions

File tree

app.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
var express = require('express'); // app server
2020
var bodyParser = require('body-parser'); // parser for post requests
2121
var AssistantV1 = require('watson-developer-cloud/assistant/v1'); // watson sdk
22-
var _ = require('lodash'); // lodash
2322

2423
var app = express();
2524

@@ -55,34 +54,26 @@ app.post('/api/message', function (req, res) {
5554
return res.status(err.code || 500).json(err);
5655
}
5756

58-
console.log('\n\nData.output:');
59-
60-
console.log(data.output);
61-
6257
// This is a fix for now, as since Assistant version 2018-07-10,
6358
// output text can now be in output.generic.text
6459
var output = data.output;
65-
if (output.text.length === 0 && _.has(output, 'generic')) {
60+
if (output.text.length === 0 && output.hasOwnProperty('generic')) {
6661
var generic = output.generic;
6762

68-
if (_.isArray(generic)) {
63+
if (Array.isArray(generic)) {
6964
// Loop through generic and add all text to data.output.text.
7065
// If there are multiple responses, this will add all of them
7166
// to the response.
7267
for(var i = 0; i < generic.length; i++) {
73-
if (_.has(generic[i], 'text')) {
68+
if (generic[i].hasOwnProperty('text')) {
7469
data.output.text.push(generic[i].text);
75-
} else if (_.has(generic[i], 'title')) {
70+
} else if (generic[i].hasOwnProperty('title')) {
7671
data.output.text.push(generic[i].title);
7772
}
7873
}
7974
}
8075
}
8176

82-
console.log("------------");
83-
console.log("Output text:");
84-
console.log(data.output.text);
85-
8677
return res.json(updateMessage(payload, data));
8778
});
8879
});

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"body-parser": "^1.18.3",
2323
"dotenv": "^6.0.0",
2424
"express": "^4.16.3",
25-
"lodash": "^4.17.10",
2625
"watson-developer-cloud": "^3.7.0"
2726
},
2827
"publishConfig": {

0 commit comments

Comments
 (0)