Skip to main content

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