npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

deflectjs-engine

v0.1.7

Published

Make it easier to hook APIs and functions into javascript using DeflectJS API Hooking.

Downloads

15

Readme

DeflectJS API - Hooking

Make it easier to hook APIs and functions into javascript using DeflectJS API Hooking. If you want install it in node, please check our npm package deflectjs-engine.

Get started into DeflectJS Hooking Engine

Our example will show how to change the behavior of the console.log function using a replacement hook.

The console.log by default display a text parameter specified in log(str), thus let's change the real output to "Hooked: " + str. When an user call console.log(str) the string displayed should be "Hooked: " + str. After attach our hook, console.log("Test!") will give "Hooked: Test!" instead of "Test!".

Original output when calling console.log

Hooking the function console.log using DeflectJS Hooking Engine

var hookStruct; //Struct that contains our hook data.
var hookQueue = []; //Queue where our hook will be added.

//Function that will replace the current console.log
function hookedLog(text){
    return hookStruct.OriginalFunction("Hooked: " + text); 
}

//Creating the stub that will intercept calls for console.log
hookStruct = deflect_create_native_hook(console.log, hookedLog, DEFLECT_NATIVE_OVERWRITTEN_HOOK, console);

//Adding the hooks in the queue to be attached.
if (deflect_enqueue_hook(hookStruct, hookQueue) != DEFLECT_STATE_ENQUEUED){
    alert('Error!');
}

//Attaching all hooks in queue.
if (deflect_attach_hook(hookQueue) != DEFLECT_STATE_HOOKED){
    alert('Error!');
}

After hooking the console.log api, let's see what happens when you call it.

//Now, let's see what happens when call console.log
console.log("Test!");

And our result will be:

Unhooking the function console.log using DeflectJS Hooking Engine

if (deflect_detach_hook(hookQueue) == DEFLECT_STATE_UNHOOKED){
    alert('Successful unhooked!');
}

Compatibility of modern browsers

| Browser | Verified version | Supported features | |:---------------:|:-----------------:|:------------------:| | Google Chrome | v79.0.3945.88 | All features | | Mozilla Firefox | v71.0 | All features | | Opera | v65.0.3467.78 | All features | | Microsoft Edge | v20.10240.16384.0 | All features |

Malicious use of DeflectJS Hooking Engine

When a function is hooked its behavior changes and leads to different results than the application intended. Malicious use of hooks to exploit systems is discouraged and isn't our responsibility.

Wiki of DeflectJS Engine Hooking

Visit our wiki page and read our api sample.