Skip to main content
Module

x/registerable/deps.ts>has

Check if it can be registered as a package name or domain name
Latest
variable has
import { has } from "https://deno.land/x/registerable@v1.3.2/deps.ts";

Returns whether or not an object has an own property with the specified name.

Examples

Example 1

// Flat
has('hello', { hello: 'world' }) // true
has(0, { 0 : 1}) // true
has('', {}) // false
has('hello', { hi : hello: 'world' }) // false

Example 2

// Nest
hasPath(['hello'], { hello: 'world' }) // true
hasPath([0], { 0: 1 }) // true
hasPath(['hello', 'world'], { hello: { world: '' } } // true

hasPath(['hi'], { hello: '' } ) // false
hasPath(['hi', 'Tom'], { hi: { John: 1 } } ) // false

type

<T extends string | number | (string | number)[], U extends Record<PropertyKey, unknown>>(props: T, obj: U) => T extends unknown[] ? boolean : T extends string | number ? U extends Record<T, unknown> ? true : false : never