Created
November 18, 2019 18:39
-
-
Save paperscissors/c586abe97a4fb1c0eced34a243b7ae78 to your computer and use it in GitHub Desktop.
Intl.Collator loose comparison of diacritics with str.startsWith()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// probably not necessary to normalize, but let's cover our bets | |
var value = val.normalize() | |
var conjugation = this.conjugation.normalize() | |
// collator to do a loose comparison of characters. some characters like ț in Romanian | |
// have three or more versions, so this seems to resolve the issue | |
var collator = new Intl.Collator('ro', { sensitivity: 'base' }) | |
// do the comparison, for feedback while they type | |
if (collator.compare(value.substring(0, value.length), conjugation.substring(0, value.length)) === 0) { | |
this.status = 'correct' | |
} else { | |
this.status = 'incorrect' | |
} | |
// we have a loose collator match, so we can mark this input as correct and finished | |
if (collator.compare(value, conjugation) === 0) { | |
this.status = 'correct' | |
// update store for this verb tense | |
this.$store.commit('groups/addCorrectAnswer', this.tense_key) | |
if (this.tense_key < 6) { | |
this.focusNextInput() | |
} | |
this.finished = true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment