
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
try-typescript
Advanced tools
This repository implements a Try class inspired by the Vavr library in Java. The Try class is a functional programming construct for handling computations that may succeed or fail. It encapsulates exceptions and streamlines error handling, reducing boiler
This repository contains an implementation of the Try
class, inspired by the Vavr library in Java. The Try
class is a functional programming construct designed to handle computations that may result in success or failure. It allows developers to encapsulate exceptions and manage error handling in a more functional and expressive manner, reducing boilerplate code and improving code readability.
Success and Failure Handling: The implementation provides two subclasses, Success
and Failure
, to represent the result of computations. This makes it easy to handle both successful outcomes and exceptions gracefully.
Functional Methods: Includes a variety of methods that allow for functional transformations and error recovery:
map
and flatMap
.recover
and recoverWith
methods.filter
and execute side effects with onSuccess
and onFailure
.Option and Either Conversion: Convert the Try
results into Option
or Either
for seamless integration with other functional programming constructs.
Custom Exception Handling: Provides mechanisms to specify custom behavior for both success and failure cases, enabling tailored error handling strategies.
To use the Try
class, instantiate it with a computation that may fail, and utilize the available methods to handle the result. Below is an example of how to use the Try
class in TypeScript:
// Example of using the Try class
const result = new Try<number>(() => {
return 10 / 2; // Successful computation
});
result
.map(value => value * 2)
.onSuccess(value => console.log(`Success: ${value}`)) // Output: Success: 10
.onFailure(error => console.error(`Failed with error: ${error.message}`));
const failureResult = new Try<number>(() => {
throw new Error("Division by zero");
}).recover(() => 0);
console.log(failureResult.get()); // Output: 0
get
getOrElse
getOrElseGet
getOrElseThrow
isSuccess
isFailure
map
flatMap
recover
recoverWith
andThen
filter
onFailure
onSuccess
getCause
filterNot
peek
FAQs
This repository implements a Try class inspired by the Vavr library in Java. The Try class is a functional programming construct for handling computations that may succeed or fail. It encapsulates exceptions and streamlines error handling, reducing boiler
The npm package try-typescript receives a total of 0 weekly downloads. As such, try-typescript popularity was classified as not popular.
We found that try-typescript 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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.