From 43918ac42ffdef296f68576e28f82fad21308c9e Mon Sep 17 00:00:00 2001 From: Dima Stefantsov Date: Mon, 22 Nov 2021 11:11:08 +0300 Subject: [PATCH] unicode support --- fuzzysort.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fuzzysort.js b/fuzzysort.js index dbb2b74..e687af1 100644 --- a/fuzzysort.js +++ b/fuzzysort.js @@ -517,10 +517,11 @@ USAGE: var beginningIndexes = []; var beginningIndexesLen = 0 var wasUpper = false var wasAlphanum = false + var regexpUnicodeLetter = new RegExp(/^\p{L}/, 'u') for(var i = 0; i < targetLen; ++i) { - var targetCode = target.charCodeAt(i) - var isUpper = targetCode>=65&&targetCode<=90 - var isAlphanum = isUpper || targetCode>=97&&targetCode<=122 || targetCode>=48&&targetCode<=57 + var targetChar = target.charAt(i) + var isUpper = (targetChar === targetChar.toUpperCase()) && (targetChar !== targetChar.toLowerCase()) + var isAlphanum = regexpUnicodeLetter.test(targetChar) var isBeginning = isUpper && !wasUpper || !wasAlphanum || !isAlphanum wasUpper = isUpper wasAlphanum = isAlphanum