Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anduong96/try-nice
Make try/catch nicer
https://github.com/anduong96/try-nice
Last synced: about 1 month ago
JSON representation
Make try/catch nicer
- Host: GitHub
- URL: https://github.com/anduong96/try-nice
- Owner: anduong96
- License: mit
- Created: 2019-12-23T03:58:38.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T02:22:27.000Z (about 2 years ago)
- Last Synced: 2024-11-29T17:42:18.105Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 431 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# try-nice
[![build status](https://img.shields.io/travis/com/anduong96/try-nice.svg)](https://travis-ci.com/anduong96/try-nice)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![license](https://img.shields.io/github/license/anduong96/try-nice.svg)](LICENSE)
[![npm downloads](https://img.shields.io/npm/dt/try-nice.svg)](https://npm.im/try-nice)> Clean try/catch wrapper
## Table of Contents
* [Install](#install)
* [Usage](#usage)
* [Contributors](#contributors)
* [License](#license)## Install
[npm][]:
```sh
npm install try-nice
```[yarn][]:
```sh
yarn add try-nice
```## Usage
```js
var { tryNice } = require('try-nice')function getOne() {
return 1
}var [result] = tryNice(getOne)
// result === 1
```## Usage ES6
```js
import { tryNice } from 'try-nice'
const [result] = tryNice(() => 1)
//result === 1const getTwo = async () => 2
const [asyncResult] = await tryNice(getTwo)
// asyncResult === 2const getValue = async (value) => value
const [parameterizedResult] = await tryNice(getValue, 3)
// parameterizedResult === 3const getError = async () => {
throw new Error()
}const [emptyResult, error] = await tryNice(getError)
// emptyResult === undefined
// error instanceof Error
```## Usage Typescript
```js
import { tryNice } from 'try-nice'
const [result] = tryNice(() => 1)
//result === 1const getTwo = async (): number => 2
const [asyncResult] = await tryNice(getTwo)
// asyncResult === 2const getValue = async (value: string): string => value
const [parameterizedResult] = await tryNice(getValue, 3)
// parameterizedResult === 3const getError = async (): void => {
throw new Error()
}const [emptyResult, error] = await tryNice(getError)
// emptyResult === undefined
// error instanceof Error
```## Contributors
| Name |
| ------------ |
| **An Duong** |## License
[MIT](LICENSE) © An Duong
##
[npm]: https://www.npmjs.com/
[yarn]: https://yarnpkg.com/