@orchidjs/sifter
Advanced tools
Comparing version 0.9.2 to 0.9.3
@@ -30,3 +30,3 @@ /*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */ | ||
return str.normalize('NFKD').replace(accent_reg, '').toLowerCase().replace(convert_pat, function (foreignletter) { | ||
return latin_convert[foreignletter]; | ||
return latin_convert[foreignletter] || foreignletter; | ||
}); | ||
@@ -42,3 +42,3 @@ }; | ||
const arrayToPattern = (chars, glue = '|') => { | ||
if (chars.length == 1) { | ||
if (chars.length === 1 && chars[0] != undefined) { | ||
return chars[0]; | ||
@@ -106,8 +106,5 @@ } | ||
if (!(latin in diacritics)) { | ||
diacritics[latin] = [latin]; | ||
} | ||
const latin_diacritics = diacritics[latin] || [latin]; | ||
const patt = new RegExp(escapeToPattern(latin_diacritics), 'iu'); | ||
var patt = new RegExp(escapeToPattern(diacritics[latin]), 'iu'); | ||
if (diacritic.match(patt)) { | ||
@@ -117,19 +114,18 @@ continue; | ||
diacritics[latin].push(diacritic); | ||
latin_diacritics.push(diacritic); | ||
diacritics[latin] = latin_diacritics; | ||
} | ||
}); // filter out if there's only one character in the list | ||
// todo: this may not be needed | ||
let latin_chars = Object.keys(diacritics); | ||
Object.keys(diacritics).forEach(latin => { | ||
const latin_diacritics = diacritics[latin] || []; | ||
for (let i = 0; i < latin_chars.length; i++) { | ||
const latin = latin_chars[i]; | ||
if (diacritics[latin].length < 2) { | ||
if (latin_diacritics.length < 2) { | ||
delete diacritics[latin]; | ||
} | ||
} // latin character pattern | ||
}); // latin character pattern | ||
// match longer substrings first | ||
latin_chars = Object.keys(diacritics).sort((a, b) => b.length - a.length); | ||
let latin_chars = Object.keys(diacritics).sort((a, b) => b.length - a.length); | ||
latin_pat = new RegExp('(' + escapeToPattern(latin_chars) + accent_pat + '*)', 'gu'); // build diacritic patterns | ||
@@ -136,0 +132,0 @@ // ae needs: |
@@ -254,6 +254,2 @@ /*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */ | ||
} | ||
} | ||
for (i = 0, n = sort_flds.length; i < n; i++) { | ||
multipliers.push(sort_flds[i].direction === 'desc' ? -1 : 1); | ||
} // build function | ||
@@ -266,21 +262,21 @@ | ||
return null; | ||
} else if (sort_flds_count === 1) { | ||
const sort_fld = sort_flds[0].field; | ||
const multiplier = multipliers[0]; | ||
return function (a, b) { | ||
return multiplier * utils.cmp(get_field(sort_fld, a), get_field(sort_fld, b)); | ||
}; | ||
} else { | ||
return function (a, b) { | ||
var i, result, field; | ||
} | ||
for (i = 0; i < sort_flds_count; i++) { | ||
field = sort_flds[i].field; | ||
result = multipliers[i] * utils.cmp(get_field(field, a), get_field(field, b)); | ||
if (result) return result; | ||
return function (a, b) { | ||
var i, result, field; | ||
for (i = 0; i < sort_flds_count; i++) { | ||
field = sort_flds[i].field; | ||
let multiplier = multipliers[i]; | ||
if (multiplier == undefined) { | ||
multiplier = sort_flds[i].direction === 'desc' ? -1 : 1; | ||
} | ||
return 0; | ||
}; | ||
} | ||
result = multiplier * utils.cmp(get_field(field, a), get_field(field, b)); | ||
if (result) return result; | ||
} | ||
return 0; | ||
}; | ||
} | ||
@@ -287,0 +283,0 @@ |
@@ -26,3 +26,3 @@ /*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */ | ||
return str.normalize('NFKD').replace(accent_reg, '').toLowerCase().replace(convert_pat, function (foreignletter) { | ||
return latin_convert[foreignletter]; | ||
return latin_convert[foreignletter] || foreignletter; | ||
}); | ||
@@ -38,3 +38,3 @@ }; | ||
const arrayToPattern = (chars, glue = '|') => { | ||
if (chars.length == 1) { | ||
if (chars.length === 1 && chars[0] != undefined) { | ||
return chars[0]; | ||
@@ -102,8 +102,5 @@ } | ||
if (!(latin in diacritics)) { | ||
diacritics[latin] = [latin]; | ||
} | ||
const latin_diacritics = diacritics[latin] || [latin]; | ||
const patt = new RegExp(escapeToPattern(latin_diacritics), 'iu'); | ||
var patt = new RegExp(escapeToPattern(diacritics[latin]), 'iu'); | ||
if (diacritic.match(patt)) { | ||
@@ -113,19 +110,18 @@ continue; | ||
diacritics[latin].push(diacritic); | ||
latin_diacritics.push(diacritic); | ||
diacritics[latin] = latin_diacritics; | ||
} | ||
}); // filter out if there's only one character in the list | ||
// todo: this may not be needed | ||
let latin_chars = Object.keys(diacritics); | ||
Object.keys(diacritics).forEach(latin => { | ||
const latin_diacritics = diacritics[latin] || []; | ||
for (let i = 0; i < latin_chars.length; i++) { | ||
const latin = latin_chars[i]; | ||
if (diacritics[latin].length < 2) { | ||
if (latin_diacritics.length < 2) { | ||
delete diacritics[latin]; | ||
} | ||
} // latin character pattern | ||
}); // latin character pattern | ||
// match longer substrings first | ||
latin_chars = Object.keys(diacritics).sort((a, b) => b.length - a.length); | ||
let latin_chars = Object.keys(diacritics).sort((a, b) => b.length - a.length); | ||
latin_pat = new RegExp('(' + escapeToPattern(latin_chars) + accent_pat + '*)', 'gu'); // build diacritic patterns | ||
@@ -132,0 +128,0 @@ // ae needs: |
@@ -252,6 +252,2 @@ /*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */ | ||
} | ||
} | ||
for (i = 0, n = sort_flds.length; i < n; i++) { | ||
multipliers.push(sort_flds[i].direction === 'desc' ? -1 : 1); | ||
} // build function | ||
@@ -264,21 +260,21 @@ | ||
return null; | ||
} else if (sort_flds_count === 1) { | ||
const sort_fld = sort_flds[0].field; | ||
const multiplier = multipliers[0]; | ||
return function (a, b) { | ||
return multiplier * cmp(get_field(sort_fld, a), get_field(sort_fld, b)); | ||
}; | ||
} else { | ||
return function (a, b) { | ||
var i, result, field; | ||
} | ||
for (i = 0; i < sort_flds_count; i++) { | ||
field = sort_flds[i].field; | ||
result = multipliers[i] * cmp(get_field(field, a), get_field(field, b)); | ||
if (result) return result; | ||
return function (a, b) { | ||
var i, result, field; | ||
for (i = 0; i < sort_flds_count; i++) { | ||
field = sort_flds[i].field; | ||
let multiplier = multipliers[i]; | ||
if (multiplier == undefined) { | ||
multiplier = sort_flds[i].direction === 'desc' ? -1 : 1; | ||
} | ||
return 0; | ||
}; | ||
} | ||
result = multiplier * cmp(get_field(field, a), get_field(field, b)); | ||
if (result) return result; | ||
} | ||
return 0; | ||
}; | ||
} | ||
@@ -285,0 +281,0 @@ |
@@ -26,3 +26,3 @@ /** | ||
*/ | ||
export declare const scoreValue: (value: string, token: any, weight: number) => number; | ||
export declare const scoreValue: (value: string, token: T.Token, weight: number) => number; | ||
/** | ||
@@ -29,0 +29,0 @@ * |
@@ -30,3 +30,3 @@ /*! sifter.js | https://github.com/orchidjs/sifter.js | Apache License (v2) */ | ||
return str.normalize('NFKD').replace(accent_reg, '').toLowerCase().replace(convert_pat, function (foreignletter) { | ||
return latin_convert[foreignletter]; | ||
return latin_convert[foreignletter] || foreignletter; | ||
}); | ||
@@ -42,3 +42,3 @@ }; | ||
const arrayToPattern = (chars, glue = '|') => { | ||
if (chars.length == 1) { | ||
if (chars.length === 1 && chars[0] != undefined) { | ||
return chars[0]; | ||
@@ -106,8 +106,5 @@ } | ||
if (!(latin in diacritics)) { | ||
diacritics[latin] = [latin]; | ||
} | ||
const latin_diacritics = diacritics[latin] || [latin]; | ||
const patt = new RegExp(escapeToPattern(latin_diacritics), 'iu'); | ||
var patt = new RegExp(escapeToPattern(diacritics[latin]), 'iu'); | ||
if (diacritic.match(patt)) { | ||
@@ -117,19 +114,18 @@ continue; | ||
diacritics[latin].push(diacritic); | ||
latin_diacritics.push(diacritic); | ||
diacritics[latin] = latin_diacritics; | ||
} | ||
}); // filter out if there's only one character in the list | ||
// todo: this may not be needed | ||
let latin_chars = Object.keys(diacritics); | ||
Object.keys(diacritics).forEach(latin => { | ||
const latin_diacritics = diacritics[latin] || []; | ||
for (let i = 0; i < latin_chars.length; i++) { | ||
const latin = latin_chars[i]; | ||
if (diacritics[latin].length < 2) { | ||
if (latin_diacritics.length < 2) { | ||
delete diacritics[latin]; | ||
} | ||
} // latin character pattern | ||
}); // latin character pattern | ||
// match longer substrings first | ||
latin_chars = Object.keys(diacritics).sort((a, b) => b.length - a.length); | ||
let latin_chars = Object.keys(diacritics).sort((a, b) => b.length - a.length); | ||
latin_pat = new RegExp('(' + escapeToPattern(latin_chars) + accent_pat + '*)', 'gu'); // build diacritic patterns | ||
@@ -530,6 +526,2 @@ // ae needs: | ||
} | ||
} | ||
for (i = 0, n = sort_flds.length; i < n; i++) { | ||
multipliers.push(sort_flds[i].direction === 'desc' ? -1 : 1); | ||
} // build function | ||
@@ -542,21 +534,21 @@ | ||
return null; | ||
} else if (sort_flds_count === 1) { | ||
const sort_fld = sort_flds[0].field; | ||
const multiplier = multipliers[0]; | ||
return function (a, b) { | ||
return multiplier * cmp(get_field(sort_fld, a), get_field(sort_fld, b)); | ||
}; | ||
} else { | ||
return function (a, b) { | ||
var i, result, field; | ||
} | ||
for (i = 0; i < sort_flds_count; i++) { | ||
field = sort_flds[i].field; | ||
result = multipliers[i] * cmp(get_field(field, a), get_field(field, b)); | ||
if (result) return result; | ||
return function (a, b) { | ||
var i, result, field; | ||
for (i = 0; i < sort_flds_count; i++) { | ||
field = sort_flds[i].field; | ||
let multiplier = multipliers[i]; | ||
if (multiplier == undefined) { | ||
multiplier = sort_flds[i].direction === 'desc' ? -1 : 1; | ||
} | ||
return 0; | ||
}; | ||
} | ||
result = multiplier * cmp(get_field(field, a), get_field(field, b)); | ||
if (result) return result; | ||
} | ||
return 0; | ||
}; | ||
} | ||
@@ -563,0 +555,0 @@ |
@@ -5,3 +5,3 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).sifter=t()}(this,(function(){"use strict" | ||
var n | ||
const i={"æ":"ae","ⱥ":"a","ø":"o"},o=new RegExp(Object.keys(i).join("|"),"gu"),s=[[0,65535]],c=e=>e.normalize("NFKD").replace(r,"").toLowerCase().replace(o,(function(e){return i[e]})),u=(e,t="|")=>{if(1==e.length)return e[0] | ||
const i={"æ":"ae","ⱥ":"a","ø":"o"},o=new RegExp(Object.keys(i).join("|"),"gu"),s=[[0,65535]],c=e=>e.normalize("NFKD").replace(r,"").toLowerCase().replace(o,(function(e){return i[e]||e})),u=(e,t="|")=>{if(1===e.length&&null!=e[0])return e[0] | ||
var r=1 | ||
@@ -13,9 +13,9 @@ return e.forEach((e=>{r=Math.max(r,e.length)})),1==r?"["+e.join("")+"]":"(?:"+e.join(t)+")"},f=e=>{const t=e.map((e=>d(e))) | ||
n[0]=e.charAt(0)+n[0],t.push(n),(n=r.slice(0)).unshift(e.charAt(0)),t.push(n)})),t},l=t=>{void 0===n&&(n=(t=>{var r={} | ||
t.forEach((e=>{for(let n=e[0];n<=e[1];n++){let e=String.fromCharCode(n),i=c(e) | ||
if(i!=e.toLowerCase()&&!(i.length>3)){i in r||(r[i]=[i]) | ||
var t=new RegExp(f(r[i]),"iu") | ||
e.match(t)||r[i].push(e)}}})) | ||
let n=Object.keys(r) | ||
for(let e=0;e<n.length;e++){const t=n[e] | ||
r[t].length<2&&delete r[t]}n=Object.keys(r).sort(((e,t)=>t.length-e.length)),e=new RegExp("("+f(n)+"[̀-ͯ·ʾ]*)","gu") | ||
t.forEach((e=>{for(let t=e[0];t<=e[1];t++){let e=String.fromCharCode(t),n=c(e) | ||
if(n==e.toLowerCase())continue | ||
if(n.length>3)continue | ||
const i=r[n]||[n],o=new RegExp(f(i),"iu") | ||
e.match(o)||(i.push(e),r[n]=i)}})),Object.keys(r).forEach((e=>{(r[e]||[]).length<2&&delete r[e]})) | ||
let n=Object.keys(r).sort(((e,t)=>t.length-e.length)) | ||
e=new RegExp("("+f(n)+"[̀-ͯ·ʾ]*)","gu") | ||
var i={} | ||
@@ -70,8 +70,7 @@ return n.sort(((e,t)=>e.length-t.length)).forEach((e=>{var t=a(e).map((e=>(e=e.map((e=>r.hasOwnProperty(e)?f(r[e]):e)),u(e,"")))) | ||
break}n&&c.unshift({field:"$score",direction:"desc"})}else for(t=0,r=c.length;t<r;t++)if("$score"===c[t].field){c.splice(t,1) | ||
break}for(t=0,r=c.length;t<r;t++)u.push("desc"===c[t].direction?-1:1) | ||
const a=c.length | ||
if(a){if(1===a){const e=c[0].field,t=u[0] | ||
return function(r,n){return t*v(f(e,r),f(e,n))}}return function(e,t){var r,n,i | ||
for(r=0;r<a;r++)if(i=c[r].field,n=u[r]*v(f(i,e),f(i,t)))return n | ||
return 0}}return null}prepareSearch(e,t){const r={} | ||
break}const a=c.length | ||
return a?function(e,t){var r,n,i | ||
for(r=0;r<a;r++){i=c[r].field | ||
let o=u[r] | ||
if(null==o&&(o="desc"===c[r].direction?-1:1),n=o*v(f(i,e),f(i,t)))return n}return 0}:null}prepareSearch(e,t){const r={} | ||
var n=Object.assign({},t) | ||
@@ -78,0 +77,0 @@ if(m(n,"sort"),m(n,"sort_empty"),n.fields){m(n,"fields") |
@@ -35,3 +35,3 @@ | ||
.replace(convert_pat,function(foreignletter) { | ||
return latin_convert[foreignletter]; | ||
return latin_convert[foreignletter] || foreignletter; | ||
}); | ||
@@ -48,3 +48,3 @@ }; | ||
if( chars.length == 1 ){ | ||
if( chars.length === 1 && chars[0] != undefined ){ | ||
return chars[0]; | ||
@@ -118,12 +118,9 @@ } | ||
if( !(latin in diacritics) ){ | ||
diacritics[latin] = [latin]; | ||
} | ||
var patt = new RegExp( escapeToPattern(diacritics[latin]),'iu'); | ||
const latin_diacritics:string[] = diacritics[latin] || [latin]; | ||
const patt = new RegExp( escapeToPattern(latin_diacritics),'iu'); | ||
if( diacritic.match(patt) ){ | ||
continue; | ||
} | ||
diacritics[latin].push(diacritic); | ||
latin_diacritics.push(diacritic); | ||
diacritics[latin] = latin_diacritics; | ||
} | ||
@@ -133,9 +130,9 @@ }); | ||
// filter out if there's only one character in the list | ||
let latin_chars = Object.keys(diacritics); | ||
for( let i = 0; i < latin_chars.length; i++){ | ||
const latin = latin_chars[i]; | ||
if( diacritics[latin].length < 2 ){ | ||
// todo: this may not be needed | ||
Object.keys(diacritics).forEach(latin => { | ||
const latin_diacritics = diacritics[latin] || []; | ||
if( latin_diacritics.length < 2 ){ | ||
delete diacritics[latin]; | ||
} | ||
} | ||
}); | ||
@@ -145,3 +142,3 @@ | ||
// match longer substrings first | ||
latin_chars = Object.keys(diacritics).sort((a, b) => b.length - a.length ); | ||
let latin_chars = Object.keys(diacritics).sort((a, b) => b.length - a.length ); | ||
latin_pat = new RegExp('('+ escapeToPattern(latin_chars) + accent_pat + '*)','gu'); | ||
@@ -161,3 +158,3 @@ | ||
if( diacritics.hasOwnProperty(l) ){ | ||
return escapeToPattern(diacritics[l]); | ||
return escapeToPattern(diacritics[l]!); | ||
} | ||
@@ -164,0 +161,0 @@ return l; |
@@ -63,4 +63,4 @@ /** | ||
if( field_regex && (field_match = word.match(field_regex)) ){ | ||
field = field_match[1]; | ||
word = field_match[2]; | ||
field = field_match[1]!; | ||
word = field_match[2]!; | ||
} | ||
@@ -254,5 +254,2 @@ | ||
for (i = 0, n = sort_flds.length; i < n; i++) { | ||
multipliers.push(sort_flds[i].direction === 'desc' ? -1 : 1); | ||
} | ||
@@ -263,25 +260,23 @@ // build function | ||
return null; | ||
} else if (sort_flds_count === 1) { | ||
const sort_fld = sort_flds[0].field; | ||
const multiplier = multipliers[0]; | ||
return function(a:T.ResultItem, b:T.ResultItem) { | ||
return multiplier * cmp( | ||
get_field(sort_fld, a), | ||
get_field(sort_fld, b) | ||
} | ||
return function(a:T.ResultItem, b:T.ResultItem) { | ||
var i, result, field; | ||
for (i = 0; i < sort_flds_count; i++) { | ||
field = sort_flds[i].field; | ||
let multiplier = multipliers[i]; | ||
if( multiplier == undefined ){ | ||
multiplier = sort_flds[i].direction === 'desc' ? -1 : 1; | ||
} | ||
result = multiplier * cmp( | ||
get_field(field, a), | ||
get_field(field, b) | ||
); | ||
}; | ||
} else { | ||
return function(a:T.ResultItem, b:T.ResultItem) { | ||
var i, result, field; | ||
for (i = 0; i < sort_flds_count; i++) { | ||
field = sort_flds[i].field; | ||
result = multipliers[i] * cmp( | ||
get_field(field, a), | ||
get_field(field, b) | ||
); | ||
if (result) return result; | ||
} | ||
return 0; | ||
}; | ||
} | ||
if (result) return result; | ||
} | ||
return 0; | ||
}; | ||
}; | ||
@@ -288,0 +283,0 @@ |
@@ -14,3 +14,3 @@ { | ||
"description": "A library for textually searching arrays and hashes of objects by property (or multiple properties). Designed specifically for autocomplete.", | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"license": "Apache-2.0", | ||
@@ -46,3 +46,3 @@ "author": "Brian Reavis <brian@thirdroute.com>", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"typescript": "^4.2.4" | ||
"typescript": "^4.7.4" | ||
}, | ||
@@ -49,0 +49,0 @@ "browserslist": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
225803
2526