formatMessage
Turns a diagnostic code into the text the runtime throws or logs: the full sentence in development builds and only a stable code in production builds, so message strings never reach user bundles.
Turns a diagnostic code into the text the runtime throws or logs: the full sentence in development builds and only a stable code in production builds, so message strings never reach user bundles. Use it when a custom primitive reports a core diagnostic in its own way.
Import#
ts
import { formatMessage } from "@shadow-js/core/extend";
Signature#
ts
function formatMessage(code: MessageCode): string
Parameters#
| Name | Description |
|---|---|
code |
The diagnostic code. |
Returns#
[shadow <CODE>] <text> in development builds, SHADOW_<CODE> in production builds.
Examples#
ts
import { formatMessage } from "@shadow-js/core/extend";
const text = formatMessage("CONTEXT_MISSING");
// development: "[shadow CONTEXT_MISSING] useContext() found no provider ..."
// production: "SHADOW_CONTEXT_MISSING"