mirror of
https://github.com/koloml/philomena-tagging-assistant.git
synced 2026-05-09 15:12:21 +00:00
Added Tag Presets, popup editor for them, implemented presets image edit
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import type StorageEntity from "$lib/extension/base/StorageEntity";
|
||||
import type TagGroup from "$entities/TagGroup";
|
||||
|
||||
/**
|
||||
* Traverse and find the object using the key path.
|
||||
* @param targetObject Target object to traverse into.
|
||||
@@ -39,3 +42,14 @@ export function escapeRegExp(value: string): string {
|
||||
unsafeRegExpCharacters.lastIndex = 0;
|
||||
return value.replace(unsafeRegExpCharacters, "\\$&");
|
||||
}
|
||||
|
||||
type OnlyStringFields<Fields extends Record<string, any>> = {
|
||||
[FieldKey in keyof Fields as Fields[FieldKey] extends string ? FieldKey : never]: string;
|
||||
};
|
||||
|
||||
export function sortEntitiesByField<Fields extends Object>(entities: StorageEntity<Fields>[], fieldName: keyof OnlyStringFields<Fields>) {
|
||||
return entities.toSorted(
|
||||
(a, b) => (a.settings[fieldName] as string)
|
||||
.localeCompare(b.settings[fieldName] as string)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user