Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/dtils/mod.ts>SafeUnknownObject#get

The best unofficial library of utilities for Deno applications
Go to Latest
method SafeUnknownObject.prototype.get
import { SafeUnknownObject } from "https://deno.land/x/dtils@2.5.0/mod.ts";

Gets the value of an object path in the object. If a key doesn't exist, a SafeUnknown with null will be returned. If a key gives null, either by it not existing, or it actually being null, a SafeUnknown with null is immediately returned.

Examples:

new SafeUnknownObject({ foo: null }).get('foo', 'bar', 'bin', 'baz').isNull() // true
new SafeUnknownObject({}).get('foo').isNull() // true
new SafeUnknownObject({}).get('foo', 'bar', 'bin', 'baz').isNull() // true
new SafeUnknownObject({ foo: "hello" }).get('foo', 'bar', 'bin', 'baz') // Error: Expected data to be an object, but found type string at $.foo
new SafeUnknownObject({ foo: { bar: { bin: { baz: "Hello" }}}}).asString() // "Hello"

Parameters

...keys: string[]