Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 219f436

Browse files
committed
characters without diacritics should be recomposed
1 parent 66f9dfa commit 219f436

File tree

2 files changed

+50
-32
lines changed

2 files changed

+50
-32
lines changed

lib/index.mjs

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const latin_condensed = {
4646
"f": "ꝼƒ",
4747
"g": "ǥɠꞡᵹꝿɢ",
4848
"h": "ħⱨⱶɥ",
49-
"i": "i̇ɨı",
49+
"i": "ɨı",
5050
"j": "ɉȷ",
5151
"k": "ƙⱪꝁꝃꝅꞣ",
5252
"l": "łƚɫⱡꝉꝇꞁɭ",
@@ -60,7 +60,7 @@ const latin_condensed = {
6060
"p": "ƥᵽꝑꝓꝕρ",
6161
"q": "ꝗꝙɋ",
6262
"r": "ɍɽꝛꞧꞃ",
63-
"s": "ßȿꞩꞅʂṧṩ",
63+
"s": "ßȿꞩꞅʂ",
6464
"t": "ŧƭʈⱦꞇ",
6565
"th": "þ",
6666
"tz": "ꜩ",
@@ -107,44 +107,37 @@ export const initialize = (_code_points) => {
107107
export const normalize = (str,form='NFKD') => str.normalize(form);
108108

109109

110-
/**
111-
* Compatibility Decomposition without reordering string
112-
* calling str.normalize('NFKD') on \u{594}\u{595}\u{596} becomes \u{596}\u{594}\u{595}
113-
* @param {string} str
114-
*/
115-
export const decompose = (str) =>{
116-
117-
if( str.match(/[\u0f71-\u0f81]/) ){
118-
return toArray(str).reduce(
119-
/**
120-
* @param {string} result
121-
* @param {string} char
122-
*/
123-
(result, char) =>{
124-
return result + normalize(char)
125-
},
126-
''
127-
);
128-
}
129-
130-
return normalize(str);
131-
}
132-
133-
134-
135110

136111
/**
137-
* Remove accents
112+
* Remove accents without reordering string
113+
* calling str.normalize('NFKD') on \u{594}\u{595}\u{596} becomes \u{596}\u{594}\u{595}
138114
* via https://github.com/krisk/Fuse/issues/133#issuecomment-318692703
139115
* @param {string} str
140116
* @return {string}
141117
*/
142118
export const asciifold = (str) => {
143-
return decompose(str)
119+
120+
return toArray(str).reduce(
121+
/**
122+
* @param {string} result
123+
* @param {string} char
124+
*/
125+
(result, char) =>{
126+
return result + _asciifold(char)
127+
},
128+
''
129+
);
130+
};
131+
132+
export const _asciifold = (str) => {
133+
str = normalize(str)
144134
.toLowerCase()
145135
.replace(convert_pat,(/** @type {string} */ char) => {
146136
return latin_convert[char] || '';
147-
});
137+
})
138+
139+
//return str;
140+
return normalize(str,'NFC')
148141
};
149142

150143

test/matching.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,45 @@ describe('Matching', function(){
100100
testCombos(combos);
101101
});
102102

103+
// https://github.com/orchidjs/tom-select/discussions/491
104+
it('full-width characters',()=>{
105+
let combos = ['アプ'];
106+
testCombos(combos);
107+
});
108+
103109
it('diacritic list',()=>{
104110

111+
let missing = {};
112+
105113
for( let folded in diacritics ){
106114
let chars = Array.from(diacritics[folded]);
107115

108116
for( let char of chars){
109117
folded = folded.toLowerCase();
110118
char = char.toLowerCase();
111119

112-
let combos = [folded,char];
113-
testCombos(combos);
120+
let regex = regExp(folded);
121+
let r = regex.test(char);
122+
if( r ){
123+
continue;
124+
}
125+
126+
let temp = missing[folded] || '';
127+
128+
if( temp.indexOf(char) >= 0 ){
129+
continue;
130+
}
131+
132+
missing[folded] = temp + char;
133+
114134
}
115135
}
116136

137+
if( Object.keys(missing).length > 0 ){
138+
console.log('missing characters',JSON.stringify(missing,null,"\t"));
139+
assert.equal(false, true, 'should not be missing characters. see console output');
140+
}
141+
117142
});
118143

119144
it('Should match all code points individually',()=>{

0 commit comments

Comments
 (0)