Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@aurelle/result
Advanced tools
A Typescript error handling library inspired by Rust's Result type.
There is a lot of those already, but this one aims to be simple and doesn't attempt to turn Typescript into a functional programming language.
I originally wrote this because I find error handling in Typescript absolutely terrible. Wrapping everything in try/catch blocks really isn't my thing.
If you plan to use this, I recommend you simply copy src/index.ts
into your project instead of installing this package, given how small it is.
import { Result, Ok, Err } from '@aurelle/result';
const divide = (a: number, b: number): Result<number, Error> {
if (b === 0) {
return Err(new Error('Division by zero'));
}
return Ok(a / b);
}
const result = divide(10, 2);
if (result.err) {
// handle error
return ;
}
// work with result
console.log(result.val);
const [divided, divisionErr] = divide(10, 2).split();
if (divisionErr) {
// handle error
return ;
}
// work with result
console.log(divided);
// throws if there is an error
const divided = divide(10, 2).unwrap();
console.log(divided);
It is possible to turn any existing function into a function that returns a Result
by using the resultify
utility:
import { readFileSync } from 'fs';
import { resultify } from '@aurelle/result';
const rfs = resultify(readFileSync);
const file = rfs('file.txt', 'utf8'); // Result<string, Error>
Note that resultify
also works with async functions. It will return a function that returns a Promise<Result<T, E>>
.
this
context issuesIf you need to use a method that relies on the this
context, you should call bind
appropriately or wrap the call in a lambda function.
FAQs
Simple error handling library inspired by Rust's Result type
The npm package @aurelle/result receives a total of 2 weekly downloads. As such, @aurelle/result popularity was classified as not popular.
We found that @aurelle/result demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.