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

existential-proxy

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

existential-proxy - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

coverage/lcov-report/utils.ts.html

5

coverage/coverage-final.json

@@ -1,5 +0,6 @@

{"/Users/jake/code/existential-proxy/src/constants.ts": {"path":"/Users/jake/code/existential-proxy/src/constants.ts","statementMap":{"0":{"start":{"line":1,"column":13},"end":{"line":1,"column":63}}},"fnMap":{},"branchMap":{},"s":{"0":1},"f":{},"b":{}}
{"/Users/jake/code/existential-proxy/src/constants.ts": {"path":"/Users/jake/code/existential-proxy/src/constants.ts","statementMap":{"0":{"start":{"line":1,"column":13},"end":{"line":1,"column":63}},"1":{"start":{"line":2,"column":13},"end":{"line":2,"column":37}}},"fnMap":{},"branchMap":{},"s":{"0":3,"1":3},"f":{},"b":{}}
,"/Users/jake/code/existential-proxy/src/get.ts": {"path":"/Users/jake/code/existential-proxy/src/get.ts","statementMap":{"0":{"start":{"line":18,"column":26},"end":{"line":18,"column":31}},"1":{"start":{"line":20,"column":19},"end":{"line":30,"column":3}},"2":{"start":{"line":22,"column":6},"end":{"line":22,"column":32}},"3":{"start":{"line":24,"column":6},"end":{"line":26,"column":7}},"4":{"start":{"line":25,"column":8},"end":{"line":25,"column":49}},"5":{"start":{"line":28,"column":6},"end":{"line":28,"column":37}},"6":{"start":{"line":32,"column":16},"end":{"line":32,"column":58}},"7":{"start":{"line":34,"column":2},"end":{"line":34,"column":18}},"8":{"start":{"line":36,"column":2},"end":{"line":40,"column":3}},"9":{"start":{"line":37,"column":4},"end":{"line":39,"column":5}},"10":{"start":{"line":38,"column":6},"end":{"line":38,"column":26}},"11":{"start":{"line":42,"column":2},"end":{"line":42,"column":22}},"12":{"start":{"line":13,"column":0},"end":{"line":43,"column":1}}},"fnMap":{"0":{"name":"get","decl":{"start":{"line":13,"column":16},"end":{"line":13,"column":19}},"loc":{"start":{"line":16,"column":18},"end":{"line":43,"column":1}}}},"branchMap":{"0":{"loc":{"start":{"line":24,"column":6},"end":{"line":26,"column":7}},"type":"if","locations":[{"start":{"line":24,"column":6},"end":{"line":26,"column":7}},{"start":{"line":24,"column":6},"end":{"line":26,"column":7}}]},"1":{"loc":{"start":{"line":24,"column":10},"end":{"line":24,"column":22}},"type":"binary-expr","locations":[{"start":{"line":24,"column":10},"end":{"line":24,"column":22}},{"start":{"line":24,"column":26},"end":{"line":24,"column":58}}]},"2":{"loc":{"start":{"line":36,"column":2},"end":{"line":40,"column":3}},"type":"if","locations":[{"start":{"line":36,"column":2},"end":{"line":40,"column":3}},{"start":{"line":36,"column":2},"end":{"line":40,"column":3}}]},"3":{"loc":{"start":{"line":36,"column":6},"end":{"line":36,"column":41}},"type":"binary-expr","locations":[{"start":{"line":36,"column":6},"end":{"line":36,"column":41}},{"start":{"line":36,"column":45},"end":{"line":36,"column":66}}]},"4":{"loc":{"start":{"line":37,"column":4},"end":{"line":39,"column":5}},"type":"if","locations":[{"start":{"line":37,"column":4},"end":{"line":39,"column":5}},{"start":{"line":37,"column":4},"end":{"line":39,"column":5}}]}},"s":{"0":16,"1":16,"2":24,"3":24,"4":8,"5":16,"6":16,"7":16,"8":16,"9":8,"10":5,"11":11,"12":2},"f":{"0":16},"b":{"0":[8,16],"1":[24,9],"2":[8,8],"3":[16,9],"4":[5,3]}}
,"/Users/jake/code/existential-proxy/src/index.ts": {"path":"/Users/jake/code/existential-proxy/src/index.ts","statementMap":{"0":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},"1":{"start":{"line":1,"column":9},"end":{"line":1,"column":12}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":27}},"3":{"start":{"line":2,"column":9},"end":{"line":2,"column":12}}},"fnMap":{},"branchMap":{},"s":{"0":2,"1":2,"2":2,"3":2},"f":{},"b":{}}
,"/Users/jake/code/existential-proxy/src/set.ts": {"path":"/Users/jake/code/existential-proxy/src/set.ts","statementMap":{"0":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}},"1":{"start":{"line":5,"column":4},"end":{"line":5,"column":20}},"2":{"start":{"line":8,"column":34},"end":{"line":8,"column":38}},"3":{"start":{"line":9,"column":14},"end":{"line":11,"column":14}},"4":{"start":{"line":14,"column":2},"end":{"line":18,"column":3}},"5":{"start":{"line":15,"column":4},"end":{"line":15,"column":45}},"6":{"start":{"line":17,"column":4},"end":{"line":17,"column":69}},"7":{"start":{"line":20,"column":2},"end":{"line":20,"column":51}},"8":{"start":{"line":22,"column":2},"end":{"line":22,"column":14}},"9":{"start":{"line":3,"column":0},"end":{"line":23,"column":1}},"10":{"start":{"line":30,"column":25},"end":{"line":30,"column":27}},"11":{"start":{"line":32,"column":19},"end":{"line":38,"column":3}},"12":{"start":{"line":34,"column":6},"end":{"line":34,"column":21}},"13":{"start":{"line":36,"column":6},"end":{"line":36,"column":37}},"14":{"start":{"line":40,"column":16},"end":{"line":40,"column":55}},"15":{"start":{"line":42,"column":2},"end":{"line":42,"column":18}},"16":{"start":{"line":44,"column":2},"end":{"line":44,"column":38}},"17":{"start":{"line":25,"column":0},"end":{"line":45,"column":1}}},"fnMap":{"0":{"name":"setIn","decl":{"start":{"line":3,"column":16},"end":{"line":3,"column":21}},"loc":{"start":{"line":3,"column":76},"end":{"line":23,"column":1}}},"1":{"name":"set","decl":{"start":{"line":25,"column":16},"end":{"line":25,"column":19}},"loc":{"start":{"line":28,"column":13},"end":{"line":45,"column":1}}}},"branchMap":{"0":{"loc":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}},"type":"if","locations":[{"start":{"line":4,"column":2},"end":{"line":6,"column":3}},{"start":{"line":4,"column":2},"end":{"line":6,"column":3}}]},"1":{"loc":{"start":{"line":10,"column":6},"end":{"line":10,"column":26}},"type":"cond-expr","locations":[{"start":{"line":10,"column":6},"end":{"line":10,"column":26}},{"start":{"line":11,"column":6},"end":{"line":11,"column":14}}]},"2":{"loc":{"start":{"line":14,"column":2},"end":{"line":18,"column":3}},"type":"if","locations":[{"start":{"line":14,"column":2},"end":{"line":18,"column":3}},{"start":{"line":14,"column":2},"end":{"line":18,"column":3}}]},"3":{"loc":{"start":{"line":14,"column":6},"end":{"line":14,"column":20}},"type":"binary-expr","locations":[{"start":{"line":14,"column":6},"end":{"line":14,"column":20}},{"start":{"line":14,"column":24},"end":{"line":14,"column":52}}]},"4":{"loc":{"start":{"line":15,"column":37},"end":{"line":15,"column":39}},"type":"cond-expr","locations":[{"start":{"line":15,"column":37},"end":{"line":15,"column":39}},{"start":{"line":15,"column":42},"end":{"line":15,"column":44}}]},"5":{"loc":{"start":{"line":17,"column":34},"end":{"line":17,"column":44}},"type":"cond-expr","locations":[{"start":{"line":17,"column":34},"end":{"line":17,"column":44}},{"start":{"line":17,"column":46},"end":{"line":17,"column":68}}]}},"s":{"0":42,"1":14,"2":28,"3":28,"4":28,"5":10,"6":18,"7":28,"8":28,"9":2,"10":14,"11":14,"12":28,"13":28,"14":14,"15":14,"16":14,"17":2},"f":{"0":42,"1":14},"b":{"0":[14,28],"1":[14,14],"2":[10,18],"3":[28,26],"4":[7,3],"5":[5,13]}}
,"/Users/jake/code/existential-proxy/src/set.ts": {"path":"/Users/jake/code/existential-proxy/src/set.ts","statementMap":{"0":{"start":{"line":2,"column":0},"end":{"line":2,"column":31}},"1":{"start":{"line":9,"column":25},"end":{"line":9,"column":27}},"2":{"start":{"line":11,"column":19},"end":{"line":17,"column":3}},"3":{"start":{"line":13,"column":6},"end":{"line":13,"column":21}},"4":{"start":{"line":15,"column":6},"end":{"line":15,"column":37}},"5":{"start":{"line":19,"column":16},"end":{"line":19,"column":55}},"6":{"start":{"line":21,"column":2},"end":{"line":21,"column":18}},"7":{"start":{"line":23,"column":2},"end":{"line":23,"column":38}},"8":{"start":{"line":4,"column":0},"end":{"line":24,"column":1}}},"fnMap":{"0":{"name":"set","decl":{"start":{"line":4,"column":16},"end":{"line":4,"column":19}},"loc":{"start":{"line":7,"column":13},"end":{"line":24,"column":1}}}},"branchMap":{},"s":{"0":2,"1":14,"2":14,"3":28,"4":28,"5":14,"6":14,"7":14,"8":2},"f":{"0":14},"b":{}}
,"/Users/jake/code/existential-proxy/src/utils.ts": {"path":"/Users/jake/code/existential-proxy/src/utils.ts","statementMap":{"0":{"start":{"line":1,"column":0},"end":{"line":1,"column":41}},"1":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}},"2":{"start":{"line":5,"column":4},"end":{"line":5,"column":20}},"3":{"start":{"line":8,"column":34},"end":{"line":8,"column":38}},"4":{"start":{"line":9,"column":14},"end":{"line":9,"column":74}},"5":{"start":{"line":12,"column":2},"end":{"line":16,"column":3}},"6":{"start":{"line":13,"column":4},"end":{"line":13,"column":45}},"7":{"start":{"line":15,"column":4},"end":{"line":15,"column":69}},"8":{"start":{"line":18,"column":2},"end":{"line":18,"column":51}},"9":{"start":{"line":20,"column":2},"end":{"line":20,"column":14}},"10":{"start":{"line":3,"column":0},"end":{"line":21,"column":1}}},"fnMap":{"0":{"name":"setIn","decl":{"start":{"line":3,"column":16},"end":{"line":3,"column":21}},"loc":{"start":{"line":3,"column":76},"end":{"line":21,"column":1}}}},"branchMap":{"0":{"loc":{"start":{"line":4,"column":2},"end":{"line":6,"column":3}},"type":"if","locations":[{"start":{"line":4,"column":2},"end":{"line":6,"column":3}},{"start":{"line":4,"column":2},"end":{"line":6,"column":3}}]},"1":{"loc":{"start":{"line":9,"column":43},"end":{"line":9,"column":63}},"type":"cond-expr","locations":[{"start":{"line":9,"column":43},"end":{"line":9,"column":63}},{"start":{"line":9,"column":66},"end":{"line":9,"column":74}}]},"2":{"loc":{"start":{"line":12,"column":2},"end":{"line":16,"column":3}},"type":"if","locations":[{"start":{"line":12,"column":2},"end":{"line":16,"column":3}},{"start":{"line":12,"column":2},"end":{"line":16,"column":3}}]},"3":{"loc":{"start":{"line":12,"column":6},"end":{"line":12,"column":20}},"type":"binary-expr","locations":[{"start":{"line":12,"column":6},"end":{"line":12,"column":20}},{"start":{"line":12,"column":24},"end":{"line":12,"column":52}}]},"4":{"loc":{"start":{"line":13,"column":37},"end":{"line":13,"column":39}},"type":"cond-expr","locations":[{"start":{"line":13,"column":37},"end":{"line":13,"column":39}},{"start":{"line":13,"column":42},"end":{"line":13,"column":44}}]},"5":{"loc":{"start":{"line":15,"column":34},"end":{"line":15,"column":44}},"type":"cond-expr","locations":[{"start":{"line":15,"column":34},"end":{"line":15,"column":44}},{"start":{"line":15,"column":46},"end":{"line":15,"column":68}}]}},"s":{"0":2,"1":42,"2":14,"3":28,"4":28,"5":28,"6":10,"7":18,"8":28,"9":28,"10":2},"f":{"0":42},"b":{"0":[14,28],"1":[14,14],"2":[10,18],"3":[28,26],"4":[7,3],"5":[5,13]}}
}

52

dist/index.js

@@ -7,2 +7,3 @@ "use strict";

exports.MAGIC_PROXY_SYMBOL = Symbol('Magic proxy symbol');
exports.MATCHES_INT = /^-?\d+$/;
"use strict";

@@ -60,23 +61,4 @@

function setIn(input, keys, newValue) {
if (!keys.length) {
return newValue;
}
const utils_1 = require("./utils");
const [firstKey, ...restKeys] = keys;
const key = Number.isFinite(parseFloat(firstKey)) ? parseFloat(firstKey) : firstKey;
let copy;
if (input === null || typeof input === 'undefined') {
copy = typeof key === 'number' ? [] : {};
} else {
copy = Array.isArray(input) ? [...input] : Object.assign({}, input);
}
copy[key] = setIn(copy[key], restKeys, newValue);
return copy;
}
exports.setIn = setIn;
function set(input, callback, newValue) {

@@ -93,3 +75,3 @@ const keys = [];

callback(proxy);
return setIn(input, keys, newValue);
return utils_1.setIn(input, keys, newValue);
}

@@ -105,3 +87,31 @@

const constants_1 = require("./constants");
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const constants_1 = require("./constants");
function setIn(input, keys, newValue) {
if (!keys.length) {
return newValue;
}
const [firstKey, ...restKeys] = keys;
const key = constants_1.MATCHES_INT.test(firstKey) ? parseFloat(firstKey) : firstKey;
let copy;
if (input === null || typeof input === 'undefined') {
copy = typeof key === 'number' ? [] : {};
} else {
copy = Array.isArray(input) ? [...input] : Object.assign({}, input);
}
copy[key] = setIn(copy[key], restKeys, newValue);
return copy;
}
exports.setIn = setIn;
//# sourceMappingURL=index.js.map

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MAGIC_PROXY_SYMBOL=Symbol("Magic proxy symbol");
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MAGIC_PROXY_SYMBOL=Symbol("Magic proxy symbol"),exports.MATCHES_INT=/^-?\d+$/;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});function get(a,b,c){let d=a;const e={get(a,b){return d=a[b],d&&"object"==typeof d?new Proxy(d,e):new Proxy({},e)}},f=new Proxy(a,e);return b(f),("undefined"==typeof d||null===d)&&"undefined"!=typeof c?c:d}exports.get=get;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var get_1=require("./get");exports.get=get_1.get;var set_1=require("./set");exports.set=set_1.set;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});function setIn(a,b,c){var d=Number.isFinite;if(!b.length)return c;const[e,...f]=b,g=d(parseFloat(e))?parseFloat(e):e;let h;return h=null===a||"undefined"==typeof a?"number"==typeof g?[]:{}:Array.isArray(a)?[...a]:Object.assign({},a),h[g]=setIn(h[g],f,c),h}exports.setIn=setIn;function set(a,b,c){const d=[],e={get(a,b){return d.push(b),new Proxy({},e)}},f=new Proxy({},e);return b(f),setIn(a,d,c)}exports.set=set;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const utils_1=require("./utils");function set(a,b,c){const d=[],e={get(a,b){return d.push(b),new Proxy({},e)}},f=new Proxy({},e);return b(f),utils_1.setIn(a,d,c)}exports.set=set;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const constants_1=require("./constants");
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const constants_1=require("./constants");function setIn(a,b,c){if(!b.length)return c;const[d,...e]=b,f=constants_1.MATCHES_INT.test(d)?parseFloat(d):d;let g;return g=null===a||"undefined"==typeof a?"number"==typeof f?[]:{}:Array.isArray(a)?[...a]:Object.assign({},a),g[f]=setIn(g[f],e,c),g}exports.setIn=setIn;
//# sourceMappingURL=index.min.js.map
export declare const MAGIC_PROXY_SYMBOL: unique symbol;
export declare const MATCHES_INT: RegExp;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MAGIC_PROXY_SYMBOL = Symbol('Magic proxy symbol');
exports.MATCHES_INT = /^-?\d+$/;
//# sourceMappingURL=constants.js.map
import { WithProxy } from './types';
export declare function setIn(input: any, keys: ReadonlyArray<string>, newValue: any): any;
export declare function set<T extends object, R>(input: T, callback: (input: WithProxy<T>) => WithProxy<R>, newValue: R): T;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function setIn(input, keys, newValue) {
if (!keys.length) {
return newValue;
}
const [firstKey, ...restKeys] = keys;
const key = Number.isFinite(parseFloat(firstKey))
? parseFloat(firstKey)
: firstKey;
let copy;
if (input === null || typeof input === 'undefined') {
copy = typeof key === 'number' ? [] : {};
}
else {
copy = Array.isArray(input) ? [...input] : Object.assign({}, input);
}
copy[key] = setIn(copy[key], restKeys, newValue);
return copy;
}
exports.setIn = setIn;
const utils_1 = require("./utils");
function set(input, callback, newValue) {

@@ -32,5 +14,5 @@ const keys = [];

callback(proxy);
return setIn(input, keys, newValue);
return utils_1.setIn(input, keys, newValue);
}
exports.set = set;
//# sourceMappingURL=set.js.map
{
"name": "existential-proxy",
"version": "0.0.3",
"version": "0.0.4",
"description": "Type safe existential property access using ES6 proxies",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -92,3 +92,3 @@ # existential-proxy

1. The return type will always match the input type - if keys are nullable, they will still be nullable even if set by this function
2. Keys that when cast to a number are finite numbers will produce arrays if the parent object is undefined or null. This is because there is no way to detect if trying to access values from an array or object if the target is undefined or null (all keys; `.a`, `[0]`, are only available as strings when using a proxy).
2. Keys that when cast to a number are a valid integer (including negative values) will produce arrays if the parent object is undefined or null. This is because there is no way to detect if trying to access values from an array or object if the target is undefined or null (all keys; `.a`, `[0]`, are only available as strings when using a proxy).

@@ -104,3 +104,3 @@ ```typescript

This library's `set` function may not give you the output you'd expect if you are using numbers as keys in objects.
This library's `set` function may not give you the output you'd expect if you are using integers as keys in objects.

@@ -107,0 +107,0 @@ ```typescript

export const MAGIC_PROXY_SYMBOL = Symbol('Magic proxy symbol');
export const MATCHES_INT = /^-?\d+$/;
import { WithProxy } from './types';
import { setIn } from './utils';
export function setIn(input: any, keys: ReadonlyArray<string>, newValue: any) {
if (!keys.length) {
return newValue;
}
const [firstKey, ...restKeys] = keys;
const key = Number.isFinite(parseFloat(firstKey))
? parseFloat(firstKey)
: firstKey;
let copy: any;
if (input === null || typeof input === 'undefined') {
copy = typeof key === 'number' ? [] : {};
} else {
copy = Array.isArray(input) ? [...input] : { ...(input as any) };
}
copy[key] = setIn(copy[key], restKeys, newValue);
return copy;
}
export function set<T extends object, R>(

@@ -26,0 +5,0 @@ input: T,

import * as CONSTANTS from '../src/constants';
describe('constants', () => {
it('should export a single symbol', () => {
expect(Object.keys(CONSTANTS)).toEqual(['MAGIC_PROXY_SYMBOL']);
it('should export some constants', () => {
expect(Object.keys(CONSTANTS)).toEqual(['MAGIC_PROXY_SYMBOL', 'MATCHES_INT']);
expect(typeof CONSTANTS.MAGIC_PROXY_SYMBOL).toBe('symbol');
expect(CONSTANTS.MATCHES_INT instanceof RegExp).toBe(true);
});
describe('MATCHES_INT', () => {
it('should test for strings that represent valid integers', () => {
expect(CONSTANTS.MATCHES_INT.test('')).toBe(false);
expect(CONSTANTS.MATCHES_INT.test('0.1')).toBe(false);
expect(CONSTANTS.MATCHES_INT.test('-0.1')).toBe(false);
expect(CONSTANTS.MATCHES_INT.test('1a')).toBe(false);
expect(CONSTANTS.MATCHES_INT.test('a1')).toBe(false);
expect(CONSTANTS.MATCHES_INT.test(' 1')).toBe(false);
expect(CONSTANTS.MATCHES_INT.test('1 ')).toBe(false);
expect(CONSTANTS.MATCHES_INT.test('1')).toBe(true);
expect(CONSTANTS.MATCHES_INT.test('-1')).toBe(true);
expect(CONSTANTS.MATCHES_INT.test('123')).toBe(true);
expect(CONSTANTS.MATCHES_INT.test('-123')).toBe(true);
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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