// Ported from js-yaml v3.13.1:
// https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import type { Type } from "../_type.ts";

const YAML_TRUE_BOOLEANS = ["true", "True", "TRUE"];
const YAML_FALSE_BOOLEANS = ["false", "False", "FALSE"];
const YAML_BOOLEANS = [...YAML_TRUE_BOOLEANS, ...YAML_FALSE_BOOLEANS];

export const bool: Type<"scalar", boolean> = {
  tag: "tag:yaml.org,2002:bool",
  kind: "scalar",
  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: {
    // deno-lint-ignore ban-types
    lowercase: (object: boolean | Boolean): string => {
      const value = object instanceof Boolean ? object.valueOf() : object;
      return value ? "true" : "false";
    },
    // deno-lint-ignore ban-types
    uppercase: (object: boolean | Boolean): string => {
      const value = object instanceof Boolean ? object.valueOf() : object;
      return value ? "TRUE" : "FALSE";
    },
    // deno-lint-ignore ban-types
    camelcase: (object: boolean | Boolean): string => {
      const value = object instanceof Boolean ? object.valueOf() : object;
      return value ? "True" : "False";
    },
  },
};

// denoCacheMetadata={"headers":{"accept-ranges":"bytes","vary":"Origin","access-control-expose-headers":"*","access-control-allow-origin":"*","cache-control":"public, max-age=31536000, immutable","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","cf-cache-status":"HIT","x-content-type-options":"nosniff","age":"3680076","etag":"\"f045ffcf9744b66680452b926444b8ed\"","content-length":"1529","cross-origin-resource-policy":"cross-origin","x-robots-tag":"noindex","alt-svc":"h3=\":443\"; ma=86400","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","server":"cloudflare","cf-ray":"a223e6590e377db6-LAX","content-type":"text/typescript","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=AcnUVQZCxqoDl8QErEZxyQ6EBkEyZb6%2B3weanlrwqjj44F7CzRloUHuSd%2BUWvg4qVbvi3kwtfz9LPdJqZHACnan2NkhgaWDGPYUyvicHoRcCpp%2FEEx8x0Ac%3D\"}]}","x-jsr-backend":"modules","set-cookie":"__cf_bm=jNUgcbdyTdDckdNr.hupznEAD066U8tw1oG8QOixsG4-1785241875.3684645-1.0.1.1-MyVfqTQAgR3kF3s5XVIqahi2uYLKLt3WrUvC1fdLhWPl_y7HmLJy8XB6nRKYGRMOtZdlm8jjCgSN1IKrq36KXNiFnYlPJ6OC3wHMgXXTmW8pNMuzoBmm0Mh2wVKAswY8; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","date":"Tue, 28 Jul 2026 12:31:15 GMT"},"url":"https://jsr.io/@std/yaml/1.0.5/_type/bool.ts","time":1785241875}