@spenserblack/that
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

That

A small utility for mapping properties in JavaScript

Usage

import { prop as p, fn } from "@spenserblack/that";

// Mapping to properties
[foo, bar, baz].map(p("foo")); // Same as .map((item) => item.prop) or .map(({ prop }) => prop)

[1, 2, 3].map(fn("toString", 16)); // Same as .map((n) => n.toString(16))

Why?

  • When doing these types of simple mapping, thinking of the item's parameter name is unnecessary mental overhead
  • I wanted to play around with TypeScript
  • Laziness (= and > are so annoying to type!)

Inspiration

This Ruby syntax:

[1, 2, 3].map(&:to_s)  # equivalent to [1, 2, 3].map((n) => n.toString()) in JavaScript

Readme

Keywords

Package Sidebar

Install

npm i @spenserblack/that

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

3.38 kB

Total Files

5

Last publish

Collaborators

  • spenserblack