interpolate
Helpers utility functions library.
getObjPath()β
function getObjPath(
path,
obj,
fallback): unknown
Returns the value of the specified property or nested property of an object using a string path.
Parametersβ
β’ path: Maybe
<string
>
property path as string.
β’ obj: unknown
the key/value record object.
β’ fallback: unknown
= ""
optional fallback value to be returned if the path cannot be resolved.
Returnsβ
unknown
the property value if the path is resolved, else returns the fallback
value.
Exampleβ
import { getObjPath } from '@graphql-markdown/utils/object';
getObjPath("foo.bar", { foo: { bar: 42 } }); // Returns 42
getObjPath("foo.bak", { foo: { bar: 42 } }, "fallback"); // Returns "fallback"
Defined inβ
utils/interpolate.ts:31
interpolate()β
function interpolate(
template,
variables,
fallback?): string
Interpolate a template literal-like string.
Parametersβ
β’ template: string
a string template literal-like.
β’ variables: Maybe
<Record
<string
, unknown
> & object
>
a record map of values with variable's name as key and description
as directive's description.
β’ fallback?: string
optional fallback value if a variable cannot be substituted.
Returnsβ
string
an interpolated new string from the template.
Exampleβ
const values = { foo: 42, bar: { value: "test" } };
const template = "${foo} is not ${bar.notfound}";
interpolate(template, values, "fallback"); // Expected result: "42 is not fallback",
Defined inβ
utils/interpolate.ts:64