
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
Patch and unpatch JavaScript functions multiple times, with the ability to remove patches in any order.
npm install patcharan
import { patch, unpatch } from 'patcharan';
const mod = {
greet(name) {
return `hello ${name}`;
},
};
// Define a patcher: receives the original and returns a wrapped version
const loud = (orig) => {
return function (...args) {
return orig.apply(this, args).toUpperCase();
};
};
patch(mod, 'greet', loud);
mod.greet('world'); // => "HELLO WORLD"
unpatch(mod, 'greet', loud);
mod.greet('world'); // => "hello world"
Multiple patches can be applied to the same function. Each patch wraps the result of the previous one. When a patch is removed with unpatch, the remaining patches are re-applied in order so the function stays consistent.
const logger = (orig) =>
function (...args) {
console.log('called with', args);
return orig.apply(this, args);
};
const timer = (orig) =>
function (...args) {
const start = performance.now();
const result = orig.apply(this, args);
console.log(`took ${performance.now() - start}ms`);
return result;
};
patch(mod, 'greet', logger);
patch(mod, 'greet', timer);
// Remove logger while keeping timer
unpatch(mod, 'greet', logger);
patch(obj, name, patcher)Wraps obj[name] with the function returned by patcher.
(original) => replacement — receives the current function and must return the replacementunpatch(obj, name, patcher)Removes a previously applied patcher and rebuilds obj[name] from the remaining patches.
Arguments are the same as patch.
FAQs
patch/unpatch JavaScript functions multiple times easily
The npm package patcharan receives a total of 218 weekly downloads. As such, patcharan popularity was classified as not popular.
We found that patcharan demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.