+52
-0
@@ -14,2 +14,54 @@ "use strict"; | ||
| static Wrapper = class { | ||
| constructor() { | ||
| return new Proxy(this, { | ||
| map: new Map(), | ||
| get(target, name) { | ||
| const self = this; | ||
| if (name === "toJSON") { | ||
| return target.constructor.toString(); | ||
| } | ||
| const key = JSON.stringify({ | ||
| target: target.constructor.toString(), | ||
| name, | ||
| }); | ||
| if (typeof target[name] === "function") { | ||
| if (this.map.has(key)) { | ||
| return () => this.map.get(key); | ||
| } | ||
| return function (...args) { | ||
| const output = target[name].bind(target)(...args); | ||
| if (typeof output === "string") { | ||
| const response = cipherio.compile(output); | ||
| self.map.set(key, response); | ||
| return response; | ||
| } | ||
| return output; | ||
| }; | ||
| } | ||
| const value = target[name]; | ||
| if (typeof value === "string") { | ||
| const response = cipherio.compile(value); | ||
| self.map.set(key, response); | ||
| return response; | ||
| } | ||
| return value; | ||
| }, | ||
| }); | ||
| } | ||
| }; | ||
| static compile(code, params) { | ||
@@ -16,0 +68,0 @@ params = getNormalizedParams(params, this.DEFAULT); |
+1
-1
| { | ||
| "name": "cipherio", | ||
| "version": "1.2.3", | ||
| "version": "1.3.3", | ||
| "description": "Make secure parts in shared code", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+14
-0
@@ -46,2 +46,16 @@ # cipherio | ||
| Wrapping classes to return hashed values | ||
| ```js | ||
| const instance = new (class extends cipherio.Wrapper { | ||
| prop = "abc"; | ||
| foo() { | ||
| return "bar"; | ||
| } | ||
| })(); | ||
| const originalProp = cipherio.read(instance.prop); | ||
| const functionResult = cipherio.read(instance.foo()); | ||
| ``` | ||
| ## Test | ||
@@ -48,0 +62,0 @@ |
8804
19.62%251
17.84%65
27.45%