adobe / ferrum

Features from the rust language in javascript: Provides Traits/Type classes & a hashing infrastructure and an advanced library for working with sequences/iterators in js
https://www.ferrumjs.org
Apache License 2.0
519 stars 25 forks source link

null/undefined safe ways of working with properties & entries #182

Open koraa opened 3 years ago

koraa commented 3 years ago

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;