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

1.3.0 • Public • Published

Attempt

Replaces lodash.get with a similar API while also providing additional features.

Why?

Lodash is an amazing utility however it's quite bloated, even its modularized version.

This module has around 0.2kb while lodash.get has 27kb.

Remember that size is really important in our serverless world 🚀

API

attempt(getter, fallback)

  • getter: A function which returns the value we want or executes another function
  • fallback: Fallback value in case getter throws or returns undefined. If typeof fallback === 'function' then it will execute it.

Usage

Retrieving data based on a given path:

const data = attempt(() => response.items[2].payload)
const dataWithFallback = attempt(() => response.items[2].payload, null)

Readme

Keywords

none

Package Sidebar

Install

npm i @new10com/attempt

Weekly Downloads

345

Version

1.3.0

License

none

Unpacked Size

4.27 kB

Total Files

6

Last publish

Collaborators

  • bruno-force
  • yaminihundare
  • karanew10
  • nizami.mursudlu
  • jazzlikefruit
  • jr_new10
  • maxvandermeij
  • canassa
  • aminnew10
  • eflorko
  • halfstack
  • elmarw_new10
  • douaa_hasan
  • aleksandranew10
  • daan.rotman
  • lcssvieira
  • nus.new10
  • kamil-new10
  • bartnew10
  • mykola.martynenko
  • dirkagterhuis.new10
  • nisaaa
  • new10admin
  • rictorres
  • keesonew10
  • sean6bucks
  • git-robot
  • hansregeer
  • virayavorska
  • malnakib
  • romulogmp
  • tomaszzbrozeknew10