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