UNPKG

@konker.dev/tiny-error-fp

Version:

A configurable error for Typescript projects based on Effect-ts

27 lines 1.12 kB
export const hasTag = (tag) => (x) => { return typeof x === 'object' && !!x && '_tag' in x && typeof x._tag === 'string' && x._tag === tag; }; // -------------------------------------------------------------------------- export function hasErrorMessage(x) { return typeof x === 'object' && !!x && 'message' in x && typeof x.message === 'string'; } export function hasErrorName(x) { return typeof x === 'object' && !!x && 'name' in x && typeof x.name === 'string'; } export function hasErrorStack(x) { return typeof x === 'object' && !!x && 'stack' in x && typeof x.stack === 'string'; } // -------------------------------------------------------------------------- export function isError(x) { return x instanceof Error && hasErrorName(x) && hasErrorMessage(x); } export function toError(x) { return isError(x) ? x : new Error(String(x)); } // -------------------------------------------------------------------------- export function getStackTraceString() { // eslint-disable-next-line fp/no-mutation Error.stackTraceLimit = 100; return Error().stack; } //# sourceMappingURL=lib.js.map