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.
Safely select arbitrarily nested nullable fields (with strong types).
import { select } from "pselect";
const foo = {};
const baz = select(foo, p => p.bar.baz); // No Error!
console.log(baz); // undefined
pselect uses the JavaScript Proxy
object and Reflect
ion to safely select the nullable field. If Proxy
support doesn't exist (ex: due to an old browser), if gracefully falls back to the less effiecient, but always available try-catch.
npm install pselect
select
takes in your subject and a selector function and returns the value or undefined
.
const select: <TObj, TResult>(
subject: TObj,
selector: (obj: TObj) => TResult
) => TResult;
Example:
import { select } from "pselect";
const foo = {};
const baz = select(foo, p => p.bar.baz); // No Error!
console.log(baz); // undefined
cselect
is the curried version of the select
function. It lets you write nice functional code that you can pipe and chain. (See example)
const cselect: <TObj, TResult>(
selector: (subject: TObj) => TResult
) => (subject: TObj) => TResult;
Examples:
import { cselect } from "pselect";
const foo = {};
const getBaz = p => p.bar.baz;
console.log(getBaz(foo)); // undefined
import { cselect } from "pselect";
interface IPerson {
name: string;
identification?: {
passport?: {
passportNumber: "111";
};
};
}
const getPerson = (id: number) => {
return people.find(...);
}
const passportNumber = pipe(
getPerson,
cselect(p => p.identification!.passport!.passportNumber),
passportNumber => passportNumber || "NO_PASSPORT"
);
const fred: IPerson = {
name: "fred"
};
passportNumber(fred); // NO_PASSPORT
MIT
FAQs
Safely resolve deeply nested nullable values with type-safety
We found that pselect 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.
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.