Skip to content

Commit 97a124b

Browse files
committed
Formatting changes to \!mdn to remove redundancy, unescape html entities
1 parent 3193fc9 commit 97a124b

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

jshelp.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ const npminfo = Promise.promisify(npm.info, npm);
44
const format = require('util').format;
55
const inspect = require('util').inspect;
66
const request = require('request');
7+
const unescape = require('lodash.unescape');
78

89
module.exports = {
910
init: function (client, imports) {
10-
const ready = Promise.promisify(npm.load, npm)({});
11+
const npm_ready = Promise.promisify(npm.load, npm)({});
1112

12-
ready.catch(function (err) {
13+
npm_ready.catch(function (err) {
1314
client.error('Plugin-JSHelp', err.name);
1415
client.error('Plugin-JSHelp', err.stack);
1516
});
@@ -21,7 +22,7 @@ module.exports = {
2122
return;
2223
}
2324

24-
return ready
25+
return npm_ready
2526
.then(function () {
2627
return new Promise(function (resolve, reject) {
2728
npm.commands.info([command.args[0], 'name', 'description'], true, function (err, res) {
@@ -66,7 +67,15 @@ module.exports = {
6667
});
6768
})
6869
.then(function (res) {
69-
return format('%s - %s', res.url, res.titleNoFormatting);
70+
// Turn > into >, ect.
71+
// Strip the " | MDN" from end of title.
72+
return {
73+
url: res.url,
74+
title: unescape(res.titleNoFormatting.slice(0, -6))
75+
};
76+
})
77+
.then(function (res) {
78+
return format("%s - %s", res.url, res.title)
7079
})
7180
.catch(function (err) {
7281
client.error('Plugin-JSHelp', err.name);

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "JS Help Plugin for Tennu IRC Bot Framework",
55
"main": "jshelp.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "mocha tests.js"
88
},
99
"repository": {
1010
"type": "git",
@@ -22,7 +22,12 @@
2222
"homepage": "https://github.com/Tennu/tennu-jshelp",
2323
"dependencies": {
2424
"bluebird": "^0.11.x",
25+
"lodash.unescape": "^2.4.1",
2526
"npm": "^1.3.x",
2627
"request": "^2.33.0"
28+
},
29+
"devDependencies": {
30+
"better-assert": "^1.0.2",
31+
"mocha": "^2.1.0"
2732
}
2833
}

tests.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//const sinon = require('sinon');
2+
const assert = require('better-assert');
3+
// const equal = require('deep-eql');
4+
const inspect = require('util').inspect;
5+
const format = require('util').format;
6+
7+
const debug = false;
8+
const logfn = debug ? console.log.bind(console) : function () {};
9+
10+
const jshelp_plugin = require('./jshelp');
11+
const client = {
12+
notice: logfn,
13+
error: function err (pluginName, errorState) {
14+
if (err.showedName !== true) {
15+
logfn("Error: " + errorState);
16+
err.showedName = true;
17+
return;
18+
}
19+
20+
logfn("Error: " + errorState);
21+
assert(false);
22+
}
23+
};
24+
25+
describe("MDN -", function () {
26+
it("Escapes common HTML entities", function () {
27+
const jshelp = jshelp_plugin.init(client, {});
28+
return jshelp.handlers["!mdn"]({args: ['HTML script']})
29+
.then(function (output) {
30+
logfn(format("'%s'", output));
31+
assert(output === "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script - <script> - HTML (HyperText Markup Language)")
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)