perform checkMatchesObjectStructure in parseValidObject

This commit is contained in:
marlon-erler
2024-07-22 01:40:00 +02:00
parent d85ced4e36
commit 53399ba2b4
4 changed files with 25 additions and 18 deletions
+9 -2
View File
@@ -1,4 +1,4 @@
import { checkIsValidObject } from "./typeSafety";
import { checkIsValidObject, checkMatchesObjectStructure } from "./typeSafety";
// date
export function createTimestamp(): string {
@@ -18,9 +18,16 @@ export function parse(string: string): any {
}
}
export function parseValidObject<T>(string: string): T|null {
export function parseValidObject<T>(string: string, reference: T): T | null {
const parsed: any = parse(string);
if (checkIsValidObject(parsed) == false) return null;
const doesMatchReference: boolean = checkMatchesObjectStructure(
parsed,
reference
);
if (doesMatchReference == false) return null;
return parsed;
}