From e1ce293a48721500a19247201cc81a3cc41099d3 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 27 Aug 2024 13:50:02 +0200 Subject: [PATCH 1/2] initial commit --- yaml/_type/omap.ts | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/yaml/_type/omap.ts b/yaml/_type/omap.ts index 74084ce68960..2c79dd040194 100644 --- a/yaml/_type/omap.ts +++ b/yaml/_type/omap.ts @@ -7,30 +7,18 @@ import type { Type } from "../_type.ts"; import { getObjectTypeString } from "../_utils.ts"; function resolveYamlOmap(data: Record[]): boolean { - const objectKeys: string[] = []; - let pairKey = ""; - let pairHasKey = false; - - for (const pair of data) { - pairHasKey = false; - - if (getObjectTypeString(pair) !== "[object Object]") { - return false; - } - - for (pairKey in pair) { - if (Object.hasOwn(pair, pairKey)) { - if (!pairHasKey) pairHasKey = true; - else return false; - } + if (!data.length) return false; + + const objectKeys = new Set(); + for (const object of data) { + if (getObjectTypeString(object) !== "[object Object]") return false; + const keys = Object.keys(object); + if (keys.length !== 1) return false; + for (const key of keys) { + if (objectKeys.has(key)) return false; + objectKeys.add(key); } - - if (!pairHasKey) return false; - - if (!objectKeys.includes(pairKey)) objectKeys.push(pairKey); - else return false; } - return true; } From 5ece346b091bd365d5da7b3e569400a792fddbb4 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 27 Aug 2024 14:56:05 +0200 Subject: [PATCH 2/2] update --- yaml/_type/omap.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/yaml/_type/omap.ts b/yaml/_type/omap.ts index 2c79dd040194..88682338a9d9 100644 --- a/yaml/_type/omap.ts +++ b/yaml/_type/omap.ts @@ -7,8 +7,6 @@ import type { Type } from "../_type.ts"; import { getObjectTypeString } from "../_utils.ts"; function resolveYamlOmap(data: Record[]): boolean { - if (!data.length) return false; - const objectKeys = new Set(); for (const object of data) { if (getObjectTypeString(object) !== "[object Object]") return false;