Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Available now
pnpm add @ollierelph/result4t
or pnpm add result4t
result4t
takes some pointers from the wonderful result4k
It's a replacement for Promise
that gives us a strongly-typed error mode.
import fs from "node:fs";
const readFileAndReverse = () =>
fs
.readFile("./boom.txt")
.then((contents) => contents.split("\n").reverse().join("\n"));
readFileAndReverse()
.then((reversedFile) => {
console.log(reversedFile);
process.exit(0);
})
.catch((error: unknown) => {
console.error(error);
process.exit(1);
});
in result4t
:
import fs from "node:fs";
import { TaskResult } from "./TaskResult";
const readFileAndReverse = () =>
TaskResult.ofPromise(
() => fs.readFile("./boom.txt"),
(err: unknown) => new Error("Unable to find file"),
).map((contents) => contents.split("\n").reverse().join("\n"));
readFileAndReverse()
.peek((reversedFile) => {
console.log(reversedFile);
process.exit(0);
})
.peekLeft((error) => {
// ^--- typed as Error
console.error(error);
process.exit(1);
})
.run();
FAQs
result4t
We found that result4t demonstrated a not healthy version release cadence and project activity because the last version was released 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.