@hyperfrontend/time-utils 0.0.4 → 1.0.0

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +20 -6
  2. package/README.md +6 -3
  3. package/SECURITY.md +50 -15
  4. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/date/index.cjs.js +10 -0
  5. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/date/index.esm.js +8 -0
  6. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.cjs.js +6 -0
  7. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.esm.js +5 -0
  8. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.cjs.js +5 -0
  9. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.esm.js +4 -0
  10. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/number/index.cjs.js +4 -0
  11. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/number/index.esm.js +5 -0
  12. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.cjs.js +5 -0
  13. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.esm.js +4 -0
  14. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/promise/index.cjs.js +6 -0
  15. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/promise/index.esm.js +5 -0
  16. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/timers/index.cjs.js +18 -0
  17. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/timers/index.esm.js +14 -0
  18. package/bundle/index.iife.js +0 -192
  19. package/bundle/index.iife.min.js +0 -1
  20. package/bundle/index.umd.js +0 -192
  21. package/bundle/index.umd.min.js +0 -1
  22. package/index.cjs.js +84 -213
  23. package/index.d.ts +134 -6
  24. package/index.d.ts.map +1 -1
  25. package/index.esm.js +67 -196
  26. package/package.json +12 -7
  27. package/bundle/index.iife.js.map +0 -1
  28. package/bundle/index.iife.min.js.map +0 -1
  29. package/bundle/index.umd.js.map +0 -1
  30. package/bundle/index.umd.min.js.map +0 -1
  31. package/create-clock.d.ts +0 -20
  32. package/create-clock.d.ts.map +0 -1
  33. package/create-timer.d.ts +0 -18
  34. package/create-timer.d.ts.map +0 -1
  35. package/index.cjs.js.map +0 -1
  36. package/index.esm.js.map +0 -1
  37. package/normalize-to-base-time-window.d.ts +0 -9
  38. package/normalize-to-base-time-window.d.ts.map +0 -1
  39. package/set-interval-callback.d.ts +0 -9
  40. package/set-interval-callback.d.ts.map +0 -1
  41. package/sleep.d.ts +0 -8
  42. package/sleep.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,16 +1,30 @@
1
1
  # Changelog
2
2
 
3
- This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
3
+ All notable changes to this project will be documented in this file.
4
4
 
5
- ## [0.0.4](https://github.com/AndrewRedican/hyperfrontend/compare/lib-time-utils@0.0.3...lib-time-utils@0.0.4) (2026-03-08)
5
+ ## [1.0.0](https://github.com/AndrewRedican/hyperfrontend/compare/5f116abb8ba6355dfb283fa03b7481e5eb029480...4b34883aead4c721f021465b19fa5bdd49514d37) - 2026-08-31
6
6
 
7
- ## [0.0.3](https://github.com/AndrewRedican/hyperfrontend/compare/lib-time-utils@0.0.2...lib-time-utils@0.0.3) (2026-03-02)
7
+ ### Features
8
8
 
9
+ - Marked stable. No API changes since 0.0.5.
10
+
11
+ ## [0.0.5](https://github.com/AndrewRedican/hyperfrontend/compare/c8db08be8b183addd26caf81fdd17fb3693f296f...466c0388c4cd516b9c704214140b4df1004098e6) - 2026-06-23
12
+
13
+ ### Other
14
+
15
+ - **@hyperfrontend/workspace:** remove lib-builder and tool-package as implicit dependencies for all lib projects
16
+
17
+ ## [0.0.4](https://github.com/AndrewRedican/hyperfrontend/compare/lib-time-utils@0.0.3...lib-time-utils@0.0.4) - 2026-03-08
18
+
19
+
20
+ ## [0.0.3](https://github.com/AndrewRedican/hyperfrontend/compare/lib-time-utils@0.0.2...lib-time-utils@0.0.3) - 2026-03-02
9
21
 
10
22
  ### Bug Fixes
11
23
 
12
- * **lib-time-utils:** correct package exports and dependencies ([3b9096b](https://github.com/AndrewRedican/hyperfrontend/commit/3b9096b54337c2c2f3e06d6b97865a772e79aad9))
24
+ - **lib-time-utils:** correct package exports and dependencies ([3b9096b](https://github.com/AndrewRedican/hyperfrontend/commit/3b9096b54337c2c2f3e06d6b97865a772e79aad9))
25
+
26
+ ## [0.0.2](https://github.com/AndrewRedican/hyperfrontend/compare/lib-time-utils@0.0.1...lib-time-utils@0.0.2) - 2026-02-26
27
+
13
28
 
14
- ## [0.0.2](https://github.com/AndrewRedican/hyperfrontend/compare/lib-time-utils@0.0.1...lib-time-utils@0.0.2) (2026-02-26)
29
+ ## 0.0.1 - 2026-02-15
15
30
 
16
- ## 0.0.1 (2026-02-15)
package/README.md CHANGED
@@ -35,6 +35,9 @@
35
35
 
36
36
  Functional time utilities for async operations, intervals, and time normalization.
37
37
 
38
+ • 👉 See [**documentation**](https://www.hyperfrontend.dev/docs/libraries/utils/time/)
39
+ • 👉 See [**guides & tutorials**](https://www.hyperfrontend.dev/docs/guides/?package=%40hyperfrontend%2Ftime-utils)
40
+
38
41
  ## What is @hyperfrontend/time-utils?
39
42
 
40
43
  `@hyperfrontend/time-utils` provides composable, testable utilities for working with time-based operations in JavaScript. The library focuses on enhancing the control and flexibility of standard timing APIs (`setTimeout`, `setInterval`) while adding specialized utilities for async workflows and time window calculations.
@@ -60,7 +63,7 @@ All timing abstractions maintain internal state privately while exposing frozen
60
63
 
61
64
  ### 1. Pause/Resume Capabilities Native APIs Lack
62
65
 
63
- JavaScript's `setTimeout` and `setInterval` cannot be pausedonce started, they either complete or get cancelled. This creates problems for features like user-initiated pauses in games, animations during background tabs, or request throttling. `createTimer()` tracks elapsed time internally, enabling pause/resume without restarting from the beginning or losing progress.
66
+ JavaScript's `setTimeout` and `setInterval` cannot be paused: once started, they either complete or get cancelled. This creates problems for features like user-initiated pauses in games, animations during background tabs, or request throttling. `createTimer()` tracks elapsed time internally, enabling pause/resume without restarting from the beginning or losing progress.
64
67
 
65
68
  **Example:** A countdown timer in a game needs to pause when the user switches tabs. With `setTimeout`, you'd need to calculate remaining time manually and create a new timeout. With `createTimer`, just call `timer.pause()`.
66
69
 
@@ -245,7 +248,7 @@ cleanup()
245
248
 
246
249
  ### Dependencies
247
250
 
248
- None zero external dependencies.
251
+ None: zero external dependencies.
249
252
 
250
253
  ## Part of hyperfrontend
251
254
 
@@ -257,4 +260,4 @@ This library is part of the [hyperfrontend](https://github.com/AndrewRedican/hyp
257
260
 
258
261
  ## License
259
262
 
260
- MIT
263
+ [MIT](https://github.com/AndrewRedican/hyperfrontend/blob/main/LICENSE.md)
package/SECURITY.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Security Policy
2
2
 
3
+ ## The Security Model
4
+
5
+ Before reporting or reviewing, read the model this project is built on:
6
+ **[Security Model](https://www.hyperfrontend.dev/docs/core-concepts/security)**. It is the canonical
7
+ statement of what hyperfrontend defends against and what it does not, and it is the reference every
8
+ other security claim in these docs points back to. In short:
9
+
10
+ - **The named adversary is co-resident script**: an analytics snippet, tag manager, compromised
11
+ dependency, or unknown page that embeds a feature URL. A host that deliberately installs a feature
12
+ is trusting it, the way it trusts any dependency; the controls exist to bound a trusted
13
+ feature's bad day, not to treat its authors as hostile.
14
+ - **Origin checks authenticate rooms, not speakers.** Once arbitrary script runs inside a page, no
15
+ message check distinguishes it from the application. Threats inside a page need Content Security
16
+ Policy, Trusted Types, dependency provenance, and server-side authorisation. That is a different
17
+ treatment, deliberately outside this model.
18
+ - **Three parties carry the security of an integration.** The browser enforces document isolation
19
+ and the frame's capability attributes; the protocol enforces the relationship (pinned
20
+ counterparts, gated handshake, validated payloads, versioned contracts, an optional encrypted
21
+ envelope); and **you** decide authorisation: `frame-ancestors`, backend checks, HTTPS, the
22
+ envelope you choose, and the containment posture you set.
23
+
24
+ A vulnerability report is most useful when it names which of those three the issue defeats.
25
+
3
26
  ## Reporting a Vulnerability
4
27
 
5
28
  We take the security of hyperfrontend seriously. If you discover a security vulnerability, please help us protect our users by following responsible disclosure practices.
@@ -58,14 +81,30 @@ Thank you for helping keep hyperfrontend and its users safe!
58
81
 
59
82
  ## Security Best Practices
60
83
 
61
- When using hyperfrontend in your applications:
62
-
63
- 1. **Keep Dependencies Updated**: Regularly update to the latest version to receive security patches
64
- 2. **Content Security Policy**: Implement appropriate CSP headers when embedding features
65
- 3. **Input Validation**: Validate and sanitize all data passed between features
66
- 4. **Origin Verification**: Always verify the origin of messages in cross-frame communication
67
- 5. **Authentication**: Implement proper authentication and authorization for sensitive features
68
- 6. **HTTPS**: Always serve hyperfrontend features over HTTPS in production
84
+ These are the decisions the SDK cannot make for you. Everything the protocol already enforces —
85
+ origin pinning, window binding, instance identity, the gated handshake, payload validation on both
86
+ ends is on by default and is not something you should be re-implementing by hand.
87
+
88
+ 1. **Restrict who may embed the feature.** Send
89
+ `Content-Security-Policy: frame-ancestors <hosts>` on the response that serves the feature
90
+ document. Origin pinning keeps a conversation consistent; only `frame-ancestors` decides whether
91
+ a page was ever allowed to frame you.
92
+ 2. **Authorise on the server.** A message that crossed the boundary is not an authorised operation.
93
+ Protected work needs credentials the feature's own backend validates.
94
+ 3. **Choose the envelope deliberately.** `v2` with a pre-shared key is the confidentiality control;
95
+ `v1` is time-window obfuscation and buys deterrence only. Provision and rotate the `v2` key
96
+ yourself; a key is never baked into a built artifact. A handshake that cannot agree on an
97
+ encrypted transport falls back to plaintext; where that would be unacceptable, drive
98
+ `@hyperfrontend/nexus` directly and set `security.mode: 'fail-closed'` on the channel so the
99
+ connection is denied instead.
100
+ 4. **Declare schemas and a contract version.** Actions without a schema pass unvalidated, and a side
101
+ without a version always passes the compatibility gate. Both are how drift is caught early.
102
+ 5. **Grant capability narrowly.** Delegate only the Permissions-Policy features the integration
103
+ needs, and price a `sandbox` posture against what the product actually requires.
104
+ 6. **Serve everything over HTTPS**, host and feature alike.
105
+ 7. **Keep dependencies updated** on both sides of the boundary, and pair that with the page-integrity
106
+ controls this model deliberately leaves to you: Content Security Policy, Trusted Types,
107
+ Subresource Integrity, and dependency provenance.
69
108
 
70
109
  ## Security Updates
71
110
 
@@ -73,10 +112,6 @@ Security updates will be released as patch versions and documented in the [CHANG
73
112
 
74
113
  ## Supported Versions
75
114
 
76
- We currently provide security updates for:
77
-
78
- | Version | Supported |
79
- | ------- | ------------------ |
80
- | 0.0.x | :white_check_mark: |
81
-
82
- As the project matures, we will update this table to reflect our long-term support policy.
115
+ Security updates are provided for the latest published version of each `@hyperfrontend/*` package.
116
+ Older releases receive no backports. A long-term support policy will replace this section once the
117
+ packages settle on a stable release cadence.
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ const _Date = globalThis.Date;
4
+ const _Reflect = globalThis.Reflect;
5
+ function createDate(...args) {
6
+ return _Reflect.construct(_Date, args);
7
+ }
8
+ const dateNow = _Date.now;
9
+ exports.createDate = createDate;
10
+ exports.dateNow = dateNow;
@@ -0,0 +1,8 @@
1
+ const _Date = globalThis.Date;
2
+ const _Reflect = globalThis.Reflect;
3
+ function createDate(...args) {
4
+ return _Reflect.construct(_Date, args);
5
+ }
6
+ const dateNow = _Date.now;
7
+
8
+ export { createDate, dateNow };
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ const _Error = globalThis.Error;
4
+ const _Reflect = globalThis.Reflect;
5
+ const createError = (message, options) => _Reflect.construct(_Error, [message, options]);
6
+ exports.createError = createError;
@@ -0,0 +1,5 @@
1
+ const _Error = globalThis.Error;
2
+ const _Reflect = globalThis.Reflect;
3
+ const createError = (message, options) => _Reflect.construct(_Error, [message, options]);
4
+
5
+ export { createError };
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const _Math = globalThis.Math;
4
+ const floor = _Math.floor;
5
+ exports.floor = floor;
@@ -0,0 +1,4 @@
1
+ const _Math = globalThis.Math;
2
+ const floor = _Math.floor;
3
+
4
+ export { floor };
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+ const _isNaN = globalThis.isNaN;
3
+ const globalIsNaN = _isNaN;
4
+ exports.globalIsNaN = globalIsNaN;
@@ -0,0 +1,5 @@
1
+
2
+ const _isNaN = globalThis.isNaN;
3
+ const globalIsNaN = _isNaN;
4
+
5
+ export { globalIsNaN };
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const _Object = globalThis.Object;
4
+ const freeze = _Object.freeze;
5
+ exports.freeze = freeze;
@@ -0,0 +1,4 @@
1
+ const _Object = globalThis.Object;
2
+ const freeze = _Object.freeze;
3
+
4
+ export { freeze };
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ const _Promise = globalThis.Promise;
4
+ const _Reflect = globalThis.Reflect;
5
+ const createPromise = (executor) => _Reflect.construct(_Promise, [executor]);
6
+ exports.createPromise = createPromise;
@@ -0,0 +1,5 @@
1
+ const _Promise = globalThis.Promise;
2
+ const _Reflect = globalThis.Reflect;
3
+ const createPromise = (executor) => _Reflect.construct(_Promise, [executor]);
4
+
5
+ export { createPromise };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const _setTimeout = globalThis.setTimeout;
4
+ const _setInterval = globalThis.setInterval;
5
+ const _clearTimeout = globalThis.clearTimeout;
6
+ const _clearInterval = globalThis.clearInterval;
7
+ const setTimeout = (callback, delay, ...args) => _setTimeout(callback, delay, ...args);
8
+ const setInterval = (callback, delay, ...args) => _setInterval(callback, delay, ...args);
9
+ const clearTimeout = (id) => {
10
+ _clearTimeout(id);
11
+ };
12
+ const clearInterval = (id) => {
13
+ _clearInterval(id);
14
+ };
15
+ exports.clearInterval = clearInterval;
16
+ exports.clearTimeout = clearTimeout;
17
+ exports.setInterval = setInterval;
18
+ exports.setTimeout = setTimeout;
@@ -0,0 +1,14 @@
1
+ const _setTimeout = globalThis.setTimeout;
2
+ const _setInterval = globalThis.setInterval;
3
+ const _clearTimeout = globalThis.clearTimeout;
4
+ const _clearInterval = globalThis.clearInterval;
5
+ const setTimeout = (callback, delay, ...args) => _setTimeout(callback, delay, ...args);
6
+ const setInterval = (callback, delay, ...args) => _setInterval(callback, delay, ...args);
7
+ const clearTimeout = (id) => {
8
+ _clearTimeout(id);
9
+ };
10
+ const clearInterval = (id) => {
11
+ _clearInterval(id);
12
+ };
13
+
14
+ export { clearInterval, clearTimeout, setInterval, setTimeout };
@@ -1,102 +1,29 @@
1
1
  var HyperfrontendTimeUtils = (function (exports) {
2
2
  'use strict';
3
3
 
4
- /**
5
- * Safe copies of Date built-in via factory function and static methods.
6
- *
7
- * Since constructors cannot be safely captured via Object.assign, this module
8
- * provides a factory function that uses Reflect.construct internally.
9
- *
10
- * These references are captured at module initialization time to protect against
11
- * prototype pollution attacks. Import only what you need for tree-shaking.
12
- *
13
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/date
14
- */
15
- // Capture references at module initialization time
16
4
  const _Date = globalThis.Date;
17
5
  const _Reflect$2 = globalThis.Reflect;
18
6
  function createDate(...args) {
19
7
  return _Reflect$2.construct(_Date, args);
20
8
  }
21
- /**
22
- * (Safe copy) Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
23
- */
24
9
  const dateNow = _Date.now;
25
10
 
26
- /**
27
- * Safe copies of Object built-in methods.
28
- *
29
- * These references are captured at module initialization time to protect against
30
- * prototype pollution attacks. Import only what you need for tree-shaking.
31
- *
32
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/object
33
- */
34
- // Capture references at module initialization time
35
11
  const _Object = globalThis.Object;
36
- /**
37
- * (Safe copy) Prevents modification of existing property attributes and values,
38
- * and prevents the addition of new properties.
39
- */
40
12
  const freeze = _Object.freeze;
41
13
 
42
- /**
43
- * Safe copies of Timer/Scheduling built-in functions.
44
- *
45
- * These references are captured at module initialization time to protect against
46
- * prototype pollution attacks. Import only what you need for tree-shaking.
47
- *
48
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/timers
49
- */
50
- // Capture references at module initialization time
51
14
  const _setTimeout = globalThis.setTimeout;
52
15
  const _setInterval = globalThis.setInterval;
53
16
  const _clearTimeout = globalThis.clearTimeout;
54
17
  const _clearInterval = globalThis.clearInterval;
55
- /**
56
- * (Safe copy) Sets a timer which executes a function once the timer expires.
57
- *
58
- * @param callback - Function to call when the timer elapses.
59
- * @param delay - Time in milliseconds before executing.
60
- * @param args - Additional arguments to pass to the callback.
61
- * @returns A numeric ID for the timer.
62
- */
63
18
  const setTimeout = (callback, delay, ...args) => _setTimeout(callback, delay, ...args);
64
- /**
65
- * (Safe copy) Repeatedly calls a function with a fixed time delay between each call.
66
- *
67
- * @param callback - Function to call at each interval.
68
- * @param delay - Time in milliseconds between calls.
69
- * @param args - Additional arguments to pass to the callback.
70
- * @returns A numeric ID for the interval.
71
- */
72
19
  const setInterval = (callback, delay, ...args) => _setInterval(callback, delay, ...args);
73
- /**
74
- * (Safe copy) Cancels a timeout previously established by setTimeout.
75
- *
76
- * @param id - The identifier of the timeout to cancel.
77
- */
78
20
  const clearTimeout = (id) => {
79
21
  _clearTimeout(id);
80
22
  };
81
- /**
82
- * (Safe copy) Cancels a timed, repeating action previously established by setInterval.
83
- *
84
- * @param id - The identifier of the interval to cancel.
85
- */
86
23
  const clearInterval = (id) => {
87
24
  _clearInterval(id);
88
25
  };
89
26
 
90
- /**
91
- * Creates an interval loop that invokes one or more subscribed callback functions
92
- * at the specified internal (in milliseconds).
93
- *
94
- * Allows you to start or stop the interval loop, much like a stop watch.
95
- * Allows you to unsubscribe callback functions.
96
- *
97
- * @param interval - Time in milliseconds between each callback invocation (default: 1000ms)
98
- * @returns A Clock instance with start, stop, subscribe, and unsubscribe methods
99
- */
100
27
  function createClock(interval = 1000) {
101
28
  let clockId = null;
102
29
  let subscribers = [];
@@ -123,14 +50,6 @@ var HyperfrontendTimeUtils = (function (exports) {
123
50
  return freeze({ start, stop, subscribe, unsubscribe, interval });
124
51
  }
125
52
 
126
- /**
127
- * Invokes callback function after the designated time has passed, much like a timer.
128
- * Allows you to pause, resume, or reset the progress of time tracked.
129
- *
130
- * @param callback - The function to invoke after the delay
131
- * @param delay - Time in milliseconds to wait until callback is invoked
132
- * @returns A Timer instance with pause, resume, and reset methods
133
- */
134
53
  function createTimer(callback, delay) {
135
54
  let timerId = null;
136
55
  let start = null;
@@ -139,7 +58,6 @@ var HyperfrontendTimeUtils = (function (exports) {
139
58
  if (timerId !== null) {
140
59
  clearTimeout(timerId);
141
60
  const now = dateNow();
142
- /* istanbul ignore else - start is always set when timerId is not null */
143
61
  if (start !== null) {
144
62
  remaining -= now - start;
145
63
  }
@@ -163,70 +81,16 @@ var HyperfrontendTimeUtils = (function (exports) {
163
81
  return freeze({ pause, resume, reset });
164
82
  }
165
83
 
166
- /**
167
- * Safe copies of Error built-ins via factory functions.
168
- *
169
- * Since constructors cannot be safely captured via Object.assign, this module
170
- * provides factory functions that use Reflect.construct internally.
171
- *
172
- * These references are captured at module initialization time to protect against
173
- * prototype pollution attacks. Import only what you need for tree-shaking.
174
- *
175
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/error
176
- */
177
- // Capture references at module initialization time
178
84
  const _Error = globalThis.Error;
179
85
  const _Reflect$1 = globalThis.Reflect;
180
- /**
181
- * (Safe copy) Creates a new Error using the captured Error constructor.
182
- * Use this instead of `new Error()`.
183
- *
184
- * @param message - Optional error message.
185
- * @param options - Optional error options.
186
- * @returns A new Error instance.
187
- */
188
86
  const createError = (message, options) => _Reflect$1.construct(_Error, [message, options]);
189
87
 
190
- /**
191
- * Safe copies of Math built-in methods.
192
- *
193
- * These references are captured at module initialization time to protect against
194
- * prototype pollution attacks. Import only what you need for tree-shaking.
195
- *
196
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/math
197
- */
198
- // Capture references at module initialization time
199
88
  const _Math = globalThis.Math;
200
- /**
201
- * (Safe copy) Returns the largest integer less than or equal to a number.
202
- */
203
89
  const floor = _Math.floor;
204
90
 
205
- /**
206
- * Safe copies of Number built-in methods and constants.
207
- *
208
- * These references are captured at module initialization time to protect against
209
- * prototype pollution attacks. Import only what you need for tree-shaking.
210
- *
211
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/number
212
- */
213
- // Capture references at module initialization time
214
91
  const _isNaN = globalThis.isNaN;
215
- // ============================================================================
216
- // Global Type Checking (legacy, less strict)
217
- // ============================================================================
218
- /**
219
- * (Safe copy) Global isNaN function (coerces to number first, less strict than Number.isNaN).
220
- */
221
92
  const globalIsNaN = _isNaN;
222
93
 
223
- /**
224
- * Normalizes a given time to the nearest base time window.
225
- *
226
- * @param time - The Date object to normalize to the nearest time window
227
- * @param baseTimeWindow - The size of the time window in minutes for normalization
228
- * @returns A new Date object normalized to the start of the time window
229
- */
230
94
  function normalizeToBaseTimeWindow(time, baseTimeWindow) {
231
95
  if (!time || !(time instanceof Date) || globalIsNaN(time.getTime())) {
232
96
  throw createError('Invalid time input');
@@ -240,77 +104,22 @@ var HyperfrontendTimeUtils = (function (exports) {
240
104
  return createDate(normalizedTimeInMs);
241
105
  }
242
106
 
243
- /**
244
- * Creates a repeating interval that invokes a callback function at regular intervals.
245
- *
246
- * @param callback - The function to invoke at each interval
247
- * @param interval - Time in milliseconds between each callback invocation
248
- * @returns A cleanup function that stops the interval when called
249
- */
250
107
  function setIntervalCallback(callback, interval) {
251
108
  const timerId = setInterval(callback, interval);
252
109
  return () => clearInterval(timerId);
253
110
  }
254
111
 
255
- /**
256
- * Safe copies of Promise built-in methods via factory functions.
257
- *
258
- * Since constructors cannot be safely captured via Object.assign, this module
259
- * provides factory functions that use Reflect.construct internally.
260
- *
261
- * These references are captured at module initialization time to protect against
262
- * prototype pollution attacks. Import only what you need for tree-shaking.
263
- *
264
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/promise
265
- */
266
- // Capture references at module initialization time
267
112
  const _Promise = globalThis.Promise;
268
113
  const _Reflect = globalThis.Reflect;
269
- /**
270
- * (Safe copy) Creates a new Promise using the captured Promise constructor.
271
- * Use this instead of `new Promise()`.
272
- *
273
- * @param executor - The executor function.
274
- * @returns A new Promise instance.
275
- */
276
114
  const createPromise = (executor) => _Reflect.construct(_Promise, [executor]);
277
- /**
278
- * (Safe copy) Returns a Promise that resolves with the given value.
279
- */
280
115
  _Promise.resolve.bind(_Promise);
281
- /**
282
- * (Safe copy) Returns a Promise that rejects with the given reason.
283
- */
284
116
  _Promise.reject.bind(_Promise);
285
- /**
286
- * (Safe copy) Returns a Promise that resolves when all promises resolve.
287
- */
288
117
  _Promise.all.bind(_Promise);
289
- /**
290
- * (Safe copy) Returns a Promise that resolves/rejects with the first settled promise.
291
- */
292
118
  _Promise.race.bind(_Promise);
293
- /**
294
- * (Safe copy) Returns a Promise that resolves when all promises settle.
295
- */
296
119
  _Promise.allSettled.bind(_Promise);
297
- /**
298
- * (Safe copy) Returns a Promise that resolves with the first fulfilled promise.
299
- */
300
120
  _Promise.any.bind(_Promise);
301
- /**
302
- * (Safe copy) Creates a Promise along with its resolve and reject functions.
303
- * Note: Available only in ES2024+ environments.
304
- */
305
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
306
121
  _Promise.withResolvers?.bind(_Promise);
307
122
 
308
- /**
309
- * Pauses execution for a specified duration.
310
- *
311
- * @param milliseconds - The duration to sleep in milliseconds
312
- * @returns A promise that resolves after the specified duration
313
- */
314
123
  function sleep(milliseconds) {
315
124
  return createPromise((resolve) => setTimeout(resolve, milliseconds));
316
125
  }
@@ -324,4 +133,3 @@ var HyperfrontendTimeUtils = (function (exports) {
324
133
  return exports;
325
134
 
326
135
  })({});
327
- //# sourceMappingURL=index.iife.js.map
@@ -1,2 +1 @@
1
1
  var HyperfrontendTimeUtils=function(e){"use strict";const l=globalThis.Date,t=globalThis.Reflect;function n(...e){return t.construct(l,e)}const i=l.now,o=globalThis.Object.freeze,s=globalThis.setTimeout,r=globalThis.setInterval,a=globalThis.clearTimeout,c=globalThis.clearInterval,u=(e,l,...t)=>s(e,l,...t),b=(e,l,...t)=>r(e,l,...t),T=e=>{c(e)};const f=globalThis.Error,h=globalThis.Reflect,g=(e,l)=>h.construct(f,[e,l]),m=globalThis.Math.floor,d=globalThis.isNaN;const v=globalThis.Promise,p=globalThis.Reflect;return v.resolve.bind(v),v.reject.bind(v),v.all.bind(v),v.race.bind(v),v.allSettled.bind(v),v.any.bind(v),v.withResolvers?.bind(v),e.createClock=function(e=1e3){let l=null,t=[];return o({start:()=>{null===l&&(l=b(()=>{const e=n();t.forEach(l=>l(e))},e))},stop:()=>{null!==l&&(T(l),l=null)},subscribe:e=>{t.push(e)},unsubscribe:e=>{t=t.filter(l=>l!==e)},interval:e})},e.createTimer=function(e,l){let t=null,n=null,s=l;const r=()=>{if(null!==t){a(t);const e=i();null!==n&&(s-=e-n),t=null}},c=()=>{null===t&&(n=i(),t=u(()=>{e(),t=null},s))};return o({pause:r,resume:c,reset:(e=l)=>{r(),s=e,c()}})},e.normalizeToBaseTimeWindow=function(e,l){if(!e||!(e instanceof Date)||d(e.getTime()))throw g("Invalid time input");if(l<=0)throw g("Base time window must be positive");const t=e.getTime(),i=60*l*1e3;return n(m(t/i)*i)},e.setIntervalCallback=function(e,l){const t=b(e,l);return()=>T(t)},e.sleep=function(e){return l=l=>u(l,e),p.construct(v,[l]);var l},e}({});
2
- //# sourceMappingURL=index.iife.min.js.map