ferrum icon indicating copy to clipboard operation
ferrum copied to clipboard

null/undefined safe ways of working with properties & entries

Open koraa opened this issue 4 years ago • 0 comments

Type safe way of iterating the properties of arbitrary types; this is a reflection feature and refers to arbitrary types.

const entries = (o) => isdef(o) ? Object.entries(o) : [];
const propertyDescriptors = (o) => isdef(o) ? Object.getOwnPropertyDescriptors(o) : [];
const propertyNames = (o) => isdef(o) ? Object.getOwnPropertyNames(o) : [];
const properties = (o) => map(propertyNames(o), (k) => [k, o[k]]);
const getProperty = (o, k) => isdef(o) ? o[k] : undefined;

koraa avatar Apr 30 '21 18:04 koraa