class-privacy
Version:
Simple way to define private members on ES6 classes, keep their code clean.
1 lines • 1.95 kB
JavaScript
;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;