mirror of
https://github.com/denoland/std.git
synced 2024-11-21 12:40:03 +00:00
refactor(yaml): simplify omap resolve()
(#5843)
* initial commit * update
This commit is contained in:
parent
8770ff156c
commit
c7835496e4
@ -7,28 +7,16 @@ import type { Type } from "../_type.ts";
|
||||
import { isPlainObject } from "../_utils.ts";
|
||||
|
||||
function resolveYamlOmap(data: Record<string, unknown>[]): boolean {
|
||||
const objectKeys: string[] = [];
|
||||
let pairKey = "";
|
||||
let pairHasKey = false;
|
||||
|
||||
for (const pair of data) {
|
||||
pairHasKey = false;
|
||||
|
||||
if (!isPlainObject(pair)) return false;
|
||||
|
||||
for (pairKey in pair) {
|
||||
if (Object.hasOwn(pair, pairKey)) {
|
||||
if (!pairHasKey) pairHasKey = true;
|
||||
else return false;
|
||||
}
|
||||
const objectKeys = new Set();
|
||||
for (const object of data) {
|
||||
if (!isPlainObject(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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user