separate checkDoesObjectMatchReference from StringEntryObject
This commit is contained in:
@@ -35,14 +35,27 @@ export function filterObjectsByStringEntries<T>(
|
||||
converter: (T) => StringEntryObject,
|
||||
objects: T[]
|
||||
): Set<T> {
|
||||
const matches: Set<T> = new Set()
|
||||
const matches: Set<T> = new Set();
|
||||
|
||||
object_loop: for (const object of objects) {
|
||||
const doesMatch: boolean = checkDoesObjectMatchReference(
|
||||
reference,
|
||||
converter(object)
|
||||
);
|
||||
if (doesMatch) matches.add(object);
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
export function checkDoesObjectMatchReference<T>(
|
||||
reference: StringEntryObject,
|
||||
stringEntryObject: StringEntryObject
|
||||
): boolean {
|
||||
reference_entry_loop: for (const referenceEntry of Object.entries(
|
||||
reference
|
||||
)) {
|
||||
const [referenceKey, referenceValue] = referenceEntry;
|
||||
const stringEntryObject: StringEntryObject = converter(object);
|
||||
const stringEntryObjectValue: string = stringEntryObject[referenceKey];
|
||||
|
||||
if (referenceValue[0] == "-") {
|
||||
@@ -53,12 +66,12 @@ export function filterObjectsByStringEntries<T>(
|
||||
stringEntryObjectValue != undefined &&
|
||||
stringEntryObjectValue != ""
|
||||
) {
|
||||
continue object_loop;
|
||||
return false;
|
||||
}
|
||||
|
||||
// property may not match
|
||||
if (stringEntryObjectValue == strippedReferenceValue) {
|
||||
continue object_loop;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// property must exist but be anything
|
||||
@@ -66,21 +79,18 @@ export function filterObjectsByStringEntries<T>(
|
||||
referenceValue == "" &&
|
||||
(stringEntryObjectValue == undefined || stringEntryObjectValue == "")
|
||||
) {
|
||||
continue object_loop;
|
||||
return false;
|
||||
} else if (referenceValue == "") {
|
||||
continue reference_entry_loop;
|
||||
}
|
||||
|
||||
// property must match
|
||||
if (stringEntryObjectValue != referenceValue) {
|
||||
continue object_loop;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
matches.add(object);
|
||||
}
|
||||
|
||||
return matches;
|
||||
return true;
|
||||
}
|
||||
|
||||
export function collectObjectValuesForKey<T>(
|
||||
|
||||
Reference in New Issue
Block a user