Skip to content

Function: describeValue()

API / @xmachines/core / utils / describeValue

function describeValue(value): string;

Defined in: packages/core/src/utils/describe-value.ts:53

Describes an unknown value for the message of an error, and throws nothing itself.

JSON.stringify alone is not enough for a value that arrives from the config of a user. It returns the VALUE undefined for a function, for a symbol, and for undefined, which puts the text “undefined” in a field that is declared string. It also THROWS a TypeError for a circular object, and an error constructor that throws hides the error that it was built to report. The fallback names the type instead, for example [function].

Parameters

ParameterTypeDescription
valueunknownThe value to describe.

Returns

string

The JSON text of the value, or its type in brackets.

Example

import { describeValue } from "@xmachines/core/utils";
describeValue({ path: 1 }); // '{"path":1}'
describeValue(() => {}); // "[function]"