@altostra/core
Version:
Core library for shared types and logic
41 lines (40 loc) • 1.64 kB
TypeScript
/// <reference types="node" />
import type { InspectOptions } from 'util';
import type { Maybe } from "../Maybe";
export declare type ErrorHandler<T> = T | ((err: any) => T);
/**
* Gets the value from the value or handler/
* @param err The error that was thrown
* @param handlerOrValue Maybe either actual value, or a function from the error
* to a value
*/
export declare function fromHandler<T>(err: any, handlerOrValue: ErrorHandler<T>): T;
/**
* Gets the value from the value or handler/
* @param err The error that was thrown
* @param handlerOrValue Maybe either actual value, or a function from the error
* to a value
*/
export declare function fromHandler<T>(err: any, handlerOrValue?: ErrorHandler<T>): Maybe<T>;
export interface ErrorLike {
message: string;
}
export declare function isErrorLike(err: any): err is ErrorLike;
export declare const DEF_INSPECT_OPT: InspectOptions;
/**
* Converts the data to JSON. \
* If the data cannot be represented as JSON (circular references, invalid chars, etc')
* it is inspected, and the inspection result is JSON stringified.
* @param data The data to serialize
* @param inspectionDepth If simple JSON serialization fails, specify the inspections
* depth for the data
* @returns Data serialized as string
*/
export declare function safeJSONSerialize(data: unknown, inspectionDepth?: number): string;
/**
* Parse stringified data. \
* Opposite of `JSON.stringify` that doesn't throw on undefined.
* @param json Anything that may return from `JSON.stringify`
* @returns The parsed data
*/
export declare function parseJSONStringified(json: Maybe<string>): unknown;