New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-res

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-res - npm Package Compare versions

Comparing version

to
1.2.0

2

package.json
{
"name": "ts-res",
"version": "1.1.1",
"version": "1.2.0",
"description": "TypeScript Result",

@@ -5,0 +5,0 @@ "repository": "https://github.com/Slava-Ini/ts-result",

@@ -0,1 +1,3 @@

[![https://nodei.co/npm/ts-res.png?mini=true](https://nodei.co/npm/ts-res.png?mini=true)](https://www.npmjs.com/package/ts-res)
# ts-res

@@ -14,5 +16,5 @@

- Using npm - `npm install ts-result`
- Using yarn - `yarn add ts-result`
- Using pnpm - `pnpm add ts-result`
- Using npm - `npm install ts-res`
- Using yarn - `yarn add ts-res`
- Using pnpm - `pnpm add ts-res`

@@ -73,3 +75,3 @@ ## Result Type

- `else(callback: (error: E) => T)` - returns an unwrapped result or executes callback that returns back-up value which can be based on provided error
- `and(callback: (result: T) => void)` - handles a result in a callback while ignoring an error, doesn't return anything
- `and(callback: (result: T) => Result<T, E>)` - handles a result in a callback while ignoring an error, returns the result allowing for chaining

@@ -128,3 +130,3 @@ ```ts

return Err("Invalide status code");
return Err("Invalid status code");
}

@@ -194,1 +196,31 @@

```
- Use `and()` for handling http response data and chaining it with another method
```ts
type User = {
name: string;
age: number;
};
async function fetchUserData(): Promise<Result<User, Error>> {
const response = await fetch("https://api.example.com/user");
if (!response.ok) {
return Err(new Error("Failed to fetch user data"));
}
const data = await response.json();
return Ok(data);
}
const result = await fetchUserData();
result
.and((user) => {
console.log(user);
})
.else((error) => {
console.error(error);
});
```