I firmly believe in free software. The application I'm making here have capabilities that I've not seen in any system. It presents itself as an opportunity to collaborate on a tool that serves the people rather than corporations. Whose incentives are to help people rather, not make the most money. And whose terms ensure that these freedoms and incentives cannot be taken back or subverted. I license this software under the AGPL.
41 lines
951 B
TypeScript
41 lines
951 B
TypeScript
/*
|
|
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
export function useStringSort() {
|
|
const accountStore = useAccountStore();
|
|
const localeCompare = computed(() => Intl.Collator(
|
|
accountStore.activeLocale,
|
|
{
|
|
usage: "sort",
|
|
numeric: true,
|
|
sensitivity: "base",
|
|
},
|
|
).compare);
|
|
return function stringSort(a: string, b: string) {
|
|
return localeCompare.value(a, b);
|
|
}
|
|
}
|
|
|
|
export function useFuzzyMatch() {
|
|
const accountStore = useAccountStore();
|
|
const localeCompare = computed(() => Intl.Collator(
|
|
accountStore.activeLocale,
|
|
{
|
|
usage: "search",
|
|
sensitivity: "base",
|
|
},
|
|
).compare);
|
|
return function fuzzyMatch(pattern: string, text: string) {
|
|
let pos = 0;
|
|
for (const char of text) {
|
|
if (localeCompare.value(char, pattern[pos]) === 0) {
|
|
pos += 1;
|
|
if (pos === pattern.length) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return pos === pattern.length;
|
|
}
|
|
}
|