Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ls-proxy

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ls-proxy - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

57

lib/index.js

@@ -16,2 +16,27 @@ "use strict";

};
const shouldObjectProxy = (object) =>
// Check that the target isn't falsey (primarily in case it's null, since typeof null === 'object')
object &&
// Check type
typeof object === 'object' &&
// 'object' type includes some unwanted types, so check constructor
[Object, Array].includes(object.constructor);
/** Proxy handler for deeply nested objects on the main object */
const nestedProxyHandler = (parent, parentKey, nested, parentSet) => {
return new Proxy(nested, {
set(target, key, value) {
const setResult = Reflect.set(target, key, value);
// Trigger set trap of original object, updating localStorage
parentSet(parent, parentKey, target, parent);
return setResult;
},
get(target, key) {
if (shouldObjectProxy(target[key])) {
// Return a Proxy to the object to catch sets
return nestedProxyHandler(target, key, Reflect.get(target, key), this.set);
}
return Reflect.get(target, key);
},
});
};
/**

@@ -141,26 +166,2 @@ * Store a stringified JSON object in localStorage.

}
/** Proxy handler for deeply nested objects on the main object */
const nestedProxyHandler = (parent, parentKey, nested, parentSet) => {
return new Proxy(nested, {
set(target, key, value) {
const setResult = Reflect.set(target, key, value);
// Trigger set trap of original object, updating localStorage
parentSet(parent, parentKey, target, parent);
return setResult;
},
get(target, key) {
if (
// Check that the target isn't falsey (primarily in case it's null, since typeof null === 'object')
target[key] &&
// Check type
typeof target[key] === 'object' &&
// 'object' type includes arrays and other things, so check the constructor
target[key].constructor === Object) {
// Return a Proxy to the object to catch sets
return nestedProxyHandler(target, key, Reflect.get(target, key), this.set);
}
return Reflect.get(target, key);
},
});
};
/** Proxy handler for the main object */

@@ -188,9 +189,3 @@ const proxyHandler = {

}
if (
// Check that the target isn't falsey (primarily in case it's null, since typeof null === 'object')
target[key] &&
// Check type
typeof target[key] === 'object' &&
// 'object' type includes arrays and other things, so check the constructor
target[key].constructor === Object) {
if (shouldObjectProxy(target[key])) {
// Return a Proxy to the object to catch sets

@@ -197,0 +192,0 @@ return nestedProxyHandler(target, key, target[key], this.set);

{
"$schema": "https://json.schemastore.org/package",
"name": "ls-proxy",
"version": "0.3.0",
"version": "0.3.1",
"description": "Wrapper around localStorage to easily store JSON objects",

@@ -6,0 +6,0 @@ "repository": "https://gitlab.com/MysteryBlokHed/ls-proxy",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc