deno.land / std@0.177.1 / collections / includes_value.ts

includes_value.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.
/** * If the given value is part of the given object it returns true, otherwise it * returns false. Doesn't work with non-primitive values: includesValue({x: {}}, * {}) returns false. * * @example * ```ts * import { includesValue } from "https://deno.land/std@$STD_VERSION/collections/includes_value.ts"; * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; * * 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;}
std

Version Info

Tagged at
10 months ago