refactor(yaml): simplify null type (#5858)

initial commit
This commit is contained in:
Tim Reichen 2024-08-29 02:17:00 +02:00 committed by GitHub
parent 11fce1a431
commit 2c4287178a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,39 +5,23 @@
import type { Type } from "../_type.ts";
function resolveYamlNull(data: string): boolean {
const max = data.length;
return (
(max === 1 && data === "~") ||
(max === 4 && (data === "null" || data === "Null" || data === "NULL"))
);
}
function constructYamlNull(): null {
return null;
}
function isNull(object: unknown): object is null {
return object === null;
}
export const nil: Type<"scalar", null> = {
tag: "tag:yaml.org,2002:null",
construct: constructYamlNull,
defaultStyle: "lowercase",
kind: "scalar",
predicate: isNull,
represent: {
lowercase(): string {
return "null";
},
uppercase(): string {
return "NULL";
},
camelcase(): string {
return "Null";
},
defaultStyle: "lowercase",
predicate: (object: unknown): object is null => object === null,
construct: () => null,
resolve: (data: string): boolean => {
return (
data === "~" ||
data === "null" ||
data === "Null" ||
data === "NULL"
);
},
represent: {
lowercase: (): string => "null",
uppercase: (): string => "NULL",
camelcase: (): string => "Null",
},
resolve: resolveYamlNull,
};