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.
@quanterall/lich
Advanced tools
Lich is a library for chaining computations in TypeScript. It's heavily inspired by the monadic structures in Haskell. In particular Maybe and Either.
Lich is a library for chaining computations in TypeScript. It's heavily inspired by the monadic structures in Haskell. In particular Maybe
and Either
.
The goal of lich is to improve flow, safety and reliability of your code.
Via npm:
$ npm install @quanterall/lich
Via yarn:
$ yarn add @quanterall/lich
Via html:
<script src="https://unpkg.com/@quanterall/lich@1.0.8/dist/index.web.js"></script>
and then use via Lich
like so:
<script>
const maybe = Lich.Just(10);
const either = Lich.Right("hello world");
</script>
Let's say you want to apply several functions to a string, but you only want to work with it, if it's not empty at the end of each one of them?
This is how you may go about it, using lich
:
import { Maybe, Just, Nothing } from "lich";
export function parseString(s: string): Maybe<string> {
return safeTrim(s)
.map((j) => j.toUpperCase())
.bind(removePs) // Maybe remove the 'p's in the text.
.bind(clearSpaces); // Maybe clear up the spaces.
}
function safeTrim(s: string): Maybe<string> {
const trimmed = s.trim();
if (trimmed.length === 0) return Nothing();
return Just(trimmed);
}
function removePs(s: string): Maybe<string> {
const res = s.replace(/p/g, "");
if (res.length === 0) return Nothing();
return Just(res);
}
function clearSpaces(s: string): Maybe<string> {
const res = s.replace(/ +/g, " ").trim(); // We want only one space between words
if (res.length === 0) return Nothing();
return Just(res);
}
If you care about in which step things went wrong you can use Either
to track your errors:
import { Either, Right, Left } from "lich";
export function parseString(s: string): Either<string, string> {
return safeTrim(s)
.map((j) => j.toUpperCase())
.bind(removePs) // Either remove the 'p's in the text or return a `Left` with a reason.
.bind(clearSpaces) // Either clear up the spaces or return `Left` with a reason.
.onLeft((l) => console.error(l)); // Log the error to the console
}
function safeTrim(s: string): Either<string, string> {
const trimmed = s.trim();
if (trimmed.length === 0) return Left("Error in 'safeTrim': String is empty");
return Right(trimmed);
}
function removePs(s: string): Either<string, string> {
const res = s.replace(/p/g, "");
if (res.length === 0) return Left("Error in 'removePs': String is empty");
return Right(res);
}
function clearSpaces(s: string): Either<string, string> {
const res = s.replace(/ +/g, " ").trim(); // We want only one space between words.
if (res.length === 0) return Left("Error in 'clearSpaces': String is empty");
return Right(res);
}
A more deep comparison against other error handling practices could be found here.
FAQs
Lich is a library for chaining computations in TypeScript. It's heavily inspired by the monadic structures in Haskell. In particular Maybe and Either.
The npm package @quanterall/lich receives a total of 14 weekly downloads. As such, @quanterall/lich popularity was classified as not popular.
We found that @quanterall/lich demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.