collator
This commit is contained in:
parent
e0bbd1107b
commit
a55201f928
2 changed files with 7 additions and 8 deletions
|
@ -1,2 +1,3 @@
|
||||||
export const artSize = 96;
|
export const artSize = 96;
|
||||||
export const ytPath = "_youtube";
|
export const ytPath = "_youtube";
|
||||||
|
export const locale = "cs";
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
import * as html from "./html.js";
|
import * as html from "./html.js";
|
||||||
|
import * as conf from "../conf.js";
|
||||||
|
|
||||||
const OPEN = "open";
|
const OPEN = "open";
|
||||||
|
const collator = new Intl.Collator(conf.locale, {usage:"search", sensitivity:"base"});
|
||||||
export function normalize(str) {
|
|
||||||
// FIXME diac/translit
|
|
||||||
return str.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Search extends EventTarget {
|
export default class Search extends EventTarget {
|
||||||
constructor(parent) {
|
constructor(parent) {
|
||||||
|
@ -33,9 +30,10 @@ export default class Search extends EventTarget {
|
||||||
getNode() { return this._node; }
|
getNode() { return this._node; }
|
||||||
|
|
||||||
match(str) {
|
match(str) {
|
||||||
let q = normalize(this._input.value.trim());
|
let q = this._input.value.trim();
|
||||||
if (!q) { return true; }
|
if (!q) { return true; }
|
||||||
return normalize(str).split(" ").some(str => str.indexOf(q) == 0);
|
let len = q.length;
|
||||||
|
return str.split(" ").some(str => collator.compare(q, str.substring(0, len)) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
|
|
Loading…
Reference in a new issue