New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

js-watcher

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-watcher

A JS watcher implementation for objects, arrays, literals

latest
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

JS Watcher

Overview

A JS watcher implementation for objects, arrays, literals

If you need to catch every change made on your JS variables, this library is for you.

Install

npm i js-watcher in your npm project directory.

The npm package is located here

Run

proxy = require('js-watcher')
a = {a:'1', b:[1,2,3]}
p = proxy.createProxy(a, { valueChangeCallback: () => {console.log('hello')} })
p.a = 2

Will print: hello

proxy = require('js-watcher')
b = {a:{o:[1,2,3]}}
x = proxy.createProxy(b, {}, (prev, next, path) => { console.log(prev + ' -> ' + next + '; path: ' + path)})
x.a.o[0] = -1

Will print: 1 -> -1; path: a.o[0]

If you want to prevent assignment of the same value to the object, you can use comparison in shouldComponentUpdate method.

proxy = require('js-watcher')
b = {a:{o:[1,2,3]}}
x = proxy.createProxy(b, {}, (prev, next, path) => { if(prev === next) return false; console.log('hello') })
x.a.o[0] = 1
x.a.o[0] = -1

Will print (once): hello

More

To test the implementation run: npm test

More examples on usage of this library is available at test/proxyTest.js file.

FAQs

Package last updated on 10 Feb 2019

Did you know?

Socket

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.

Install

Related posts