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

x/dtils/mod.ts>SafeUnknownObject#sureGet

The best unofficial library of utilities for Deno applications
Go to Latest
method SafeUnknownObject.prototype.sureGet
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, an error is thrown. Unlike get, null is not immediately returned.

Examples:

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

Parameters

...keys: string[]