UNPKG

error-serializer

Version:
28 lines (17 loc) 551 B
import isPlainObj from"is-plain-obj"; export const isErrorObject=(value)=> isPlainObj(value)&&isStringProp(value,"message"); const isStringProp=(object,propName)=> isSafeProp(object,propName)&&typeof object[propName]==="string"; export const REQUIRED_PROPERTY="message"; export const safeListKeys=(value)=>listSafeKeys(value,Object.keys(value)); export const listSafeKeys=(object,keys)=> keys.filter((propName)=>isSafeProp(object,propName)); const isSafeProp=(object,propName)=>{ try{ object[propName]; return true }catch{ return false } };