import { SafeUnknownObject } from "https://deno.land/x/dtils@2.6.1/safe_unknown.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"