Skip to content

Commit 406d9c3

Browse files
committed
Refactor
1 parent 11c2737 commit 406d9c3

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

index.js

+19-12
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,23 @@ function spell(options) {
2525
var digits = settings.ignoreDigits
2626
var apos = settings.normalizeApostrophes
2727
var personal = settings.personal
28-
var config = {}
28+
var config
2929
var loadError
3030

3131
if (typeof load !== 'function') {
3232
throw new Error('Expected `Object`, got `' + load + '`')
3333
}
3434

35-
config.ignoreLiteral =
36-
literal === null || literal === undefined ? true : literal
37-
config.ignoreDigits = digits === null || digits === undefined ? true : digits
38-
config.normalizeApostrophes =
39-
apos === null || apos === undefined ? true : apos
40-
config.ignore = settings.ignore
41-
config.max = settings.max || max
42-
config.count = 0
43-
config.cache = {}
35+
config = {
36+
ignoreLiteral: literal === null || literal === undefined ? true : literal,
37+
ignoreDigits: digits === null || digits === undefined ? true : digits,
38+
normalizeApostrophes: apos === null || apos === undefined ? true : apos,
39+
ignore: settings.ignore,
40+
max: settings.max || max,
41+
count: 0,
42+
cache: {},
43+
checker: null
44+
}
4445

4546
load(construct)
4647

@@ -60,8 +61,8 @@ function spell(options) {
6061
}
6162

6263
// Callback invoked when a `dictionary` is loaded (possibly erroneous) or
63-
// when `load`ing failed. Flushes the queue when available, and sets the
64-
// results on the parent scope.
64+
// when `load`ing failed.
65+
// Flushes the queue when available, and sets the results on the parent scope.
6566
function construct(err, dictionary) {
6667
var length = queue.length
6768
var index = -1
@@ -123,8 +124,12 @@ function all(tree, file, config) {
123124
return
124125
}
125126

127+
// Check the whole word.
126128
correct = checker.correct(word)
127129

130+
// If the whole word is not correct, check all its parts.
131+
// This makes sure that, if `alpha` and `bravo` are correct, `alpha-bravo`
132+
// is also seenn as correct.
128133
if (!correct && children.length > 1) {
129134
correct = true
130135
length = children.length
@@ -144,6 +149,8 @@ function all(tree, file, config) {
144149
}
145150

146151
if (!correct) {
152+
// Suggestions are very slow, so cache them (spelling mistakes other than
153+
// typos often occur multiple times).
147154
if (own.call(cache, word)) {
148155
reason = cache[word]
149156
} else {

0 commit comments

Comments
 (0)