shelving
Version:
Toolkit for using data in JavaScript.
29 lines (28 loc) • 1.53 kB
TypeScript
import type { ImmutableDictionary } from "./dictionary.js";
import type { AnyCaller } from "./function.js";
/** Log an error to the console. */
export declare function logError(reason: unknown): void;
/** Is an unknown value an `Error` instance? */
export declare function isError(v: unknown): v is Error & {
readonly code?: string | undefined;
};
/** Things that can be a message. */
export type PossibleMessage = {
message: string;
} | string;
/** Return the string message from an unknown value, or return `undefined` if it could not be found. */
export declare function getMessage(input: unknown): string | undefined;
/** Require a message from an unknown value, or throw `RequiredError` if it could not be found. */
export declare function requireMessage(input: PossibleMessage, caller?: AnyCaller): string;
/**
* Split a string message into lines, look for prefixes like `name:`, and return a dictionary of those named messages.
* - Full messages strings can have multiple lines separated by `\n` newline.
* - Named messages are extracted into their own entries in the dictionary.
* - Unnamed messages are combined into a single entry with the key `""` (empty string).
*/
export declare function splitMessage(input: PossibleMessage): ImmutableDictionary<string>;
/**
* Name a message by applying a `name: ` prefix to it.
* - Assumes each line in the message is a separate error, so each line has the same prefix applied.
*/
export declare function getNamedMessage(name: string | number, message: string): string;