0.1.0 • Published 1 year ago

@spenserblack/that v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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