this.searchKeys = null;
this.isContain = false;
this.isCaseSensitive = false;
+ this.normalizeUnicode = true;
this.ignoreWhitespace = true;
this.limit = null;
this.findingList = [];
* @param {string | [string]} [opts.keys=null]
* @param {boolean} [opts.isContain=false] - Add finding to result if it contain search term
* @param {boolean} [opts.isCaseSensitive=false]
+ * @param {boolean} [opts.normalizeUnicode=true]
* @param {boolean} [opts.ignoreWhitespace=true]
* @param {number} [opts.limit=null] - Stop search after limit
*/
this.searchKeys = opts?.keys || null;
this.isContain = opts?.isContain || false;
this.isCaseSensitive = opts?.isCaseSensitive || false;
+ this.normalizeUnicode = opts?.normalizeUnicode || true;
this.ignoreWhitespace = opts?.ignoreWhitespace || true;
this.limit = opts?.limit || null;
}
search(term) {
this._softReset();
- this.term = (this.isCaseSensitive) ? term : term.toLocaleLowerCase();
- if (this.ignoreWhitespace) this.term = this.term.replaceAll(' ', '');
+ this.term = this._normalize(term);
if (this.term === '') {
this._sendFindings();
return;
_compare(item) {
if (typeof item !== 'string') return false;
- let myItem = (this.isCaseSensitive) ? item : item.toLocaleLowerCase();
- if (this.ignoreWhitespace) myItem = myItem.replaceAll(' ', '');
-
+ const myItem = this._normalize(item);
if (this.isContain) return myItem.indexOf(this.term) !== -1;
return myItem.startsWith(this.term);
}
+ _normalize(item) {
+ let myItem = item.normalize(this.normalizeUnicode ? 'NFKC' : 'NFC');
+ if (!this.isCaseSensitive) myItem = myItem.toLocaleLowerCase();
+ if (this.ignoreWhitespace) myItem = myItem.replaceAll(' ', '');
+ return myItem;
+ }
+
_sendFindings() {
this.emit(this.RESULT_SENT, this.findingList, this.term);
}