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

@teamawesome/access

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teamawesome/access - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

access.d.ts

0

.eslintrc.js

@@ -0,0 +0,0 @@ module.exports = {

53

dist/access.js
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = exports.types = void 0;
var types = new Map();
/**
* Call a method on the object's proxy or the object itself
*
* @param {*} obj
* @param {string} method
* @param {*} [key]
* @param {*} [value]
*/
exports.default = void 0;
exports.types = types;
var _call = require("./call");
function call(obj, method, key, value) {
var proxy = types.get(obj.constructor);
var _types = _interopRequireDefault(require("./types"));
if (proxy !== undefined && typeof proxy[method] === 'function') {
return proxy[method](obj, key, value);
}
if (typeof obj[method] === 'function') {
return obj[method](key, value);
}
throw new TypeError("No [".concat(method, "] handler for objects of type [").concat(obj.constructor.name, "]"));
}
var _default = {

@@ -42,3 +23,3 @@ /**

get: function get(obj, key) {
return call(obj, 'get', key);
return (0, _call.call1)(obj, 'get', key);
},

@@ -56,3 +37,3 @@

set: function set(obj, key, value) {
call(obj, 'set', key, value);
(0, _call.call2)(obj, 'set', key, value);
return obj;

@@ -69,3 +50,3 @@ },

has: function has(obj, key) {
return call(obj, 'has', key);
return (0, _call.call1)(obj, 'has', key);
},

@@ -80,4 +61,4 @@

*/
"delete": function _delete(obj, key) {
return call(obj, 'delete', key);
delete: function _delete(obj, key) {
return (0, _call.call1)(obj, 'delete', key);
},

@@ -91,3 +72,3 @@

clear: function clear(obj) {
call(obj, 'clear');
(0, _call.call0)(obj, 'clear');
},

@@ -102,3 +83,3 @@

keys: function keys(obj) {
return call(obj, 'keys');
return (0, _call.call0)(obj, 'keys');
},

@@ -113,3 +94,3 @@

values: function values(obj) {
return call(obj, 'values');
return (0, _call.call0)(obj, 'values');
},

@@ -124,3 +105,3 @@

entries: function entries(obj) {
return call(obj, 'entries');
return (0, _call.call0)(obj, 'entries');
},

@@ -135,3 +116,3 @@

register: function register(type, proxy) {
types.set(type, proxy);
_types.default.set(type, proxy);
},

@@ -145,5 +126,5 @@

unregister: function unregister(type) {
types["delete"](type);
_types.default.delete(type);
}
};
exports["default"] = _default;
exports.default = _default;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _access = _interopRequireDefault(require("./access"));
_access["default"].register(Array, {
_access.default.register(Array, {
get: function get(obj, key) {

@@ -17,3 +17,3 @@ return obj[key];

},
"delete": function _delete(obj, key) {
delete: function _delete(obj, key) {
return obj.splice(key, 1).length === 1;

@@ -20,0 +20,0 @@ },

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

@@ -11,9 +11,15 @@ Object.defineProperty(exports, "__esModule", {

get: function get() {
return _access["default"];
return _access.default;
}
});
Object.defineProperty(exports, "access", {
enumerable: true,
get: function get() {
return _access.default;
}
});
Object.defineProperty(exports, "types", {
enumerable: true,
get: function get() {
return _access.types;
return _types.default;
}

@@ -28,2 +34,4 @@ });

var _access = _interopRequireWildcard(require("./access"));
var _access = _interopRequireDefault(require("./access"));
var _types = _interopRequireDefault(require("./types"));
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

@@ -9,3 +9,3 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var proxy = (0, _defineProperty2["default"])({
var proxy = (0, _defineProperty2.default)({
get: function get(obj, key) {

@@ -20,3 +20,3 @@ return obj[key];

},
"delete": function _delete(obj, key) {
delete: function _delete(obj, key) {
return key in obj && delete obj[key];

@@ -42,5 +42,3 @@ },

_access["default"].register(Object, proxy); // Objects created without a prototype do not have a constructor
_access["default"].register(undefined, proxy);
_access.default.register(Object, proxy); // Objects created without a prototype do not have a constructor
// access.register(undefined, proxy);
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

@@ -9,3 +9,3 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var proxy = (0, _defineProperty2["default"])({
var proxy = (0, _defineProperty2.default)({
get: function get(obj, key) {

@@ -20,3 +20,3 @@ return obj.getItem(key);

},
"delete": function _delete(obj, key) {
delete: function _delete(obj, key) {
return obj.getItem(key) === null && obj.removeItem(key) === undefined;

@@ -42,4 +42,4 @@ },

if (typeof window !== 'undefined' && typeof window.Storage !== 'undefined') {
_access["default"].register(window.Storage, proxy);
_access.default.register(window.Storage, proxy);
}
/* eslint-enable no-undef */
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;

@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", {

});
exports["default"] = wrap;
exports.default = wrap;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _access = require("./access");
var _types = _interopRequireDefault(require("./types"));

@@ -21,3 +21,3 @@ /**

function get(obj, method) {
var proxy = _access.types.get(obj.constructor);
var proxy = _types.default.get(obj.constructor);

@@ -45,3 +45,3 @@ if (proxy !== undefined && typeof proxy[method] === 'function') {

var wrapped = (0, _defineProperty2["default"])({
var wrapped = (0, _defineProperty2.default)({
constructor: wrap,

@@ -55,3 +55,3 @@ get: get(obj, 'get'),

has: get(obj, 'has'),
"delete": get(obj, 'delete'),
delete: get(obj, 'delete'),
clear: get(obj, 'clear'),

@@ -58,0 +58,0 @@ keys: get(obj, 'keys'),

{
"name": "@teamawesome/access",
"version": "1.0.8",
"version": "1.0.9",
"description": "Provide a unified interface for objects.",

@@ -13,2 +13,3 @@ "keywords": [

"main": "dist/index.js",
"types": "./access.d.ts",
"scripts": {

@@ -27,19 +28,19 @@ "build": "babel src --out-dir dist",

"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/plugin-transform-runtime": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@babel/eslint-parser": "^7.12.1",
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/eslint-parser": "^7.14.4",
"@babel/plugin-transform-runtime": "^7.14.3",
"@babel/preset-env": "^7.14.4",
"benchmark": "^2.1.4",
"eslint": "^7.17.0",
"eslint": "^7.27.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1",
"mocha": "^8.2.1",
"eslint-plugin-import": "^2.23.4",
"mocha": "^8.4.0",
"should": "^13.2.3",
"should-sinon": "0.0.6",
"sinon": "^9.2.2"
"sinon": "^11.1.1"
},
"dependencies": {
"@babel/runtime": "^7.12.5"
"@babel/runtime": "^7.14.0"
}
}

@@ -1,25 +0,4 @@

export const types = new Map();
import { call0, call1, call2 } from './call';
import types from './types';
/**
* Call a method on the object's proxy or the object itself
*
* @param {*} obj
* @param {string} method
* @param {*} [key]
* @param {*} [value]
*/
function call(obj, method, key, value) {
const proxy = types.get(obj.constructor);
if (proxy !== undefined && typeof proxy[method] === 'function') {
return proxy[method](obj, key, value);
}
if (typeof obj[method] === 'function') {
return obj[method](key, value);
}
throw new TypeError(`No [${method}] handler for objects of type [${obj.constructor.name}]`);
}
export default {

@@ -34,3 +13,3 @@ /**

get(obj, key) {
return call(obj, 'get', key);
return call1(obj, 'get', key);
},

@@ -48,3 +27,3 @@

set(obj, key, value) {
call(obj, 'set', key, value);
call2(obj, 'set', key, value);

@@ -62,3 +41,3 @@ return obj;

has(obj, key) {
return call(obj, 'has', key);
return call1(obj, 'has', key);
},

@@ -74,3 +53,3 @@

delete(obj, key) {
return call(obj, 'delete', key);
return call1(obj, 'delete', key);
},

@@ -84,3 +63,3 @@

clear(obj) {
call(obj, 'clear');
call0(obj, 'clear');
},

@@ -95,3 +74,3 @@

keys(obj) {
return call(obj, 'keys');
return call0(obj, 'keys');
},

@@ -106,3 +85,3 @@

values(obj) {
return call(obj, 'values');
return call0(obj, 'values');
},

@@ -117,3 +96,3 @@

entries(obj) {
return call(obj, 'entries');
return call0(obj, 'entries');
},

@@ -120,0 +99,0 @@

@@ -5,2 +5,3 @@ import './array';

export { default, types } from './access';
export { default, default as access } from './access';
export { default as types } from './types';

@@ -37,2 +37,2 @@ import access from './access';

// Objects created without a prototype do not have a constructor
access.register(undefined, proxy);
// access.register(undefined, proxy);

@@ -1,2 +0,2 @@

import { types } from './access';
import types from './types';

@@ -13,3 +13,5 @@ /**

return proxy[method].bind(null, obj);
} if (typeof obj[method] === 'function') {
}
if (typeof obj[method] === 'function') {
return obj[method].bind(obj);

@@ -16,0 +18,0 @@ }

@@ -167,10 +167,12 @@ const should = require('should');

it('implicit type', () => {
const custom = {
constructor() {},
get: sinon.stub().returns(1),
has: sinon.stub().returns(true),
delete: sinon.stub().returns(true),
clear: sinon.stub().returns(undefined),
};
const custom = new class {
get = sinon.stub().returns(1);
has = sinon.stub().returns(true);
delete = sinon.stub().returns(true);
clear = sinon.stub().returns(undefined);
}();
custom.set = sinon.stub().returns(custom);

@@ -199,3 +201,3 @@

it('register & unregister', () => {
function Custom() {}
class Custom { }
const proxy = {};

@@ -211,4 +213,5 @@

it('mixed type', () => {
function Custom() {}
Custom.prototype.get = sinon.stub().returns(1);
class Custom {
get = sinon.stub().returns(1)
}

@@ -218,2 +221,3 @@ const custom = new Custom();

const proxy = {
// No getter in proxy.
set: sinon.stub().returns(custom),

@@ -276,1 +280,20 @@ has: sinon.stub().returns(true),

});
it('proxy precedence', () => {
class Custom {
get = sinon.stub().returns(1)
}
const custom = new Custom();
const proxy = {
get: sinon.stub().returns(1),
};
access.register(Custom, proxy);
access.get(custom, 'a');
custom.get.should.not.be.called();
proxy.get.should.be.calledOnce()
.and.be.calledWith(custom, 'a');
});

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