@alwatr/delay 7.0.2 → 9.1.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.
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
- /* 📦 @alwatr/delay v7.0.2 */
1
+ /* 📦 @alwatr/delay v9.1.0 */
2
2
  import{parseDuration as O}from"@alwatr/parse-duration";import{getGlobalThis as M}from"@alwatr/global-this";var H=M(),K=H.requestAnimationFrame?.bind(H)??((z)=>setTimeout(()=>z(performance.now()),16.666666666666668)),L=H.requestIdleCallback?.bind(H)??((z,B)=>{let E=Date.now();return setTimeout(()=>{z({didTimeout:!!B?.timeout,timeRemaining:()=>Math.max(0,50-(Date.now()-E))})},B?.timeout??20)});var U={by:(z)=>new Promise((B)=>setTimeout(B,O(z))),animationFrame:()=>new Promise((z)=>K(z)),idleCallback:(z)=>new Promise((B)=>L(B,z)),domEvent:(z,B,E={passive:!0})=>new Promise((J)=>z.addEventListener(B,J,{...E,once:!0})),event:(z,B,E={passive:!0})=>new Promise((J)=>z.addEventListener(B,J,{...E,once:!0})),nextMacrotask:()=>new Promise((z)=>setTimeout(z,0)),nextMicrotask:()=>Promise.resolve().then(()=>{})};export{L as requestIdleCallback,K as requestAnimationFrame,U as delay};
3
3
 
4
- //# debugId=B6B9E258C074F60064756E2164756E21
4
+ //# debugId=A379502355A64EF764756E2164756E21
5
5
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -3,9 +3,9 @@
3
3
  "sources": ["../src/main.ts", "../src/polyfill.ts"],
4
4
  "sourcesContent": [
5
5
  "import {parseDuration, type Duration} from '@alwatr/parse-duration';\n\nimport {requestAnimationFrame, requestIdleCallback} from './polyfill.js';\n\nexport {requestAnimationFrame, requestIdleCallback};\n\n/**\n * A utility module to help manage asynchronous operations and waiting for events or timeouts.\n */\nexport const delay = {\n /**\n * Pauses execution for a specified duration.\n *\n * @param duration The duration to wait. Can be a number in milliseconds or a string like '2s', '100ms'.\n * @returns A Promise that resolves after the specified duration.\n *\n * @example\n * ```typescript\n * await delay.by('1m'); // Wait for 1 minute\n * await delay.by('2s'); // Wait for 2 seconds\n * ```\n */\n by: (duration: Duration): Promise<void> => new Promise((resolve) => setTimeout(resolve, parseDuration(duration))),\n\n /**\n * Pauses execution until the next animation frame.\n *\n * @returns A Promise that resolves with the high-resolution timestamp of the next animation frame.\n *\n * @example\n * ```typescript\n * const timestamp = await delay.animationFrame();\n * console.log(`Next frame at ${timestamp}`);\n * ```\n */\n animationFrame: (): Promise<DOMHighResTimeStamp> => new Promise((resolve) => requestAnimationFrame(resolve)),\n\n /**\n * Pauses execution until the browser is idle.\n *\n * @param timeout An optional maximum duration to wait.\n * @returns A Promise that resolves with an `IdleDeadline` object.\n *\n * @example\n * ```typescript\n * const deadline = await delay.idleCallback({ timeout: 2000 });\n * if (deadline.didTimeout) {\n * console.log('Idle callback timed out.');\n * }\n * ```\n */\n idleCallback: (options?: IdleRequestOptions): Promise<IdleDeadline> => new Promise((resolve) => requestIdleCallback(resolve, options)),\n\n /**\n * Pauses execution until a specific DOM event is dispatched on an element.\n *\n * @param element The HTMLElement to listen on.\n * @param eventName The name of the event to wait for.\n * @param options Optional event listener options.\n * @template T The event map type for the element.\n * @returns A Promise that resolves with the triggered event object.\n *\n * @example\n * ```typescript\n * const button = document.getElementById('my-button');\n * if (button) {\n * const clickEvent = await delay.domEvent(button, 'click');\n * console.log('Button clicked!', clickEvent);\n * }\n * ```\n */\n domEvent: <T extends keyof HTMLElementEventMap>(\n element: HTMLElement,\n eventName: T,\n options: AddEventListenerOptions = {passive: true},\n ): Promise<HTMLElementEventMap[T]> =>\n new Promise((resolve) =>\n element.addEventListener(eventName, resolve, {\n ...options,\n once: true,\n }),\n ),\n\n /**\n * Pauses execution until a specific event is dispatched on any event target.\n *\n * @param target The event target (e.g., window, document, or a custom event emitter).\n * @param eventName The name of the event to wait for.\n * @param options Optional event listener options.\n * @returns A Promise that resolves with the triggered event object.\n *\n * @example\n * ```typescript\n * const resizeEvent = await delay.event(window, 'resize');\n * console.log('Window resized:', resizeEvent);\n * ```\n */\n event: (target: EventTarget, eventName: string, options: AddEventListenerOptions = {passive: true}): Promise<Event> =>\n new Promise((resolve) =>\n target.addEventListener(eventName, resolve, {\n ...options,\n once: true,\n }),\n ),\n\n /**\n * Schedules a macrotask to run after the current event loop task completes.\n * Uses `setTimeout(..., 0)`.\n *\n * @returns A Promise that resolves when the macrotask is executed.\n *\n * @example\n * ```typescript\n * console.log('Start');\n * await delay.nextMacrotask();\n * console.log('End - after current task');\n * ```\n */\n nextMacrotask: (): Promise<void> => new Promise((resolve) => setTimeout(resolve, 0)),\n\n /**\n * Queues a microtask to run after the current task completes but before the next macrotask.\n *\n * @returns A Promise that resolves when the microtask is executed.\n *\n * @example\n * ```typescript\n * console.log('Start');\n * await delay.nextMicrotask();\n * console.log('End - immediately after current task');\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n nextMicrotask: (): Promise<void> => Promise.resolve().then(() => {}),\n} as const;\n",
6
- "import {getGlobalThis} from '@alwatr/global-this';\n\nimport type {} from '@alwatr/type-helper';\n\nconst globalThis = getGlobalThis<DictionaryOpt<unknown>>();\n\n/**\n * Ensures compatibility for `requestAnimationFrame` by using the native API\n * available in `globalThis`. If it's not available, it falls back to a `setTimeout`\n * call that aims for a 60 frames per second refresh rate.\n *\n * @param callback The function to call when it's time to update your animation for the next repaint.\n * @returns A long integer value, the request ID, that uniquely identifies the entry in the callback list.\n */\nexport const requestAnimationFrame: (callback: FrameRequestCallback) => number =\n globalThis.requestAnimationFrame?.bind(globalThis) ??\n ((callback: FrameRequestCallback) => setTimeout(() => callback(performance.now()), 1000 / 60));\n\n/**\n * Ensures compatibility for `requestIdleCallback` by using the native API.\n * If unavailable, it falls back to a `setTimeout` that executes the callback\n * after a short delay, providing a mock `IdleDeadline` object.\n *\n * The mock `IdleDeadline` gives the task a 50ms budget to run.\n *\n * @param callback A reference to a function that should be called in the near future, when the event loop is idle.\n * @param options An optional object with configuration parameters.\n * @returns An ID which can be used to cancel the callback by calling `cancelIdleCallback()`.\n */\nexport const requestIdleCallback: (callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions) => number =\n globalThis.requestIdleCallback?.bind(globalThis) ??\n ((\n callback: (deadline: IdleDeadline) => void,\n // options is not used in the fallback but kept for API consistency\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n options?: IdleRequestOptions,\n ) => {\n const startTime = Date.now();\n return setTimeout(() => {\n callback({\n didTimeout: !!options?.timeout,\n timeRemaining: () => Math.max(0, 50 - (Date.now() - startTime)),\n });\n }, options?.timeout ?? 20);\n });\n"
6
+ "import {getGlobalThis} from '@alwatr/global-this';\n\n\nconst globalThis = getGlobalThis<DictionaryOpt<unknown>>();\n\n/**\n * Ensures compatibility for `requestAnimationFrame` by using the native API\n * available in `globalThis`. If it's not available, it falls back to a `setTimeout`\n * call that aims for a 60 frames per second refresh rate.\n *\n * @param callback The function to call when it's time to update your animation for the next repaint.\n * @returns A long integer value, the request ID, that uniquely identifies the entry in the callback list.\n */\nexport const requestAnimationFrame: (callback: FrameRequestCallback) => number =\n globalThis.requestAnimationFrame?.bind(globalThis) ??\n ((callback: FrameRequestCallback) => setTimeout(() => callback(performance.now()), 1000 / 60));\n\n/**\n * Ensures compatibility for `requestIdleCallback` by using the native API.\n * If unavailable, it falls back to a `setTimeout` that executes the callback\n * after a short delay, providing a mock `IdleDeadline` object.\n *\n * The mock `IdleDeadline` gives the task a 50ms budget to run.\n *\n * @param callback A reference to a function that should be called in the near future, when the event loop is idle.\n * @param options An optional object with configuration parameters.\n * @returns An ID which can be used to cancel the callback by calling `cancelIdleCallback()`.\n */\nexport const requestIdleCallback: (callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions) => number =\n globalThis.requestIdleCallback?.bind(globalThis) ??\n ((\n callback: (deadline: IdleDeadline) => void,\n // options is not used in the fallback but kept for API consistency\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n options?: IdleRequestOptions,\n ) => {\n const startTime = Date.now();\n return setTimeout(() => {\n callback({\n didTimeout: !!options?.timeout,\n timeRemaining: () => Math.max(0, 50 - (Date.now() - startTime)),\n });\n }, options?.timeout ?? 20);\n });\n"
7
7
  ],
8
- "mappings": ";AAAA,wBAAQ,+BCAR,wBAAQ,4BAIR,IAAM,EAAa,EAAsC,EAU5C,EACX,EAAW,uBAAuB,KAAK,CAAU,IAChD,CAAC,IAAmC,WAAW,IAAM,EAAS,YAAY,IAAI,CAAC,EAAG,kBAAS,GAajF,EACX,EAAW,qBAAqB,KAAK,CAAU,IAC9C,CACC,EAGA,IACG,CACH,IAAM,EAAY,KAAK,IAAI,EAC3B,OAAO,WAAW,IAAM,CACtB,EAAS,CACP,WAAY,CAAC,CAAC,GAAS,QACvB,cAAe,IAAM,KAAK,IAAI,EAAG,IAAM,KAAK,IAAI,EAAI,EAAU,CAChE,CAAC,GACA,GAAS,SAAW,EAAE,IDlCtB,IAAM,EAAQ,CAanB,GAAI,CAAC,IAAsC,IAAI,QAAQ,CAAC,IAAY,WAAW,EAAS,EAAc,CAAQ,CAAC,CAAC,EAahH,eAAgB,IAAoC,IAAI,QAAQ,CAAC,IAAY,EAAsB,CAAO,CAAC,EAgB3G,aAAc,CAAC,IAAwD,IAAI,QAAQ,CAAC,IAAY,EAAoB,EAAS,CAAO,CAAC,EAoBrI,SAAU,CACR,EACA,EACA,EAAmC,CAAC,QAAS,EAAI,IAEjD,IAAI,QAAQ,CAAC,IACX,EAAQ,iBAAiB,EAAW,EAAS,IACxC,EACH,KAAM,EACR,CAAC,CACH,EAgBF,MAAO,CAAC,EAAqB,EAAmB,EAAmC,CAAC,QAAS,EAAI,IAC/F,IAAI,QAAQ,CAAC,IACX,EAAO,iBAAiB,EAAW,EAAS,IACvC,EACH,KAAM,EACR,CAAC,CACH,EAeF,cAAe,IAAqB,IAAI,QAAQ,CAAC,IAAY,WAAW,EAAS,CAAC,CAAC,EAenF,cAAe,IAAqB,Q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  "names": []
11
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,MAEwB,CAAC;AAEjG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,kBAAkB,KAAK,MAe5G,CAAC"}
1
+ {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,MAEwB,CAAC;AAEjG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,kBAAkB,KAAK,MAe5G,CAAC"}
package/package.json CHANGED
@@ -1,34 +1,34 @@
1
1
  {
2
2
  "name": "@alwatr/delay",
3
- "version": "7.0.2",
3
+ "version": "9.1.0",
4
4
  "description": "Comprehensive toolkit for managing asynchronous operations.",
5
5
  "license": "MPL-2.0",
6
- "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
+ "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
7
7
  "type": "module",
8
8
  "repository": {
9
- "directory": "packages/delay",
10
9
  "type": "git",
11
- "url": "https://github.com/Alwatr/nanolib"
10
+ "url": "https://github.com/Alwatr/alwatr",
11
+ "directory": "pkg/nanolib/delay"
12
12
  },
13
- "homepage": "https://github.com/Alwatr/nanolib/tree/next/packages/delay#readme",
14
- "bugs": "https://github.com/Alwatr/nanolib/issues",
13
+ "homepage": "https://github.com/Alwatr/alwatr/tree/main/pkg/nanolib/delay#readme",
14
+ "bugs": "https://github.com/Alwatr/alwatr/issues",
15
15
  "exports": {
16
16
  ".": {
17
17
  "types": "./dist/main.d.ts",
18
+ "import": "./dist/main.js",
18
19
  "default": "./dist/main.js"
19
20
  }
20
21
  },
21
22
  "sideEffects": false,
22
23
  "dependencies": {
23
- "@alwatr/global-this": "6.0.2",
24
- "@alwatr/parse-duration": "6.0.2"
24
+ "@alwatr/global-this": "9.1.0",
25
+ "@alwatr/parse-duration": "9.1.0"
25
26
  },
26
27
  "devDependencies": {
27
- "@alwatr/nano-build": "7.0.1",
28
- "@alwatr/prettier-config": "7.0.1",
29
- "@alwatr/tsconfig-base": "8.0.0",
30
- "@alwatr/type-helper": "8.0.2",
31
- "@types/node": "^24.12.0",
28
+ "@alwatr/nano-build": "9.1.0",
29
+ "@alwatr/tsconfig-base": "9.1.0",
30
+ "@alwatr/type-helper": "9.1.0",
31
+ "@types/node": "^25.5.0",
32
32
  "typescript": "^6.0.2"
33
33
  },
34
34
  "scripts": {
@@ -36,21 +36,23 @@
36
36
  "build": "bun run build:ts && bun run build:es",
37
37
  "build:es": "nano-build --preset=module src/main.ts",
38
38
  "build:ts": "tsc --build",
39
- "c": "bun run clean",
40
- "cb": "bun run clean && bun run build",
39
+ "cl": "bun run clean",
41
40
  "clean": "rm -rfv dist *.tsbuildinfo",
42
- "d": "bun run build:es && bun",
41
+ "format": "prettier --write \"src/**/*.ts\"",
42
+ "lint": "eslint src/ --ext .ts",
43
+ "t": "bun run test",
44
+ "test": "ALWATR_DEBUG=0 bun test",
43
45
  "w": "bun run watch",
44
46
  "watch": "bun run watch:ts & bun run watch:es",
45
47
  "watch:es": "bun run build:es --watch",
46
48
  "watch:ts": "bun run build:ts --watch --preserveWatchOutput"
47
49
  },
48
50
  "files": [
49
- "**/*.{js,mjs,cjs,ts,map,d.ts,html,LEGAL.txt}",
51
+ "dist",
52
+ "src/**/*.ts",
53
+ "!src/**/*.test.ts",
50
54
  "README.md",
51
- "LICENSE",
52
- "!demo/**/*",
53
- "!**/*.test.js"
55
+ "LICENSE"
54
56
  ],
55
57
  "publishConfig": {
56
58
  "access": "public"
@@ -74,6 +76,5 @@
74
76
  "utils",
75
77
  "wait"
76
78
  ],
77
- "prettier": "@alwatr/prettier-config",
78
- "gitHead": "95bb13efd0a5f485c6b09f1a911b99492017aed1"
79
+ "gitHead": "4a25cd3e0499cf61dd761e87d3711abf9b0cd208"
79
80
  }
package/src/polyfill.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import {getGlobalThis} from '@alwatr/global-this';
2
2
 
3
- import type {} from '@alwatr/type-helper';
4
3
 
5
4
  const globalThis = getGlobalThis<DictionaryOpt<unknown>>();
6
5