@t007/utils 0.0.36 → 0.0.37

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.
@@ -206,10 +206,10 @@ function RAFLoop(key, fn, signal, win) {
206
206
  }
207
207
  var cancelRAFLoop = (key) => t007._RAFLoopers ? t007._RAFLoopers.delete(key) : false;
208
208
  function limited(FN_KEY, fn, opts = {}) {
209
- let count = 0, { key, maxTimes: max = 1, oncePerSession = true } = isStr(opts) ? { key: opts } : opts;
209
+ let count = 0, { key, maxTimes: max = 1, perSession = key != null } = isStr(opts) ? { key: opts } : opts;
210
210
  const getReg = () => JSON.parse(localStorage.getItem(FN_KEY) || "{}"), setReg = (r) => localStorage.setItem(FN_KEY, JSON.stringify(r));
211
211
  const handle = (...args) => {
212
- if (oncePerSession && count > 0) return void 0;
212
+ if (perSession && count >= +perSession) return;
213
213
  if (!key) return count++ < max ? fn(...args) : void 0;
214
214
  const r = getReg(), c = r[key] || 0;
215
215
  return c < max ? (count++, r[key] = c + 1, setReg(r), fn(...args)) : void 0;
@@ -4,7 +4,7 @@ import {
4
4
  createEl,
5
5
  getActiveEl,
6
6
  isInteractive
7
- } from "./chunk-ZOFWWRKV.js";
7
+ } from "./chunk-4S4VEQL7.js";
8
8
 
9
9
  // src/ts/hooks/vanilla/outsideClick.ts
10
10
  import { NIL, NOOP } from "sia-reactor";
@@ -1,6 +1,3 @@
1
- import {
2
- useHighlight
3
- } from "../chunk-RXMKMD3E.js";
4
1
  import {
5
2
  DEFAULT_CONFIG,
6
3
  H_NAV_KEYS,
@@ -11,11 +8,14 @@ import {
11
8
  initFocusTrap,
12
9
  initOutsideClick,
13
10
  rippleHandler
14
- } from "../chunk-DSDFIB5F.js";
11
+ } from "../chunk-7TIUDIEW.js";
15
12
  import {
16
13
  INTERACTIVE_SELECTOR,
17
14
  getActiveEl
18
- } from "../chunk-ZOFWWRKV.js";
15
+ } from "../chunk-4S4VEQL7.js";
16
+ import {
17
+ useHighlight
18
+ } from "../chunk-RXMKMD3E.js";
19
19
 
20
20
  // src/ts/hooks/react/useScrollAssist.ts
21
21
  import { useEffect, useRef, useCallback } from "react";
@@ -11,12 +11,12 @@ import {
11
11
  removeOutsideClick,
12
12
  rippleHandler,
13
13
  syncFocusTrap
14
- } from "../chunk-DSDFIB5F.js";
14
+ } from "../chunk-7TIUDIEW.js";
15
15
  import {
16
16
  INTERACTIVE_SELECTOR,
17
17
  createEl,
18
18
  getActiveEl
19
- } from "../chunk-ZOFWWRKV.js";
19
+ } from "../chunk-4S4VEQL7.js";
20
20
 
21
21
  // src/ts/hooks/vanilla/scrollAssist.ts
22
22
  import { NIL } from "sia-reactor";
package/dist/index.cjs CHANGED
@@ -292,10 +292,10 @@ function RAFLoop(key, fn, signal, win) {
292
292
  }
293
293
  var cancelRAFLoop = (key) => t007._RAFLoopers ? t007._RAFLoopers.delete(key) : false;
294
294
  function limited(FN_KEY, fn, opts = {}) {
295
- let count = 0, { key, maxTimes: max = 1, oncePerSession = true } = isStr(opts) ? { key: opts } : opts;
295
+ let count = 0, { key, maxTimes: max = 1, perSession = key != null } = isStr(opts) ? { key: opts } : opts;
296
296
  const getReg = () => JSON.parse(localStorage.getItem(FN_KEY) || "{}"), setReg = (r) => localStorage.setItem(FN_KEY, JSON.stringify(r));
297
297
  const handle = (...args) => {
298
- if (oncePerSession && count > 0) return void 0;
298
+ if (perSession && count >= +perSession) return;
299
299
  if (!key) return count++ < max ? fn(...args) : void 0;
300
300
  const r = getReg(), c = r[key] || 0;
301
301
  return c < max ? (count++, r[key] = c + 1, setReg(r), fn(...args)) : void 0;
package/dist/index.d.cts CHANGED
@@ -182,8 +182,8 @@ interface LimitedOptions {
182
182
  key?: string;
183
183
  /** Maximum number of allowed calls. @default 1 */
184
184
  maxTimes?: number;
185
- /** Only allow calling once per session, regardless of maxTimes. @default true */
186
- oncePerSession?: boolean;
185
+ /** Only allow calling x times per session, regardless of maxTimes. @default true */
186
+ perSession?: boolean | number;
187
187
  }
188
188
  interface LimitedHandle<T extends (...args: any[]) => any> {
189
189
  /** Call the wrapped function with the original arguments. */
package/dist/index.d.ts CHANGED
@@ -182,8 +182,8 @@ interface LimitedOptions {
182
182
  key?: string;
183
183
  /** Maximum number of allowed calls. @default 1 */
184
184
  maxTimes?: number;
185
- /** Only allow calling once per session, regardless of maxTimes. @default true */
186
- oncePerSession?: boolean;
185
+ /** Only allow calling x times per session, regardless of maxTimes. @default true */
186
+ perSession?: boolean | number;
187
187
  }
188
188
  interface LimitedHandle<T extends (...args: any[]) => any> {
189
189
  /** Call the wrapped function with the original arguments. */
package/dist/index.js CHANGED
@@ -60,7 +60,7 @@ import {
60
60
  throttle,
61
61
  uid,
62
62
  uncamelize
63
- } from "./chunk-ZOFWWRKV.js";
63
+ } from "./chunk-4S4VEQL7.js";
64
64
  export {
65
65
  INTERACTIVE_SELECTOR,
66
66
  KEYS_BLOCKS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/utils",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "description": "High-performance utilities for the t007 ecosystem.",
5
5
  "author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
6
6
  "license": "MIT",
@@ -76,7 +76,7 @@
76
76
  "react-dom": "^18.3.1"
77
77
  },
78
78
  "dependencies": {
79
- "sia-reactor": "^0.0.37"
79
+ "sia-reactor": "^0.0.38"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "react": "^18.0.0"