import { SafeUnknownObject } from "https://deno.land/x/dtils@2.3.1/mod.ts";
Methods
Calls fn
for every item in the array
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"
Gets the value of a single key in the object. If the key doesn't exist, a SafeUnknown
with null
will be returned
Gets an array of all the keys in the object
Calls fn
on each item in the array, returning a new array made up of the results of fn
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"
Gets the value of a single key in the object. If the key doesn't exist, an error is thrown
Gets an array of all the values in the array as safe unknowns