UNPKG

vuoto

Version:

Modern whitespace normalizer CLI with enhanced output and developer experience - cut the noise, clean the void

29 lines (28 loc) 740 B
/** * A typeguarded version of `instanceof Error` for NodeJS. * @param value The value to check. * @param errorType The error type to check against. * * @returns True if the value is an instance of the given error type and has NodeJS-specific error properties. * * @example * * ```ts * try { * // ... * } catch (error) { * if (instanceOfNodeError(error, TypeError)) { * console.error(error.code); * } * } * ``` */ export function instanceOfNodeError(value, errorType) { if (!(value instanceof errorType)) { return false; } const candidate = value; return (typeof candidate.code === 'string' || typeof candidate.code === 'number' || typeof candidate.errno === 'number'); }