mirror of
https://github.com/denoland/std.git
synced 2024-11-21 12:40:03 +00:00
parent
b8df2b3494
commit
11fce1a431
@ -4,36 +4,22 @@
|
||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import type { Type } from "../_type.ts";
|
||||
import { isBoolean } from "../_utils.ts";
|
||||
|
||||
const YAML_TRUE_BOOLEANS = ["true", "True", "TRUE"];
|
||||
const YAML_FALSE_BOOLEANS = ["false", "False", "FALSE"];
|
||||
const YAML_BOOLEANS = [...YAML_TRUE_BOOLEANS, ...YAML_FALSE_BOOLEANS];
|
||||
|
||||
function resolveYamlBoolean(data: string): boolean {
|
||||
return YAML_BOOLEANS.includes(data);
|
||||
}
|
||||
|
||||
function constructYamlBoolean(data: string): boolean {
|
||||
return YAML_TRUE_BOOLEANS.includes(data);
|
||||
}
|
||||
|
||||
export const bool: Type<"scalar", boolean> = {
|
||||
tag: "tag:yaml.org,2002:bool",
|
||||
construct: constructYamlBoolean,
|
||||
defaultStyle: "lowercase",
|
||||
kind: "scalar",
|
||||
predicate: isBoolean,
|
||||
defaultStyle: "lowercase",
|
||||
predicate: (value: unknown): value is boolean =>
|
||||
typeof value === "boolean" || value instanceof Boolean,
|
||||
construct: (data: string): boolean => YAML_TRUE_BOOLEANS.includes(data),
|
||||
resolve: (data: string): boolean => YAML_BOOLEANS.includes(data),
|
||||
represent: {
|
||||
lowercase(object: boolean): string {
|
||||
return object ? "true" : "false";
|
||||
},
|
||||
uppercase(object: boolean): string {
|
||||
return object ? "TRUE" : "FALSE";
|
||||
},
|
||||
camelcase(object: boolean): string {
|
||||
return object ? "True" : "False";
|
||||
},
|
||||
lowercase: (object: boolean): string => object ? "true" : "false",
|
||||
uppercase: (object: boolean): string => object ? "TRUE" : "FALSE",
|
||||
camelcase: (object: boolean): string => object ? "True" : "False",
|
||||
},
|
||||
resolve: resolveYamlBoolean,
|
||||
};
|
||||
|
@ -3,10 +3,6 @@
|
||||
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
|
||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
export function isBoolean(value: unknown): value is boolean {
|
||||
return typeof value === "boolean" || value instanceof Boolean;
|
||||
}
|
||||
|
||||
export function isObject(value: unknown): value is Record<string, unknown> {
|
||||
return value !== null && typeof value === "object";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user