memo.js
 1  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
 2  /* eslint-disable @typescript-eslint/no-explicit-any */
 3  
 4  /**
 5   * Helper to decycle json objects
 6   */
 7  function memoBuilder() {
 8    const hasWeakSet = typeof WeakSet === 'function';
 9    const inner = hasWeakSet ? new WeakSet() : [];
10    function memoize(obj) {
11      if (hasWeakSet) {
12        if (inner.has(obj)) {
13          return true;
14        }
15        inner.add(obj);
16        return false;
17      }
18      // eslint-disable-next-line @typescript-eslint/prefer-for-of
19      for (let i = 0; i < inner.length; i++) {
20        const value = inner[i];
21        if (value === obj) {
22          return true;
23        }
24      }
25      inner.push(obj);
26      return false;
27    }
28  
29    function unmemoize(obj) {
30      if (hasWeakSet) {
31        inner.delete(obj);
32      } else {
33        for (let i = 0; i < inner.length; i++) {
34          if (inner[i] === obj) {
35            inner.splice(i, 1);
36            break;
37          }
38        }
39      }
40    }
41    return [memoize, unmemoize];
42  }
43  
44  export { memoBuilder };
45  //# sourceMappingURL=memo.js.map