mentie 0.3.3 → 0.3.4

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.
package/index.js CHANGED
@@ -6,4 +6,5 @@ export * from './modules/text.js'
6
6
  export * from './modules/numbers.js'
7
7
  export * from './modules/promises.js'
8
8
  export * from './modules/cache.js'
9
- export * from './modules/crypto.js'
9
+ export * from './modules/crypto.js'
10
+ export * from './modules/network.js'
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Signal helper for fetch requests
3
+ *
4
+ * @param {Object} options - Options for the signal
5
+ * @param {number} [options.timeout_ms] - Timeout in milliseconds
6
+ * @returns {Object} signal_data - Object containing fetch options and abort signal
7
+ * @returns {Object} signal_data.fetch_options - Options for usage with fetch requests
8
+ * @returns {AbortController} signal_data.controller - Raw abort controller
9
+ * @returns {Function} signal_data.abort_signal - Function to abort the request
10
+ * @returns {Function} signal_data.abort - Alias for abort_signal
11
+ * @returns {number} signal_data.timeout_id - Timeout ID
12
+ */
13
+ export const timeout_signal = ( { timeout_ms }={} ) => {
14
+
15
+ // Request with timeout
16
+ const controller = new AbortController()
17
+ const timeout_id = timeout_ms && setTimeout( () => {
18
+ controller.abort()
19
+ }, timeout_ms )
20
+
21
+ const fetch_options = {
22
+ signal: controller.signal
23
+ }
24
+
25
+ const abort = () => {
26
+ if( timeout_ms ) clearTimeout( timeout_id )
27
+ controller.abort()
28
+ }
29
+
30
+ return {
31
+ fetch_options,
32
+ controller,
33
+ abort_signal: abort,
34
+ abort,
35
+ timeout_id
36
+ }
37
+
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mentie",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "Mentor's toolbelt",
5
5
  "type": "module",
6
6
  "main": "index.js",