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

proxserve

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proxserve - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

22

index.js

@@ -0,1 +1,8 @@

/**
* Copyright 2020 Noam Lin <noamlin@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
"use strict"

@@ -538,7 +545,12 @@

/**
* get the target matching the path from object
* @param {Proxy|Object} obj
* @param {String} path
* evaluate a long path and return the designated object and its referred property
* @param {Object} obj
* @param {String} path
* @returns {Object} - returns {object, property, value}
*/
static getPathTarget(obj, path) {
static evalPath(obj, path) {
if(path === '') {
return { object: obj, property: undefined, value: obj };
}
let segments = Proxserve.splitPath(path);

@@ -552,3 +564,3 @@ let i;

}
return obj[segments[i]]; //return last property. it can be undefined
return { object: obj, property: segments[i], value: obj[ segments[i] ] };
}

@@ -555,0 +567,0 @@

{
"name": "proxserve",
"version": "1.2.2",
"version": "1.2.3",
"description": "Proxy Observe on objects and properties changes",

@@ -5,0 +5,0 @@ "license": "Apache 2.0",

@@ -704,7 +704,9 @@ "use strict"

test('16. getPathTarget - get target property of object and path', (done) => {
test('16. evalPath - get target property of object and path', (done) => {
let proxy = new Proxserve(cloneDeep(testObject), {delay: 0});
proxy.on('change', function(changes) {
let obj = Proxserve.getPathTarget(this, changes[0].path);
expect(obj).toEqual('xyz');
let { object, property, value } = Proxserve.evalPath(this, changes[0].path);
expect(object === proxy.level1_2.level2_1.level3_1.arr2[2][2][1].deep).toBe(true);
expect(property).toEqual('deeper');
expect(value).toBe('xyz');
});

@@ -715,4 +717,6 @@ proxy.level1_2.level2_1.level3_1.arr2[2][2][1].deep.deeper = 'xyz';

proxy.level1_2.on('change', function(changes) {
let obj = Proxserve.getPathTarget(this, changes[0].path);
expect(obj).toEqual('asdf');
let { object, property, value } = Proxserve.evalPath(this, changes[0].path);
expect(object === proxy.level1_2.level2_1.level3_1.arr2[2][2][1].deep).toBe(true);
expect(property).toEqual('another');
expect(value).toBe('asdf');
});

@@ -723,5 +727,6 @@ proxy.level1_2.level2_1.level3_1.arr2[2][2][1].deep.another = 'asdf';

proxy.level1_2.level2_1.on('change', function(changes) {
let obj = Proxserve.getPathTarget(this, changes[0].path);
expect(obj).toEqual([0, {a: 'a'}]);
done();
let { object, property, value } = Proxserve.evalPath(this, changes[0].path);
expect(object === proxy.level1_2.level2_1.level3_1.arr2[2]).toBe(true);
expect(property).toEqual('2');
expect(value).toEqual([0, {a: 'a'}]);
});

@@ -732,4 +737,6 @@ proxy.level1_2.level2_1.level3_1.arr2[2][2] = [0, {a: 'a'}];

proxy.on('change', function(changes) {
let obj = Proxserve.getPathTarget(this, changes[0].path);
expect(obj).toEqual({});
let { object, property, value } = Proxserve.evalPath(this, changes[0].path);
expect(object === proxy).toBe(true);
expect(property).toEqual('a');
expect(value).toEqual({});
});

@@ -740,7 +747,15 @@ proxy.a = {};

proxy.on('change', function(changes) {
let obj = Proxserve.getPathTarget(this, changes[0].path);
expect(obj).toEqual('a');
let { object, property, value } = Proxserve.evalPath(this, changes[0].path);
expect(object === proxy.a).toBe(true);
expect(property).toEqual('a');
expect(value).toEqual('a');
});
proxy.a.a = 'a';
proxy.removeAllListeners();
let { object, property, value } = Proxserve.evalPath(proxy, '');
expect(object === proxy).toBe(true);
expect(property).toEqual(undefined);
expect(value).toEqual(proxy);
done();
});

@@ -752,4 +767,3 @@

if(changes.length === 3) {
let propValue = Proxserve.getPathTarget(this, changes[0].path);
proxy.level1_1.arr1[0] = 123; //immediate change should be insterted to next round event emiting
proxy.level1_1.arr1[0] = 123; //immediate change should be insterted to next round event emitting
expect(changes.length).toBe(3); //shouldn't have changed yet

@@ -756,0 +770,0 @@ expect(changes[0].value).toBe(17);

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