Skip to content

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

Open
@koraa

Description

@koraa

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;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions