try-to-catch

WebJar for try-to-catch

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

try-to-catch
Последняя версия

Последняя версия

1.1.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

try-to-catch
WebJar for try-to-catch
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/coderaiser/try-to-catch

Скачать try-to-catch

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/try-to-catch/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>try-to-catch</artifactId>
    <version>1.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/try-to-catch/
implementation 'org.webjars.npm:try-to-catch:1.1.1'
// https://jarcasting.com/artifacts/org.webjars.npm/try-to-catch/
implementation ("org.webjars.npm:try-to-catch:1.1.1")
'org.webjars.npm:try-to-catch:jar:1.1.1'
<dependency org="org.webjars.npm" name="try-to-catch" rev="1.1.1">
  <artifact name="try-to-catch" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='try-to-catch', version='1.1.1')
)
libraryDependencies += "org.webjars.npm" % "try-to-catch" % "1.1.1"
[org.webjars.npm/try-to-catch "1.1.1"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

Try to Catch NPM version Dependency Status Build Status Coverage Status

Functional try-catch wrapper for promises.

Install

npm i try-to-catch

API

tryToCatch(fn, [...args])

Wrap function to avoid try-catch block, resolves [error, result];

Example

Simplest example with async-await:

const tryToCatch = require('try-to-catch');
const reject = Promise.reject.bind(Promise);
await tryToCatch(reject, 'hi');
// returns
[ Error: hi]

Can be used with functions:

const tryToCatch = require('try-to-catch');
await tryToCatch(() => 5);
// returns
[null, 5]

Advanced example:

const {readFile, readdir} = require('fs').promises;
const tryToCatch = require('try-to-catch');

read(process.argv[2])
    .then(console.log)
    .catch(console.error);

async function read(path) {
    const [error, data] = await tryToCatch(readFile, path, 'utf8');
    
    if (!error)
        return data;
    
    if (error.code !== 'EISDIR')
        return error;
    
    return await readdir(path);
}

Related

License

MIT

Версии библиотеки

Версия
1.1.1