nice-try
Tries to execute a function and discards any error that occurs
Last updated 2 months ago by electerious .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install nice-try 
SYNC missed versions from official npm registry.

nice-try

Test

A function that tries to execute a function and discards any error that occurs.

Install

npm install nice-try

Usage

import niceTry from 'nice-try'

niceTry(() => JSON.parse('true')) // true
niceTry(() => JSON.parse('error')) // undefined
niceTry() // undefined
niceTry(true) // undefined
import niceTry from 'nice-try/promises'

await niceTry(async () => JSON.parse('true')) // true
await niceTry(async () => JSON.parse('error')) // undefined

API

nice-try

Parameters

  • fn {Function} The function to execute.

Returns

  • {any} The return value of the function, or undefined if an error occurred.

nice-try/promises

Parameters

  • fn {Function} An asynchronous function to execute.

Returns

  • {Promise<any>} The result of the function if it resolves successfully, otherwise undefined if an error is thrown.

What others say

This module is a controversial thing and people like to get mad about it. I decided to give those people a voice. Here's what they're saying.

fundamentally inane

— frou_dh

the worst Javascript library […] in several categories

— kuzux

how is this a thing

— uint8_t

This is blowing my mind

— mr_jim_lahey

a shit-tastic try-catch alias

— Dropping_fruits

I assumed every commit was a joke, but after researching the maintainer a bit I'm not sure it is...

— MrPineappleHat

Current Tags

  • 5.0.0                                ...           latest (2 months ago)

15 Versions

  • 5.0.0                                ...           2 months ago
  • 4.0.2                                ...           a year ago
  • 4.0.1                                ...           a year ago
  • 4.0.0                                ...           a year ago
  • 3.0.1                                ...           4 years ago
  • 3.0.0                                ...           6 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.1                                ...           7 years ago
  • 2.0.0                                ...           8 years ago
  • 1.0.5                                ...           8 years ago
  • 1.0.4                                ...           9 years ago
  • 1.0.3                                ...           9 years ago
  • 1.0.2                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 46
Today 0
This Week 0
This Month 19
Last Day 0
Last Week 4
Last Month 12
Dependencies (0)
None
Dev Dependencies (4)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE