@oscarpalmer/timer 0.41.4 → 0.43.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 (44) hide show
  1. package/README.md +1 -1
  2. package/dist/constants.d.mts +35 -0
  3. package/dist/{constants.js → constants.mjs} +2 -0
  4. package/dist/delay.d.mts +3 -0
  5. package/dist/delay.mjs +2 -0
  6. package/dist/get.d.mts +8 -0
  7. package/dist/{get.js → get.mjs} +3 -1
  8. package/dist/global.d.mts +7 -0
  9. package/dist/{global.js → global.mjs} +4 -1
  10. package/dist/index.d.mts +249 -0
  11. package/dist/{timer.full.js → index.mjs} +84 -55
  12. package/{types/is.d.ts → dist/is.d.mts} +10 -6
  13. package/dist/{is.js → is.mjs} +4 -2
  14. package/dist/models.d.mts +82 -0
  15. package/dist/{models.js → models.mjs} +2 -0
  16. package/dist/repeat.d.mts +13 -0
  17. package/dist/{repeat.js → repeat.mjs} +8 -5
  18. package/dist/timer.d.mts +52 -0
  19. package/dist/{timer.js → timer.mjs} +4 -2
  20. package/{types/wait.d.ts → dist/wait.d.mts} +6 -4
  21. package/dist/{wait.js → wait.mjs} +8 -5
  22. package/dist/when.d.mts +55 -0
  23. package/dist/{when.js → when.mjs} +10 -18
  24. package/dist/work.d.mts +8 -0
  25. package/dist/{work.js → work.mjs} +3 -1
  26. package/package.json +50 -52
  27. package/src/delay.ts +2 -1
  28. package/src/get.ts +1 -1
  29. package/src/is.ts +2 -2
  30. package/src/repeat.ts +1 -0
  31. package/src/wait.ts +1 -0
  32. package/src/when.ts +3 -15
  33. package/dist/delay.js +0 -2
  34. package/dist/index.js +0 -7
  35. package/types/constants.d.ts +0 -31
  36. package/types/delay.d.ts +0 -1
  37. package/types/get.d.ts +0 -4
  38. package/types/global.d.ts +0 -5
  39. package/types/index.d.ts +0 -235
  40. package/types/models.d.ts +0 -78
  41. package/types/repeat.d.ts +0 -11
  42. package/types/timer.d.ts +0 -48
  43. package/types/when.d.ts +0 -62
  44. package/types/work.d.ts +0 -4
@@ -1,26 +1,30 @@
1
- import type { Timer } from './timer';
2
- import type { When } from './when';
1
+ import { Timer } from "./timer.mjs";
2
+ import { When } from "./when.mjs";
3
+
4
+ //#region src/is.d.ts
3
5
  /**
4
6
  * Is the value a repeating timer?
5
7
  * @param value Value to check
6
8
  * @returns `true` if the value is a repeating timer
7
9
  */
8
- export declare function isRepeated(value: unknown): value is Timer;
10
+ declare function isRepeated(value: unknown): value is Timer;
9
11
  /**
10
12
  * Is the value a timer?
11
13
  * @param value Value to check
12
14
  * @returns `true` if the value is a timer
13
15
  */
14
- export declare function isTimer(value: unknown): value is Timer;
16
+ declare function isTimer(value: unknown): value is Timer;
15
17
  /**
16
18
  * Is the value a waiting timer?
17
19
  * @param value Value to check
18
20
  * @returns `true` if the value is a waiting timer
19
21
  */
20
- export declare function isWaited(value: unknown): value is Timer;
22
+ declare function isWaited(value: unknown): value is Timer;
21
23
  /**
22
24
  * Is the value a conditional timer?
23
25
  * @param value Value to check
24
26
  * @returns `true` if the value is a conditional timer
25
27
  */
26
- export declare function isWhen(value: unknown): value is When;
28
+ declare function isWhen(value: unknown): value is When;
29
+ //#endregion
30
+ export { isRepeated, isTimer, isWaited, isWhen };
@@ -1,4 +1,5 @@
1
- import { TYPE_REPEAT, TYPE_WAIT } from "./constants.js";
1
+ import { TYPE_REPEAT, TYPE_WAIT } from "./constants.mjs";
2
+ //#region src/is.ts
2
3
  function is(names, value) {
3
4
  return names.includes(value?.$timer);
4
5
  }
@@ -32,6 +33,7 @@ function isWaited(value) {
32
33
  * @returns `true` if the value is a conditional timer
33
34
  */
34
35
  function isWhen(value) {
35
- return is(["when"], value) && typeof value.then === "function";
36
+ return is(["when"], value) && typeof value.start === "function";
36
37
  }
38
+ //#endregion
37
39
  export { isRepeated, isTimer, isWaited, isWhen };
@@ -0,0 +1,82 @@
1
+ import { Timer } from "./timer.mjs";
2
+
3
+ //#region src/models.d.ts
4
+ /**
5
+ * Options for a repeating timer
6
+ */
7
+ type RepeatOptions = {
8
+ /**
9
+ * Callback to be called when the timer has stopped, either manually or by completing its work
10
+ */
11
+ onAfter: (finished: boolean) => void;
12
+ /**
13
+ * Callback to be called after the timer has timed out
14
+ */
15
+ onTimeout: () => void;
16
+ /**
17
+ * How many times the timer should repeat
18
+ */
19
+ count: number;
20
+ /**
21
+ * The interval between each repeat
22
+ */
23
+ interval: number;
24
+ /**
25
+ * The timeout for the timer _(any value above `0` will enable the timeout)_
26
+ */
27
+ timeout: number;
28
+ };
29
+ type TimerOptions = {
30
+ onAfter: ((finished: boolean) => void) | undefined;
31
+ onError: (() => void) | undefined;
32
+ count: number;
33
+ interval: number;
34
+ timeout: number;
35
+ };
36
+ type TimerState = {
37
+ active: boolean;
38
+ callback: () => void;
39
+ destroyed: boolean;
40
+ elapsed: number;
41
+ frame: number | undefined;
42
+ index: number;
43
+ paused: boolean;
44
+ total: number;
45
+ trace: string | undefined;
46
+ };
47
+ declare class TimerTrace extends Error {
48
+ constructor();
49
+ }
50
+ type TimerType = 'repeat' | 'wait' | 'when';
51
+ /**
52
+ * Options for a conditional timer
53
+ */
54
+ type WhenOptions = {
55
+ /**
56
+ * How many times the timer should check the condition
57
+ */
58
+ count: number;
59
+ /**
60
+ * Then interval between each condtional check
61
+ */
62
+ interval: number;
63
+ /**
64
+ * The timeout for the timer _(any value above `0` will enable the timeout)_
65
+ */
66
+ timeout: number;
67
+ };
68
+ type WhenState = {
69
+ promise: Promise<void>;
70
+ rejecter?: () => void;
71
+ resolver?: () => void;
72
+ started: boolean;
73
+ timer: Timer;
74
+ };
75
+ type WorkHandler = (type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions) => Timer;
76
+ type WorkHandlerTimer = {
77
+ instance: Timer;
78
+ type: TimerType;
79
+ };
80
+ type WorkHandlerType = 'continue' | 'pause' | 'restart' | 'start' | 'stop';
81
+ //#endregion
82
+ export { RepeatOptions, TimerOptions, TimerState, TimerTrace, TimerType, WhenOptions, WhenState, WorkHandler, WorkHandlerTimer, WorkHandlerType };
@@ -1,7 +1,9 @@
1
+ //#region src/models.ts
1
2
  var TimerTrace = class extends Error {
2
3
  constructor() {
3
4
  super();
4
5
  this.name = "TimerTrace";
5
6
  }
6
7
  };
8
+ //#endregion
7
9
  export { TimerTrace };
@@ -0,0 +1,13 @@
1
+ import { Timer } from "./timer.mjs";
2
+ import { RepeatOptions } from "./models.mjs";
3
+ //#region src/repeat.d.ts
4
+ /**
5
+ * Create a repeating timer
6
+ *
7
+ * @param callback Callback to run on each interval
8
+ * @param options Timer options
9
+ * @returns Timer instance
10
+ */
11
+ declare function repeat(callback: (index: number) => void, options?: Partial<RepeatOptions>): Timer;
12
+ //#endregion
13
+ export { type RepeatOptions, type Timer, repeat };
@@ -1,10 +1,12 @@
1
- import { TYPE_REPEAT } from "./constants.js";
2
- import { getCallback, getValidNumber } from "./get.js";
3
- import "./global.js";
4
- import { TimerTrace } from "./models.js";
5
- import { Timer } from "./timer.js";
1
+ import { TYPE_REPEAT } from "./constants.mjs";
2
+ import { getCallback, getValidNumber } from "./get.mjs";
3
+ import "./global.mjs";
4
+ import { TimerTrace } from "./models.mjs";
5
+ import { Timer } from "./timer.mjs";
6
+ //#region src/repeat.ts
6
7
  /**
7
8
  * Create a repeating timer
9
+ *
8
10
  * @param callback Callback to run on each interval
9
11
  * @param options Timer options
10
12
  * @returns Timer instance
@@ -21,4 +23,5 @@ function repeat(callback, options) {
21
23
  timeout: getValidNumber(options?.timeout)
22
24
  }, true);
23
25
  }
26
+ //#endregion
24
27
  export { repeat };
@@ -0,0 +1,52 @@
1
+ import { TimerOptions, TimerState, TimerType } from "./models.mjs";
2
+
3
+ //#region src/timer.d.ts
4
+ declare class Timer {
5
+ #private;
6
+ protected readonly options: TimerOptions;
7
+ private readonly $timer;
8
+ protected readonly state: TimerState;
9
+ /**
10
+ * Is the timer active?
11
+ */
12
+ get active(): boolean;
13
+ /**
14
+ * Is the timer destroyed?
15
+ */
16
+ get destroyed(): boolean;
17
+ /**
18
+ * Is the timer paused?
19
+ */
20
+ get paused(): boolean;
21
+ /**
22
+ * Get the timer's origin _(if debugging is enabled)_
23
+ */
24
+ get trace(): string | undefined;
25
+ constructor(type: TimerType, state: Pick<TimerState, 'callback' | 'trace'>, options: TimerOptions, start: boolean);
26
+ /**
27
+ * Continue running the timer _(if it's paused)_
28
+ */
29
+ continue(): Timer;
30
+ /**
31
+ * Destroy the timer
32
+ */
33
+ destroy(): void;
34
+ /**
35
+ * Pause the timer _(if it's running)_
36
+ */
37
+ pause(): Timer;
38
+ /**
39
+ * Restart the timer _(or start it, if it's not running)_
40
+ */
41
+ restart(): Timer;
42
+ /**
43
+ * Start the timer _(if it's not running)_
44
+ */
45
+ start(): Timer;
46
+ /**
47
+ * Stop the timer _(if it's running)_
48
+ */
49
+ stop(): Timer;
50
+ }
51
+ //#endregion
52
+ export { Timer };
@@ -1,6 +1,7 @@
1
- import { WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP } from "./constants.js";
2
- import { stop, work } from "./work.js";
1
+ import { WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP } from "./constants.mjs";
2
+ import { stop, work } from "./work.mjs";
3
3
  import { noop } from "@oscarpalmer/atoms/function";
4
+ //#region src/timer.ts
4
5
  var Timer = class {
5
6
  state;
6
7
  /**
@@ -93,4 +94,5 @@ var Timer = class {
93
94
  }, this.state, this.options);
94
95
  }
95
96
  };
97
+ //#endregion
96
98
  export { Timer };
@@ -1,9 +1,11 @@
1
- import './global';
2
- import { Timer } from './timer';
1
+ import { Timer } from "./timer.mjs";
2
+ //#region src/wait.d.ts
3
3
  /**
4
4
  * Create a waiting timer
5
+ *
5
6
  * @param callback Callback to run when the timer has finished
6
7
  * @param time How long to wait for _(in milliseconds; defaults to screen refresh rate)_
7
8
  */
8
- export declare function wait(callback: () => void, time?: number): Timer;
9
- export type { Timer };
9
+ declare function wait(callback: () => void, time?: number): Timer;
10
+ //#endregion
11
+ export { type Timer, wait };
@@ -1,10 +1,12 @@
1
- import { TYPE_WAIT } from "./constants.js";
2
- import { getCallback, getValidNumber } from "./get.js";
3
- import "./global.js";
4
- import { TimerTrace } from "./models.js";
5
- import { Timer } from "./timer.js";
1
+ import { TYPE_WAIT } from "./constants.mjs";
2
+ import { getCallback, getValidNumber } from "./get.mjs";
3
+ import "./global.mjs";
4
+ import { TimerTrace } from "./models.mjs";
5
+ import { Timer } from "./timer.mjs";
6
+ //#region src/wait.ts
6
7
  /**
7
8
  * Create a waiting timer
9
+ *
8
10
  * @param callback Callback to run when the timer has finished
9
11
  * @param time How long to wait for _(in milliseconds; defaults to screen refresh rate)_
10
12
  */
@@ -20,4 +22,5 @@ function wait(callback, time) {
20
22
  timeout: 0
21
23
  }, true);
22
24
  }
25
+ //#endregion
23
26
  export { wait };
@@ -0,0 +1,55 @@
1
+ import { WhenOptions } from "./models.mjs";
2
+ //#region src/when.d.ts
3
+ declare class When {
4
+ private readonly $timer;
5
+ private readonly state;
6
+ /**
7
+ * Is the timer active?
8
+ */
9
+ get active(): boolean;
10
+ /**
11
+ * Is the timer destroyed?
12
+ */
13
+ get destroyed(): boolean;
14
+ /**
15
+ * Is the timer paused?
16
+ */
17
+ get paused(): boolean;
18
+ /**
19
+ * Get the timer's origin _(if debugging is enabled)_
20
+ */
21
+ get trace(): string | undefined;
22
+ constructor(condition: () => boolean, options?: Partial<WhenOptions>);
23
+ /**
24
+ * Continues the timer _(if it was paused)_
25
+ */
26
+ continue(): When;
27
+ /**
28
+ * Destroys the timer _(and stops it,if it was running)_
29
+ */
30
+ destroy(): void;
31
+ /**
32
+ * Pauses the timer _(if it was running)_
33
+ */
34
+ pause(): When;
35
+ /**
36
+ * Start the timer
37
+ *
38
+ * @param resolve Optional resolve callback
39
+ * @returns Promise that resolves when the condition is met
40
+ */
41
+ start(resolve?: (() => void) | null): Promise<void>;
42
+ /**
43
+ * Stops the timer _(if it was running)_
44
+ */
45
+ stop(): When;
46
+ }
47
+ /**
48
+ * Create a conditional timer
49
+ * @param condition Condition to check
50
+ * @param options Timer options
51
+ * @returns Timer instance
52
+ */
53
+ declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
54
+ //#endregion
55
+ export { type When, when };
@@ -1,9 +1,10 @@
1
- import { MESSAGE_DESTROYED, MESSAGE_STARTED, TYPE_WHEN } from "./constants.js";
2
- import { getValidNumber, getValidTimeout } from "./get.js";
3
- import "./global.js";
4
- import { TimerTrace } from "./models.js";
5
- import { Timer } from "./timer.js";
1
+ import { MESSAGE_DESTROYED, MESSAGE_STARTED, TYPE_WHEN } from "./constants.mjs";
2
+ import { getValidNumber, getValidTimeout } from "./get.mjs";
3
+ import "./global.mjs";
4
+ import { TimerTrace } from "./models.mjs";
5
+ import { Timer } from "./timer.mjs";
6
6
  import { noop } from "@oscarpalmer/atoms/function";
7
+ //#region src/when.ts
7
8
  var When = class {
8
9
  state = {
9
10
  promise: void 0,
@@ -98,17 +99,17 @@ var When = class {
98
99
  }
99
100
  /**
100
101
  * Start the timer
102
+ *
101
103
  * @param resolve Optional resolve callback
102
- * @param reject Optional reject callback
103
104
  * @returns Promise that resolves when the condition is met
104
105
  */
105
- start(resolve, reject) {
106
+ start(resolve) {
106
107
  const { state } = this;
107
108
  if (state.timer == null) throw new Error(MESSAGE_DESTROYED);
108
109
  if (state.started) throw new Error(MESSAGE_STARTED);
109
110
  state.started = true;
110
111
  state.timer.start();
111
- return state.promise.then(resolve ?? noop, reject ?? noop);
112
+ return state.promise.then(resolve);
112
113
  }
113
114
  /**
114
115
  * Stops the timer _(if it was running)_
@@ -117,16 +118,6 @@ var When = class {
117
118
  this.state.timer?.stop();
118
119
  return this;
119
120
  }
120
- /**
121
- * Start the timer
122
- * @deprecated Use `start()` instead
123
- * @param resolve Optional resolve callback
124
- * @param reject Optional reject callback
125
- * @returns Promise that resolves when the condition is met
126
- */
127
- then(resolve, reject) {
128
- return this.start(resolve, reject);
129
- }
130
121
  };
131
122
  /**
132
123
  * Create a conditional timer
@@ -137,4 +128,5 @@ var When = class {
137
128
  function when(condition, options) {
138
129
  return new When(condition, options);
139
130
  }
131
+ //#endregion
140
132
  export { when };
@@ -0,0 +1,8 @@
1
+ import { Timer } from "./timer.mjs";
2
+ import { TimerOptions, TimerState, WorkHandlerTimer, WorkHandlerType } from "./models.mjs";
3
+
4
+ //#region src/work.d.ts
5
+ declare function stop(timer: WorkHandlerTimer, state: TimerState, options: TimerOptions): Timer;
6
+ declare function work(type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions): Timer;
7
+ //#endregion
8
+ export { stop, work };
@@ -1,4 +1,5 @@
1
- import { TIMERS_ACTIVE, WORK_PAUSE, WORK_STOP } from "./constants.js";
1
+ import { TIMERS_ACTIVE, WORK_PAUSE, WORK_STOP } from "./constants.mjs";
2
+ //#region src/work.ts
2
3
  function finish(timer, state, options, success) {
3
4
  cancelAnimationFrame(state.frame);
4
5
  TIMERS_ACTIVE.delete(timer.instance);
@@ -78,4 +79,5 @@ function work(type, timer, state, options) {
78
79
  state.frame = requestAnimationFrame(runner);
79
80
  return timer.instance;
80
81
  }
82
+ //#endregion
81
83
  export { stop, work };
package/package.json CHANGED
@@ -1,75 +1,73 @@
1
1
  {
2
+ "name": "@oscarpalmer/timer",
3
+ "version": "0.43.0",
4
+ "description": "A better solution for timeout- and interval-based timers.",
5
+ "keywords": [
6
+ "requestAnimationFrame",
7
+ "setInterval",
8
+ "setTimeout",
9
+ "timer"
10
+ ],
11
+ "license": "MIT",
2
12
  "author": {
3
13
  "name": "Oscar Palmér",
4
14
  "url": "https://oscarpalmer.se"
5
15
  },
6
- "dependencies": {
7
- "@oscarpalmer/atoms": "^0.152"
8
- },
9
- "description": "A better solution for timeout- and interval-based timers.",
10
- "devDependencies": {
11
- "@types/node": "^25.3",
12
- "@vitest/coverage-istanbul": "^4",
13
- "dts-bundle-generator": "^9.5",
14
- "jsdom": "^28.1",
15
- "oxfmt": "^0.36",
16
- "oxlint": "^1.51",
17
- "rolldown": "1.0.0-rc.6",
18
- "tslib": "^2.8",
19
- "typescript": "^5.9",
20
- "vite": "8.0.0-beta.16",
21
- "vitest": "^4"
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/oscarpalmer/timer.git"
22
19
  },
20
+ "files": [
21
+ "dist",
22
+ "src"
23
+ ],
24
+ "type": "module",
25
+ "module": "dist/index.mjs",
26
+ "types": "dist/index.d.mts",
23
27
  "exports": {
24
28
  "./package.json": "./package.json",
25
29
  ".": {
26
- "types": "./types/index.d.ts",
27
- "default": "./dist/index.js"
30
+ "types": "./dist/index.d.mts",
31
+ "default": "./dist/index.mjs"
28
32
  },
29
33
  "./delay": {
30
- "types": "./types/delay.d.ts",
31
- "default": "./dist/delay.js"
34
+ "types": "./dist/delay.d.mts",
35
+ "default": "./dist/delay.mjs"
32
36
  },
33
37
  "./repeat": {
34
- "types": "./types/repeat.d.ts",
35
- "default": "./dist/repeat.js"
38
+ "types": "./dist/repeat.d.mts",
39
+ "default": "./dist/repeat.mjs"
36
40
  },
37
41
  "./wait": {
38
- "types": "./types/wait.d.ts",
39
- "default": "./dist/wait.js"
42
+ "types": "./dist/wait.d.mts",
43
+ "default": "./dist/wait.mjs"
40
44
  },
41
45
  "./when": {
42
- "types": "./types/when.d.ts",
43
- "default": "./dist/when.js"
46
+ "types": "./dist/when.d.mts",
47
+ "default": "./dist/when.mjs"
44
48
  }
45
49
  },
46
- "files": [
47
- "dist",
48
- "src",
49
- "types"
50
- ],
51
- "keywords": [
52
- "requestAnimationFrame",
53
- "setInterval",
54
- "setTimeout",
55
- "timer"
56
- ],
57
- "license": "MIT",
58
- "module": "dist/index.js",
59
- "name": "@oscarpalmer/timer",
60
- "repository": {
61
- "type": "git",
62
- "url": "git+https://github.com/oscarpalmer/timer.git"
63
- },
64
50
  "scripts": {
65
- "build": "npm run clean && npx vite build && npm run rolldown:build && npx tsc && npx dts-bundle-generator --config ./dts.config.ts --silent",
66
- "clean": "rm -rf ./dist && rm -rf ./types && rm -f ./tsconfig.tsbuildinfo",
67
- "rolldown:build": "npx rolldown -c",
68
- "rolldown:watch": "npx rolldown -c ./rolldown.config.js --watch",
69
- "test": "npx vitest --coverage",
51
+ "build": "npx vp pack && npm run tsdown:build",
52
+ "tsdown:build": "npx tsdown -c ./tsdown.config.ts",
53
+ "tsdown:watch": "npx tsdown -c ./tsdown.config.ts --watch",
54
+ "test": "npx vp test run --coverage",
55
+ "test:leak": "npx vp test run --detect-async-leaks --coverage",
70
56
  "watch": "npx vite build --watch"
71
57
  },
72
- "type": "module",
73
- "types": "types/index.d.ts",
74
- "version": "0.41.4"
58
+ "dependencies": {
59
+ "@oscarpalmer/atoms": "^0.187"
60
+ },
61
+ "devDependencies": {
62
+ "@oxlint/plugins": "^1.66",
63
+ "@types/node": "^25.9",
64
+ "@vitest/coverage-istanbul": "^4.1",
65
+ "jsdom": "^29.1",
66
+ "tsdown": "^0.22",
67
+ "typescript": "^6",
68
+ "vite": "npm:@voidzero-dev/vite-plus-core@latest",
69
+ "vite-plus": "latest",
70
+ "vitest": "npm:@voidzero-dev/vite-plus-test@latest"
71
+ },
72
+ "packageManager": "npm@11.11.1"
75
73
  }
package/src/delay.ts CHANGED
@@ -1 +1,2 @@
1
- export {delay, type PromiseOptions} from '@oscarpalmer/atoms/promise';
1
+ export {delay} from '@oscarpalmer/atoms/promise/delay';
2
+ export type {PromiseOptions} from '@oscarpalmer/atoms/promise/models';
package/src/get.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type {GenericCallback} from '@oscarpalmer/atoms';
1
+ import type {GenericCallback} from '@oscarpalmer/atoms/models';
2
2
  import {noop} from '@oscarpalmer/atoms/function';
3
3
  import {DEFAULT_TIMEOUT} from './constants';
4
4
 
package/src/is.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type {PlainObject} from '@oscarpalmer/atoms';
1
+ import type {PlainObject} from '@oscarpalmer/atoms/models';
2
2
  import {TYPE_REPEAT, TYPE_WAIT, TYPE_WHEN} from './constants';
3
3
  import type {Timer} from './timer';
4
4
  import type {When} from './when';
@@ -40,5 +40,5 @@ export function isWaited(value: unknown): value is Timer {
40
40
  * @returns `true` if the value is a conditional timer
41
41
  */
42
42
  export function isWhen(value: unknown): value is When {
43
- return is([TYPE_WHEN], value) && typeof (value as When).then === 'function';
43
+ return is([TYPE_WHEN], value) && typeof (value as When).start === 'function';
44
44
  }
package/src/repeat.ts CHANGED
@@ -6,6 +6,7 @@ import {Timer} from './timer';
6
6
 
7
7
  /**
8
8
  * Create a repeating timer
9
+ *
9
10
  * @param callback Callback to run on each interval
10
11
  * @param options Timer options
11
12
  * @returns Timer instance
package/src/wait.ts CHANGED
@@ -6,6 +6,7 @@ import {Timer} from './timer';
6
6
 
7
7
  /**
8
8
  * Create a waiting timer
9
+ *
9
10
  * @param callback Callback to run when the timer has finished
10
11
  * @param time How long to wait for _(in milliseconds; defaults to screen refresh rate)_
11
12
  */
package/src/when.ts CHANGED
@@ -131,11 +131,11 @@ class When {
131
131
 
132
132
  /**
133
133
  * Start the timer
134
+ *
134
135
  * @param resolve Optional resolve callback
135
- * @param reject Optional reject callback
136
136
  * @returns Promise that resolves when the condition is met
137
137
  */
138
- start(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void> {
138
+ start(resolve?: (() => void) | null): Promise<void> {
139
139
  const {state} = this;
140
140
 
141
141
  if (state.timer == null) {
@@ -150,7 +150,7 @@ class When {
150
150
 
151
151
  state.timer.start();
152
152
 
153
- return state.promise.then(resolve ?? noop, reject ?? noop);
153
+ return state.promise.then(resolve);
154
154
  }
155
155
 
156
156
  /**
@@ -161,18 +161,6 @@ class When {
161
161
 
162
162
  return this;
163
163
  }
164
-
165
- /**
166
- * Start the timer
167
- * @deprecated Use `start()` instead
168
- * @param resolve Optional resolve callback
169
- * @param reject Optional reject callback
170
- * @returns Promise that resolves when the condition is met
171
- */
172
- // oxlint-disable-next-line no-thenable: Returning a promise-like object, so it's ok ;)
173
- then(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void> {
174
- return this.start(resolve, reject);
175
- }
176
164
  }
177
165
 
178
166
  /**
package/dist/delay.js DELETED
@@ -1,2 +0,0 @@
1
- import { delay } from "@oscarpalmer/atoms/promise";
2
- export { delay };
package/dist/index.js DELETED
@@ -1,7 +0,0 @@
1
- import { delay } from "./delay.js";
2
- import "./global.js";
3
- import { isRepeated, isTimer, isWaited, isWhen } from "./is.js";
4
- import { repeat } from "./repeat.js";
5
- import { wait } from "./wait.js";
6
- import { when } from "./when.js";
7
- export { delay, isRepeated, isTimer, isWaited, isWhen, repeat, wait, when };