4.0.4 • Published 4 years ago

try-nice v4.0.4

Weekly downloads
144
License
MIT
Repository
-
Last release
4 years ago

try-nice

build status styled with prettier license npm downloads

Clean try/catch wrapper

Table of Contents

Install

npm:

npm install try-nice

yarn:

yarn add try-nice

Usage

var { tryNice } = require('try-nice')

function getOne() {
  return 1
}

var [result] = tryNice(getOne)
// result === 1

Usage ES6

import { tryNice } from 'try-nice'
const [result] = tryNice(() => 1)
//result === 1

const getTwo = async () => 2
const [asyncResult] = await tryNice(getTwo)
// asyncResult === 2

const getValue = async (value) => value
const [parameterizedResult] = await tryNice(getValue, 3)
// parameterizedResult === 3

const getError = async () => {
  throw new Error()
}

const [emptyResult, error] = await tryNice(getError)
// emptyResult === undefined
// error instanceof Error

Usage Typescript

import { tryNice } from 'try-nice'
const [result] = tryNice(() => 1)
//result === 1

const getTwo = async (): number => 2
const [asyncResult] = await tryNice(getTwo)
// asyncResult === 2

const getValue = async (value: string): string  => value
const [parameterizedResult] = await tryNice(getValue, 3)
// parameterizedResult === 3

const getError = async (): void => {
  throw new Error()
}

const [emptyResult, error] = await tryNice(getError)
// emptyResult === undefined
// error instanceof Error

Contributors

Name
An Duong

License

MIT © An Duong

4.0.4

4 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.0

5 years ago

3.0.0

5 years ago

2.1.4

5 years ago

2.1.2

5 years ago

2.1.3

5 years ago

2.1.1

5 years ago

2.0.3

6 years ago

2.0.4

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.0

6 years ago

1.0.11

6 years ago

1.0.7

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago