@zlikemario/helper 0.0.9 → 0.0.10

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./utils.cjs");function m(s=0,i=(...a)=>a[0],c=!1){return function(a,r,o){const d=o.value,e=new Map;let f=Date.now();const g=Symbol(String(r)),h=()=>s>0&&f<Date.now();return o.value=function(...l){const n=(typeof i=="function"?i(...l):i)??g;if(!e.get(n)||h()){f=Date.now()+s;const t=d.apply(this,l);t instanceof Promise?(e.set(n,t),t.then(M=>{!c&&u.isUndefined(M)&&e.delete(n)})):(c||!u.isUndefined(t))&&e.set(n,t)}return e.get(n)},o}}exports.Memoize=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./utils.cjs");function v(c=0,l=(...u)=>u[0],f=!1){return function(u,h,o){const g=o.value,r=o.get,t=new Map;let a=Date.now();const m=Symbol(String(h)),y=()=>c>0&&a<Date.now(),d=(...n)=>(typeof l=="function"?l(...n):l)??m;return typeof g=="function"&&(o.value=function(...n){const e=d(...n);if(!t.get(e)||y()){a=Date.now()+c;const i=g.apply(this,n);i instanceof Promise?(t.set(e,i),i.then(p=>{!f&&s.isUndefined(p)&&t.delete(e)})):(f||!s.isUndefined(i))&&t.set(e,i)}return t.get(e)}),typeof r=="function"&&(o.get=function(){const n=d();if(!t.get(n)||y()){a=Date.now()+c;const e=r.apply(this);e instanceof Promise?(t.set(n,e),e.then(i=>{!f&&s.isUndefined(i)&&t.delete(n)})):(f||!s.isUndefined(e))&&t.set(n,e)}return t.get(n)}),o}}exports.Memoize=v;
@@ -1 +1 @@
1
- export declare function Memoize<Args extends any[]>(duration?: number, computeKey?: ((...args: Args) => PropertyKey) | PropertyKey, isCacheVoid?: boolean): <T>(_: any, name: string, descriptor: TypedPropertyDescriptor<(...args: Args) => T>) => TypedPropertyDescriptor<(...args: Args) => T>;
1
+ export declare function Memoize<Args extends any[]>(duration?: number, computeKey?: ((...args: Args) => PropertyKey) | PropertyKey, isCacheVoid?: boolean): (_: any, name: string | symbol, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>;
@@ -1,22 +1,32 @@
1
- import { isUndefined as r } from "./utils.js";
2
- function g(f = 0, o = (...c) => c[0], a = !1) {
3
- return function(c, u, i) {
4
- const h = i.value, e = /* @__PURE__ */ new Map();
5
- let s = Date.now();
6
- const d = Symbol(String(u)), m = () => f > 0 && s < Date.now();
7
- return i.value = function(...l) {
8
- const n = (typeof o == "function" ? o(...l) : o) ?? d;
9
- if (!e.get(n) || m()) {
10
- s = Date.now() + f;
11
- const t = h.apply(this, l);
12
- t instanceof Promise ? (e.set(n, t), t.then((w) => {
13
- !a && r(w) && e.delete(n);
14
- })) : (a || !r(t)) && e.set(n, t);
1
+ import { isUndefined as c } from "./utils.js";
2
+ function v(s = 0, a = (...u) => u[0], i = !1) {
3
+ return function(u, p, f) {
4
+ const g = f.value, y = f.get, t = /* @__PURE__ */ new Map();
5
+ let l = Date.now();
6
+ const r = Symbol(String(p)), h = () => s > 0 && l < Date.now(), m = (...n) => (typeof a == "function" ? a(...n) : a) ?? r;
7
+ return typeof g == "function" && (f.value = function(...n) {
8
+ const e = m(...n);
9
+ if (!t.get(e) || h()) {
10
+ l = Date.now() + s;
11
+ const o = g.apply(this, n);
12
+ o instanceof Promise ? (t.set(e, o), o.then((w) => {
13
+ !i && c(w) && t.delete(e);
14
+ })) : (i || !c(o)) && t.set(e, o);
15
15
  }
16
- return e.get(n);
17
- }, i;
16
+ return t.get(e);
17
+ }), typeof y == "function" && (f.get = function() {
18
+ const n = m();
19
+ if (!t.get(n) || h()) {
20
+ l = Date.now() + s;
21
+ const e = y.apply(this);
22
+ e instanceof Promise ? (t.set(n, e), e.then((o) => {
23
+ !i && c(o) && t.delete(n);
24
+ })) : (i || !c(e)) && t.set(n, e);
25
+ }
26
+ return t.get(n);
27
+ }), f;
18
28
  };
19
29
  }
20
30
  export {
21
- g as Memoize
31
+ v as Memoize
22
32
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zlikemario/helper",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "A utility library with number operations and common helper functions",
5
5
  "keywords": [
6
6
  "utility",