Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
chain-methods
Advanced tools
This module exposes a single function to transform a plain object into a class, where methods can be chained.
npm install chain-methods
const chainMethods = require('chain-methods');
const Path = chainMethods(require('path'));
const rootPath = new Path(__dirname);
const imagesPath = rootPath.join('dist/static/images');
// With `chainMethods`:
const stream = fs.createReadStream(imagesPath.join('foo.jpg').value);
This module was created for experimentation purposes. It works well for APIs like node's path and url modules, where the first argument of each function is consistent.
It makes code a little easier to read by avoiding this type of nesting:
const foo = obj.method1(obj.method2('bar'), 'baz');
The first argument of each method must be consistent.
const Calculator = chainMethods({
// Good:
add: (n1, n2) => n1 + n2,
subtract: (n1, n2) => n1 - n2,
// Bad:
operation(operationName, ...args) {
return this[operationName](...args);
},
});
const value = new Calculator(0)
.add(10)
.subtract(2)
// This line won't work because of the argument order of `operation`:
.operation('add', 20)
.value;
In the example above, the first argument of operation
is not the number being
operated on. It is inconsistent with add
and subtract
, so will not work in
chaining.
FAQs
Create a class to chain methods from an object.
The npm package chain-methods receives a total of 1 weekly downloads. As such, chain-methods popularity was classified as not popular.
We found that chain-methods 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 researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.