0.1.5 • Published 4 years ago

nh-utils v0.1.5

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

This project contains the most used code tools in nata.house, it's a tree-shakeable lib.

nh-utils banner

Functions

to

To avoid problems with encapsulation and to make the code clean, is not good to use try catch statements, for this problem nata.house created a method called to.

So this statement

let result: Result | undefined = undefined;
try {
    result = await someMethodThatReturnsPromise();
} catch (error: Error) {
    throw error;
}

Become this

const [error, result] = await to(someMethodThatReturnsPromise());
if (error) {
  throw error;
}

toRequest

This function works almost like the to function, but is made for apisauce results. It checks if the result has a problem and it's status is not ok, if this condition matches, it's an error.

if (data.problem && !data.ok) {
  throw data;
}
return [undefined, data];
0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago