Skip to content

Commit

Permalink
refactor(yaml): simplify null type (denoland#5858)
Browse files Browse the repository at this point in the history
initial commit
  • Loading branch information
timreichen committed Aug 29, 2024
1 parent 11fce1a commit 2c42871
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions yaml/_type/nil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 {
return "null";
},
uppercase(): string {
return "NULL";
},
camelcase(): string {
return "Null";
},
lowercase: (): string => "null",
uppercase: (): string => "NULL",
camelcase: (): string => "Null",
},
resolve: resolveYamlNull,
};

0 comments on commit 2c42871

Please sign in to comment.