Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/dtils/mod.unstable.ts>SafeUnknownObject#get

The best unofficial library of utilities for Deno applications
Latest
method SafeUnknownObject.prototype.get
import { SafeUnknownObject } from "https://deno.land/x/dtils@2.6.1/mod.unstable.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[]