electerious / nice-try

Tries to execute a function and discards any error that occurs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why?

funnbot opened this issue · comments

Why would anyone use this?

I'm using it to require optional dependencies.

const path = require('path')
const niceTry = require('nice-try')
const junk = require('junk')
const browserSync = niceTry(() => require('browser-sync'))
const cache = require('./cache')

instead of

const path = require('path')
const niceTry = require('nice-try')
const junk = require('junk')
let browserSync
try { browserSync = require('browser-sync') }
catch (e) {}
const cache = require('./cache')

¯\(ツ)