Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce backwards compatibility in favor of more logical edits #1

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions lib/suggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ function suggest(value) {
var normalized
var suggestion
var currentCase
var valueLowerCase

value = normalize(value.trim(), conversion.in)
valueLowerCase = value.toLowerCase()

if (!value || self.correct(value)) {
return []
Expand Down Expand Up @@ -81,23 +79,21 @@ function suggest(value) {

while (++index < length) {
group = groups[index]
// Only make edits to the start of value, bound by group size
count = Math.min(value.length, group.length)
count = value.length
offset = -1

while (++offset < count) {
// Consider edits where value contains character at offset in group
position = valueLowerCase.indexOf(group.charAt(offset))

if (position === -1) {
continue
}

character = value.charAt(offset)
insensitive = character.toLowerCase()
upper = insensitive !== character
charAdded = offsetAdded[offset] || {}

position = group.indexOf(insensitive)

if (position === -1) {
continue
}

before = value.slice(0, offset)
after = value.slice(offset + 1)
otherOffset = -1
Expand Down