@branch/optionify

v0.0.3
Easily create type-safe options from an array of objects.

Optionify

Easily create type-safe options from an array of objects.

Turn this:

const users = [
  {
    name: "John",
    id: 3,
  },
];

const options = users.map((user) => ({
  label: user.name,
  value: user.id,
}));

return <Select options={options} />;

Into this:

import { optionify } from '@branch/optionify'

const users = [
  {
    name: "John",
    id: 3,
  },
];

const options = optionify(users, "name", "id");

return <Select options={options} />;
npm i @branch/optionify

Metadata

  • MIT
  • Whatever
  • Unknown
  • released 5/4/2023

Downloads

Maintainers