class-privacy
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -8,2 +8,4 @@ "use strict"; | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
@@ -104,4 +106,7 @@ | ||
var member = instance[property]; | ||
var includeMember = decide(property, member, ClassDefinition); | ||
var type = _typeof(member); | ||
var includeMember = decide(property, type, ClassDefinition); | ||
if (!includeMember) { | ||
@@ -113,3 +118,3 @@ return; | ||
if (typeof member === 'function') { | ||
if (type === 'function') { | ||
return member.bind(instance); | ||
@@ -116,0 +121,0 @@ } else { |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=void 0;function isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(a){return!1}}function _construct(){return _construct=isNativeReflectConstruct()?Reflect.construct:function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&_setPrototypeOf(f,d.prototype),f},_construct.apply(null,arguments)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var defaultOptions={decide:function(){return!0},revealIsProxy:!1,referenceClass:!1},IS_PROXY="isProxy",CLASS="class",check=function(a,b){var c=a&&Object.getPrototypeOf(a),d=c&&c.constructor;if(d!==b){var e=d&&d.name,f=b&&b.name;throw new TypeError("Expected ".concat(f,", got ").concat(e,"."))}},createFactory=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:defaultOptions;check(a,Function),check(b,Object);var c=Object.assign({},defaultOptions,b),d=c.decide||defaultOptions.decide,e=c.referenceClass||defaultOptions.referenceClass,f=c.revealIsProxy||defaultOptions.revealIsProxy,g=function(){for(var b=arguments.length,c=Array(b),g=0;g<b;g++)c[g]=arguments[g];var h=_construct(a,c);return new Proxy({},{get:function(b,c){if(f&&c===IS_PROXY)return!0;if(e&&c===CLASS)return a;if(c in h){var g=h[c],i=d(c,g,a);return i?"function"==typeof g?g.bind(h):g:void 0}}})};return g},_default=createFactory;exports["default"]=_default; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=void 0;function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(a){return!1}}function _construct(){return _construct=isNativeReflectConstruct()?Reflect.construct:function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&_setPrototypeOf(f,d.prototype),f},_construct.apply(null,arguments)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}var defaultOptions={decide:function(){return!0},revealIsProxy:!1,referenceClass:!1},IS_PROXY="isProxy",CLASS="class",check=function(a,b){var c=a&&Object.getPrototypeOf(a),d=c&&c.constructor;if(d!==b){var e=d&&d.name,f=b&&b.name;throw new TypeError("Expected ".concat(f,", got ").concat(e,"."))}},createFactory=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:defaultOptions;check(a,Function),check(b,Object);var c=Object.assign({},defaultOptions,b),d=c.decide||defaultOptions.decide,e=c.referenceClass||defaultOptions.referenceClass,f=c.revealIsProxy||defaultOptions.revealIsProxy,g=function(){for(var b=arguments.length,c=Array(b),g=0;g<b;g++)c[g]=arguments[g];var h=_construct(a,c);return new Proxy({},{get:function(b,c){if(f&&c===IS_PROXY)return!0;if(e&&c===CLASS)return a;if(c in h){var g=h[c],i=_typeof(g),j=d(c,i,a);return j?"function"===i?g.bind(h):g:void 0}}})};return g},_default=createFactory;exports["default"]=_default; |
@@ -78,3 +78,5 @@ /** | ||
const member = instance[property] | ||
const includeMember = decide(property, member, ClassDefinition) | ||
const type = typeof member | ||
const includeMember = decide(property, type, ClassDefinition) | ||
if (!includeMember) { | ||
@@ -86,3 +88,3 @@ return | ||
// blocking the member function's internals | ||
if (typeof member === 'function') { | ||
if (type === 'function') { | ||
return member.bind(instance) | ||
@@ -89,0 +91,0 @@ } else { |
{ | ||
"name": "class-privacy", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Simple way to define private members on ES6 classes, keep their code clean.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -40,8 +40,4 @@ # :lock: Javascript Class-Privacy | ||
// make all functions public, all other members are private | ||
// it is your responsibility to prevent leakage of information | ||
// for example if value is passed to external functions that aid | ||
// for a decision. | ||
// Think twice, before you pass value to third party libraries. | ||
const decide = (key, value) => typeof value === 'function' | ||
// make all functions public, all other members are private | ||
const decide = (key, type) => type === 'function' | ||
@@ -65,4 +61,4 @@ // create the factory for private persons | ||
A function that is invoked on every access request (proxy `get` trap) | ||
and receives `key`, `value` and `ClassDefinition` to decide, whether | ||
this value should be allowed to be public or kept being private. | ||
and receives `key`, `type` and `ClassDefinition` to decide, whether | ||
this member should be allowed to be public or kept being private. | ||
@@ -72,8 +68,7 @@ Signature: | ||
```javascript | ||
decide: (key, value, ClassDefinition) => Boolean | ||
decide: (key, type, ClassDefinition) => Boolean | ||
``` | ||
Non-boolean return values are evaluated as truthy/falsy. | ||
If not passed, all members are included by default to preserve the original | ||
If not passed in options, all members are included by default to preserve the original | ||
state. | ||
@@ -80,0 +75,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
24781
192
0
184