Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
[What is `pipe`?](https://dev.to/benlesh/a-simple-explanation-of-functional-pipe-in-javascript-2hbj)
yarn add pipe-ts
npm install pipe-ts
pipe
Create a new function which pipes its value through the list functions.
const add1 = (n: number) => n + 1;
const times2 = (n: number) => n * 2;
const add1ThenTimes2 = pipe(
add1,
times2,
);
const result: number = add1ThenTimes2(1);
assert.strictEqual(result, 4);
Allows first function to have any number of parameters (0+), thanks to TypeScript's generic rest parameters
// First function has multiple parameters
const difference = (a: number, b: number) => a - b;
const add1 = (n: number) => n + 1;
const differenceThenAdd1 = pipe(
difference,
add1,
);
const result: number = differenceThenAdd1(5, 4);
assert.strictEqual(result, 2);
// First function has 0 parameters
const getNumber = () => 1;
const add1 = (n: number) => n + 1;
const getNumberThenAdd1 = pipe(
getNumber,
add1,
);
const result: number = getNumberThenAdd1();
assert.strictEqual(result, 2);
pipeWith
Transform a value by piping it through the listed functions. Sugar syntax for pipe(f, g)(value)
.
const add1 = (n: number) => n + 1;
const times2 = (n: number) => n * 2;
const result: number = pipeWith(1, add1, times2);
assert.strictEqual(result, 4);
pipe
and pipeWith
currently support up to 9 functions. If need be, we are open to adding more overloads to increase this limit.
We are also open to adding an array overload, so any number of funtions can be passed.
this
mattersIf a function passed to pipe
or pipeWith
relies on a specific context of execution (this
), you cannot call it by passing the reference (point-free style).
Use an anonymous function instead.
Bad
pipeWith('foo', localStorage.getItem);
Good
pipeWith('foo', key => localStorage.getItem(key));
Also good
pipeWith('foo', localStorage.getItem.bind(localStorage)),
yarn
npm run start
FAQs
[What is `pipe`?](https://dev.to/benlesh/a-simple-explanation-of-functional-pipe-in-javascript-2hbj)
The npm package pipe-ts receives a total of 2,018 weekly downloads. As such, pipe-ts popularity was classified as popular.
We found that pipe-ts 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
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.