forked from timmson/java-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeller.js
More file actions
33 lines (26 loc) · 701 Bytes
/
speller.js
File metadata and controls
33 lines (26 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Speller {
constructor(settings, yaSpeller) {
this.yaSpeller = yaSpeller || require("yaspeller");
this.settings = settings || {dictionary: []};
}
check(text, fileName) {
const _this = this;
return new Promise((resolve) => {
let callback = function (err, data) {
if (err) {
resolve([err]);
} else {
resolve(data.filter(d => !_this.isInDictionary(d.word)).map(d => {
d.fileName = fileName;
return d;
}));
}
};
_this.yaSpeller.checkText(text, callback, this.settings);
});
}
isInDictionary(text) {
return this.settings.dictionary.filter(d => text.toLowerCase().match(d.toLowerCase())).length > 0;
}
}
module.exports = Speller;