mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
refactor(yaml): simplify set type (#5867)
This commit is contained in:
parent
a26ce0fb4a
commit
15bf9115dd
@ -5,25 +5,13 @@
|
||||
|
||||
import type { Type } from "../_type.ts";
|
||||
|
||||
function resolveYamlSet(data: Record<string, unknown>): boolean {
|
||||
if (data === null) return true;
|
||||
|
||||
for (const key in data) {
|
||||
if (Object.hasOwn(data, key)) {
|
||||
if (data[key] !== null) return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function constructYamlSet(data: string) {
|
||||
return data !== null ? data : {};
|
||||
}
|
||||
|
||||
export const set: Type<"mapping", Record<PropertyKey, unknown>> = {
|
||||
tag: "tag:yaml.org,2002:set",
|
||||
construct: constructYamlSet,
|
||||
kind: "mapping",
|
||||
resolve: resolveYamlSet,
|
||||
construct: (data: Record<string, unknown>): Record<string, unknown> =>
|
||||
data !== null ? data : {},
|
||||
resolve: (data: Record<string, unknown>): boolean => {
|
||||
if (data === null) return true;
|
||||
return Object.values(data).every((it) => it === null);
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user