// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
 * Returns true if the given value is part of the given object, otherwise it
 * returns false.
 *
 * Note: this doesn't work with non-primitive values. For example,
 * `includesValue({x: {}}, {})` returns false.
 *
 * @template T The type of the values in the input record.
 *
 * @param record The record to check for the given value.
 * @param value The value to check for in the record.
 *
 * @returns `true` if the value is part of the record, otherwise `false`.
 *
 * @example Basic usage
 * ```ts
 * import { includesValue } from "@std/collections/includes-value";
 * import { assertEquals } from "@std/assert/assert-equals";
 *
 * const input = {
 *   first: 33,
 *   second: 34,
 * };
 *
 * assertEquals(includesValue(input, 34), true);
 * ```
 */
export function includesValue<T>(
  record: Readonly<Record<string, T>>,
  value: T,
): boolean {
  for (const i in record) {
    if (
      Object.hasOwn(record, i) &&
      (record[i] === value || Number.isNaN(value) && Number.isNaN(record[i]))
    ) {
      return true;
    }
  }

  return false;
}

// denoCacheMetadata={"headers":{"nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","cf-ray":"a223e6564eff7db6-LAX","date":"Tue, 28 Jul 2026 12:31:15 GMT","access-control-allow-origin":"*","content-type":"text/typescript","vary":"Origin","cross-origin-resource-policy":"cross-origin","x-content-type-options":"nosniff","cache-control":"public, max-age=31536000, immutable","etag":"\"ce41b4063126d631c209cf4b92f36182\"","access-control-expose-headers":"*","x-jsr-backend":"modules","set-cookie":"__cf_bm=yafFtMFY_xwRQxF3J9E8OsycWgh2aoipeBtppQ9S45M-1785241874.955034-1.0.1.1-QflgFIHgE1mQW3M48V6UqjVGgIQFAaXnN9vZSu_LOOdcS9Jwu0NKCH36oL5ttj0aFJt6lzFlbw9n1lKjuDXDKsS9r2ixPHR0uCCF6UiQoyiMULs0YCHZhXQ7eUwA2REf; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","server":"cloudflare","alt-svc":"h3=\":443\"; ma=86400","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=gpMtOSpK0irxPfdTZ8ZOQ85jBrH3dpK2%2Fbfi6ATTxnjWhX4wZE%2BNn5C%2FMwF9omXp1Zh%2FNlQBEjQj5UsmV4OLdHslTorkWPB3G35X%2FwqexyXSuoUIh4IMLn0%3D\"}]}","x-robots-tag":"noindex","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';","content-length":"1176"},"url":"https://jsr.io/@std/collections/0.224.2/includes_value.ts","time":1785241875}