A simple JavaScript function patcher.

Overview

spitroast

A very simple JavaScript monkeypatcher library that inserts your code in both ends.

Usage

// ESM
import * as spitroast from 'spitroast';

// CJS
const spitroast = require('spitroast');

// Deno / CDN
import * as spitroast from 'https://esm.sh/spitroast';

const exampleObject = { testFunction: () => {} };

// Patches that run before the original function
spitroast.before('testFunction', exampleObject, (args) => { // args is an array of arguments passed to the function
  console.log('Before');

  // You can return an array to replace the original arguments
}, false); // Change false to true to unpatch after the patch is first called!

exampleObject.testFunction(); // logs "Before"


// Patches that run after the original function
spitroast.after('testFunction', exampleObject, (args, response) => { // response is the return value of the function
  console.log('After');

  // You can return something to replace the original response
});

exampleObject.testFunction(); // logs "Before", then "After"


// Patches that replace the original function
const unpatch = spitroast.instead('testFunction', exampleObject, (args, originalFunction) => { // instead patches are passed the original function as the second argument
  console.log('Instead')
});

exampleObject.testFunction(); // logs "Instead" and nothing else

// Unpatches are as simple as running the return value of the patch function
unpatch();
// Now if you call the function it'll log "Before" and "After" again

// You can also unpatch every patch
spitroast.unpatchAll();

// Patches inherit context from the original function, you just have to use `this`
You might also like...

Some process handle JavaScript function parameter.

Function parameter handle or paremeter error control Example 1: Just checking if all arguments were passed / defined. const required = (name) = {

Mar 14, 2022

Vanilla javascript (ES6) function enabling drag scrolling on desktop

Drag-n-scroll also on desktop devices, by LCweb No dependencies vanilla javascript function to easily implement a nice drag-to-scroll effect using dse

Apr 5, 2022

A JavaScript Library that allows you to execute function when a certain element gets added to the document

wait-for-it.js A JavaScript Library that allows you to execute function when a certain element gets added to the document Getting Started If you want

Apr 26, 2022

⚖️ Limit an async function's concurrency with ease!

limit-concur Limit an async function's concurrency with ease! Install $ npm i limit-concur Usage import got from 'got' import limitConcur from 'limit-

Apr 8, 2022

An adapter where you can define which function to run

Switch Functions An adapter where you can define which function to run Installation This is a Node.js module available through the npm registry. Befor

Jun 17, 2022

This is an VanillaJS SPA example with function based rendering.

This is an VanillaJS SPA example with function based rendering.

Function-Based-Rendering This is an VanillaJS SPA example with function based rendering. Here's how to create Views by function composition and how to

Oct 16, 2021

Aergo Timer Service schedule smart contract function calls

Aergo Timer Service ⏰ Create timers to call functions on your smart contracts Schedule calls based on time interval or on specific date-times For a sm

Mar 10, 2022

A data-binding function for the DOM.

Alert: this library is now deprecated. s2 is its successor. It implements what simulacra does in a better way (using Proxy), and more. Simulacra.js Si

Nov 18, 2022

Avoid use of dangerouslySetInnerHTML with this lightweight (2KB) function.

Avoid use of dangerouslySetInnerHTML with this lightweight (2KB) function. Can parse HTML strings into VDom trees, ready to render in your Preact components

May 14, 2022
Comments
  • Add unit tests, fix deno + TS strangeness

    Add unit tests, fix deno + TS strangeness

    Adds unit testing via mocha and an action.

    npm i
    npm test
    

    Make sure to rebuild via prepublish before testing.

    Also fixes Deno "fixes" that broke typescript on everything else. I suggest instead of using the deno.land/x CDN to use cdn.esm.sh, which can simply bundle & minify the dist/esm from the npm package.

    - typescript fixing
    - add unit tests
    - add actions CI
    
    opened by yellowsink 0
  • Convert to TS, make code more minifier friendly in places

    Convert to TS, make code more minifier friendly in places

    Some size optimisations, for example instead of try { object.defineproperty } catch { cleanup }, you can use if (!reflect.defineproperty) { cleanup } which minifies down better.

    Also adds some comments and fixes (now) hook.ts:19 being completely broken before

    opened by yellowsink 0
Owner
A Discord mod for your Discord mod.
null
Tries to execute sync/async function, returns a specified default value if the function throws

good-try Tries to execute sync/async function, returns a specified default value if the function throws. Why Why not nice-try with it's 70+ million do

Antonio Stoilkov 14 Dec 8, 2022
Wrap a function with bun-livereload to automatically reload any imports inside the function the next time it is called

bun-livereload Wrap a function with bun-livereload to automatically reload any imports inside the function the next time it is called. import liveRelo

Jarred Sumner 19 Dec 19, 2022
A powerful simple JavaScript function-like toolset.

PrueEval PureEval 因 VoxelGeometry 项目而生,意在打造一个精巧而强大的 JavaScript 函数式工具包。 PureEval 具有以下特点: 具有独特的非变量绑定式 iterate 策略。 支持对任意参数已知函数函数的柯里化。 体积小、代码精简,嵌入成本极低。 Us

null 20 Dec 28, 2022
This simple project, show how work with async Fetch, function component and class component

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

DaliyaAsel 2 Feb 17, 2022
Interactive 3D plotting with a simple function call using Three.js

About Generate interactive 3d plots with a simple function call. Function returns a Three.js scene which can be customized as needed. Basic function c

Nathan Epstein 89 Oct 20, 2022
A simple Todo App with check complete function and filter todo. Made with React and TypeScript.

A simple Todo App with check complete function and filter todo. Made with React and TypeScript. The app can Add, Delete and Edit todo. Todo can be sorted by Complete or Active.

Bao Nguyen 9 Dec 6, 2022
Color palette generation function using hue cycling and simple easing functions.

Rampensau ?? Color palette generation function using hue cycling and easing functions. Check out a simple demo or see it in action over on farbvelo 10

David Aerne 24 Dec 28, 2022
A simple C++ function parser/tagger based on tree-sitter

What the func?! - A simple C++ function parser/tagger This project implements a simple C++ function parser, what-the-func, based on the tree-sitter C+

Software and Systems Engineering Chair 4 - Faculty of Informatics 3 May 21, 2022
A simple in-memory time-based cache for both objects and function execution.

What is this? A simple in-memory time-based cache for both objects and function execution. How do I install it? You can install it by using the follow

cadienvan 7 Dec 15, 2022
A simple in-memory key-value cache for function execution, allowing both sync and async operations using the same methods

A simple in-memory key-value cache for function execution, allowing both sync and async operations using the same methods. It provides an invalidation mechanism based both on exact string and regex.

cadienvan 10 Dec 15, 2022