corexxx 1.0.83 → 1.0.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ export declare namespace dcache {
2
+ function memoizeAsync(func: Function): (...args: any) => Promise<any>;
3
+ function memoize(func: Function): (...args: any) => any;
4
+ }
package/dist/dcache.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.dcache = void 0;
13
+ var dcache;
14
+ (function (dcache) {
15
+ /*
16
+ https://www.sitepoint.com/implementing-memoization-in-javascript/
17
+ function pow(a, b) {
18
+ return a ** b;
19
+ }
20
+
21
+ // creates the memoized version
22
+ pow = memoize(pow);
23
+
24
+ pow(3, 5); // creates the index "[3,5]" and returns 243
25
+ */
26
+ // make sure you have used await
27
+ function memoizeAsync(func) {
28
+ const cache = {};
29
+ return function memoized(...args) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const key = JSON.stringify(args);
32
+ if (!cache[key]) {
33
+ cache[key] = yield func(...args);
34
+ }
35
+ return cache[key];
36
+ });
37
+ };
38
+ }
39
+ dcache.memoizeAsync = memoizeAsync;
40
+ // just call
41
+ function memoize(func) {
42
+ const cache = {};
43
+ return function memoized(...args) {
44
+ const key = JSON.stringify(args);
45
+ if (!cache[key]) {
46
+ cache[key] = func(...args);
47
+ }
48
+ return cache[key];
49
+ };
50
+ }
51
+ dcache.memoize = memoize;
52
+ })(dcache = exports.dcache || (exports.dcache = {}));
53
+ //# sourceMappingURL=dcache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dcache.js","sourceRoot":"","sources":["../src/dcache.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,IAAiB,MAAM,CAmCtB;AAnCD,WAAiB,MAAM;IACrB;;;;;;;;;;QAUI;IACJ,gCAAgC;IAChC,SAAgB,YAAY,CAAC,IAAc;QACzC,MAAM,KAAK,GAAY,EAAE,CAAC;QAC1B,OAAO,SAAe,QAAQ,CAAC,GAAG,IAAS;;gBACzC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBACjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;oBACf,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;iBAClC;gBACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC;SAAA,CAAC;IACJ,CAAC;IATe,mBAAY,eAS3B,CAAA;IAED,YAAY;IACZ,SAAgB,OAAO,CAAC,IAAc;QACpC,MAAM,KAAK,GAAY,EAAE,CAAC;QAC1B,OAAO,SAAS,QAAQ,CAAC,GAAG,IAAS;YACnC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACjC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;gBACf,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;aAC5B;YACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC,CAAC;IACJ,CAAC;IATe,cAAO,UAStB,CAAA;AACH,CAAC,EAnCgB,MAAM,GAAN,cAAM,KAAN,cAAM,QAmCtB"}
package/dist/test.js CHANGED
@@ -1,12 +1,28 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const dcrypto_1 = require("./dcrypto");
12
+ const dcache_1 = require("./dcache");
4
13
  const dlog_1 = require("./dlog");
5
14
  dlog_1.dlog.d("hello world");
6
15
  //dvalidation.validateExistOrThrow({ a: [] }, ["a"]);
7
16
  //console.log(dtime.isSameDay("2022-02-24T11:08:54.342Z", "2022-02-24T11:08:54.342Z"));
8
17
  //console.log(dtime.getIstTime(new Date().toISOString()));
9
18
  //console.log(dformat.formatMe("Hello #{me} #{me}", { me: "dipankar" }));
10
- console.log(dcrypto_1.dcrypto.decrypt(dcrypto_1.dcrypto.encrypt("dipankar", "dip"), "dip"));
11
- console.log(dcrypto_1.dcrypto.decrypt(dcrypto_1.dcrypto.encrypt("dipankar", "dip"), "dip1"));
19
+ //console.log(dcrypto.decrypt(dcrypto.encrypt("dipankar", "dip"), "dip"));
20
+ //console.log(dcrypto.decrypt(dcrypto.encrypt("dipankar", "dip"), "dip1"));
21
+ let pow = dcache_1.dcache.memoizeAsync((a, b) => {
22
+ return Math.pow(a, b);
23
+ });
24
+ (() => __awaiter(void 0, void 0, void 0, function* () {
25
+ yield pow(3, 5); // creates the index "[3,5]" and returns 243
26
+ yield pow(3, 5);
27
+ }))();
12
28
  //# sourceMappingURL=test.js.map
package/dist/test.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;AAAA,uCAAoC;AACpC,iCAA8B;AAE9B,WAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;AACtB,qDAAqD;AACrD,uFAAuF;AACvF,0DAA0D;AAC1D,yEAAyE;AAEzE,OAAO,CAAC,GAAG,CAAC,iBAAO,CAAC,OAAO,CAAC,iBAAO,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AACxE,OAAO,CAAC,GAAG,CAAC,iBAAO,CAAC,OAAO,CAAC,iBAAO,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,qCAAkC;AAClC,iCAA8B;AAE9B,WAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;AACtB,qDAAqD;AACrD,uFAAuF;AACvF,0DAA0D;AAC1D,yEAAyE;AAEzE,0EAA0E;AAC1E,2EAA2E;AAE3E,IAAI,GAAG,GAAG,eAAM,CAAC,YAAY,CAAC,CAAC,CAAM,EAAE,CAAM,EAAE,EAAE;IAC/C,OAAO,SAAA,CAAC,EAAI,CAAC,CAAA,CAAC;AAChB,CAAC,CAAC,CAAC;AAEH,CAAC,GAAS,EAAE;IACV,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,4CAA4C;IAC7D,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAClB,CAAC,CAAA,CAAC,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corexxx",
3
- "version": "1.0.83",
3
+ "version": "1.0.84",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/dcache.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { TObject } from ".";
2
+ export namespace dcache {
3
+ /*
4
+ https://www.sitepoint.com/implementing-memoization-in-javascript/
5
+ function pow(a, b) {
6
+ return a ** b;
7
+ }
8
+
9
+ // creates the memoized version
10
+ pow = memoize(pow);
11
+
12
+ pow(3, 5); // creates the index "[3,5]" and returns 243
13
+ */
14
+ // make sure you have used await
15
+ export function memoizeAsync(func: Function) {
16
+ const cache: TObject = {};
17
+ return async function memoized(...args: any) {
18
+ const key = JSON.stringify(args);
19
+ if (!cache[key]) {
20
+ cache[key] = await func(...args);
21
+ }
22
+ return cache[key];
23
+ };
24
+ }
25
+
26
+ // just call
27
+ export function memoize(func: Function) {
28
+ const cache: TObject = {};
29
+ return function memoized(...args: any) {
30
+ const key = JSON.stringify(args);
31
+ if (!cache[key]) {
32
+ cache[key] = func(...args);
33
+ }
34
+ return cache[key];
35
+ };
36
+ }
37
+ }
package/src/test.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { dcrypto } from "./dcrypto";
1
+ import { dcache } from "./dcache";
2
2
  import { dlog } from "./dlog";
3
3
 
4
4
  dlog.d("hello world");
@@ -7,5 +7,14 @@ dlog.d("hello world");
7
7
  //console.log(dtime.getIstTime(new Date().toISOString()));
8
8
  //console.log(dformat.formatMe("Hello #{me} #{me}", { me: "dipankar" }));
9
9
 
10
- console.log(dcrypto.decrypt(dcrypto.encrypt("dipankar", "dip"), "dip"));
11
- console.log(dcrypto.decrypt(dcrypto.encrypt("dipankar", "dip"), "dip1"));
10
+ //console.log(dcrypto.decrypt(dcrypto.encrypt("dipankar", "dip"), "dip"));
11
+ //console.log(dcrypto.decrypt(dcrypto.encrypt("dipankar", "dip"), "dip1"));
12
+
13
+ let pow = dcache.memoizeAsync((a: any, b: any) => {
14
+ return a ** b;
15
+ });
16
+
17
+ (async () => {
18
+ await pow(3, 5); // creates the index "[3,5]" and returns 243
19
+ await pow(3, 5);
20
+ })();