@sapphire/timer-manager 1.0.1-next.574299a.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/CHANGELOG.md ADDED
File without changes
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ <div align="center">
2
+
3
+ ![Sapphire Logo](https://cdn.skyra.pw/gh-assets/sapphire-banner.png)
4
+
5
+ # @sapphire/timer-manager
6
+
7
+ **Timer manager utilities for JavaScript.**
8
+
9
+ [![GitHub](https://img.shields.io/github/license/sapphiredev/utilities)](https://github.com/sapphiredev/utilities/blob/main/LICENSE.md)
10
+ [![codecov](https://codecov.io/gh/sapphiredev/utilities/branch/main/graph/badge.svg?token=OEGIV6RFDO)](https://codecov.io/gh/sapphiredev/utilities)
11
+ [![npm bundle size](https://img.shields.io/bundlephobia/min/@sapphire/timer-manager?logo=webpack&style=flat-square)](https://bundlephobia.com/result?p=@sapphire/timer-manager)
12
+ [![npm](https://img.shields.io/npm/v/@sapphire/timer-manager?color=crimson&logo=npm&style=flat-square)](https://www.npmjs.com/package/@sapphire/timer-manager)
13
+
14
+ </div>
15
+
16
+ **Table of Contents**
17
+
18
+ - [Features](#features)
19
+ - [Installation](#installation)
20
+ - [Usage](#usage)
21
+ - [Basic Usage](#basic-usage)
22
+ - [Buy us some doughnuts](#buy-us-some-doughnuts)
23
+ - [Contributors ✨](#contributors-%E2%9C%A8)
24
+
25
+ ## Features
26
+
27
+ - Written in TypeScript
28
+ - Bundled with esbuild so it can be used in NodeJS and browsers
29
+ - Offers CommonJS, ESM and UMD bundles
30
+ - Fully tested
31
+
32
+ ## Installation
33
+
34
+ You can use the following command to install this package, or replace `npm install` with your package manager of choice.
35
+
36
+ ```sh
37
+ npm install @sapphire/timer-manager
38
+ ```
39
+
40
+ ## Buy us some doughnuts
41
+
42
+ Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
43
+
44
+ We accept donations through Open Collective, Ko-fi, PayPal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.
45
+
46
+ | Donate With | Address |
47
+ | :-------------: | :-------------------------------------------------: |
48
+ | Open Collective | [Click Here](https://sapphirejs.dev/opencollective) |
49
+ | Ko-fi | [Click Here](https://sapphirejs.dev/kofi) |
50
+ | Patreon | [Click Here](https://sapphirejs.dev/patreon) |
51
+ | PayPal | [Click Here](https://sapphirejs.dev/paypal) |
52
+
53
+ ## Contributors ✨
54
+
55
+ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
56
+
57
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
58
+ <!-- prettier-ignore-start -->
59
+ <!-- markdownlint-disable -->
60
+ <table>
61
+ <tr>
62
+ <td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Code">πŸ’»</a> <a href="#infra-favna" title="Infrastructure (Hosting, Build-Tools, etc)">πŸš‡</a> <a href="#projectManagement-favna" title="Project Management">πŸ“†</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Documentation">πŸ“–</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Tests">⚠️</a></td>
63
+ <td align="center"><a href="https://github.com/kyranet"><img src="https://avatars0.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura RomΓ‘n</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Code">πŸ’»</a> <a href="#projectManagement-kyranet" title="Project Management">πŸ“†</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Akyranet" title="Reviewed Pull Requests">πŸ‘€</a> <a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Tests">⚠️</a></td>
64
+ <td align="center"><a href="https://github.com/PyroTechniac"><img src="https://avatars2.githubusercontent.com/u/39341355?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gryffon Bellish</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Code">πŸ’»</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3APyroTechniac" title="Reviewed Pull Requests">πŸ‘€</a> <a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Tests">⚠️</a></td>
65
+ <td align="center"><a href="https://github.com/vladfrangu"><img src="https://avatars3.githubusercontent.com/u/17960496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vlad Frangu</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Code">πŸ’»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3Avladfrangu" title="Bug reports">πŸ›</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Avladfrangu" title="Reviewed Pull Requests">πŸ‘€</a> <a href="#userTesting-vladfrangu" title="User Testing">πŸ““</a> <a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Tests">⚠️</a></td>
66
+ <td align="center"><a href="https://github.com/Stitch07"><img src="https://avatars0.githubusercontent.com/u/29275227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stitch07</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Code">πŸ’»</a> <a href="#projectManagement-Stitch07" title="Project Management">πŸ“†</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Tests">⚠️</a></td>
67
+ <td align="center"><a href="https://github.com/apps/depfu"><img src="https://avatars3.githubusercontent.com/in/715?v=4?s=100" width="100px;" alt=""/><br /><sub><b>depfu[bot]</b></sub></a><br /><a href="#maintenance-depfu[bot]" title="Maintenance">🚧</a></td>
68
+ <td align="center"><a href="https://github.com/apps/allcontributors"><img src="https://avatars0.githubusercontent.com/in/23186?v=4?s=100" width="100px;" alt=""/><br /><sub><b>allcontributors[bot]</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=allcontributors[bot]" title="Documentation">πŸ“–</a></td>
69
+ </tr>
70
+ <tr>
71
+ <td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars1.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Nytelife26" title="Documentation">πŸ“–</a></td>
72
+ <td align="center"><a href="https://github.com/Alcremie"><img src="https://avatars0.githubusercontent.com/u/54785334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivan Lieder</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Alcremie" title="Code">πŸ’»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AAlcremie" title="Bug reports">πŸ›</a></td>
73
+ <td align="center"><a href="https://github.com/RealShadowNova"><img src="https://avatars3.githubusercontent.com/u/46537907?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hezekiah Hendry</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=RealShadowNova" title="Code">πŸ’»</a> <a href="#tool-RealShadowNova" title="Tools">πŸ”§</a></td>
74
+ <td align="center"><a href="https://github.com/Vetlix"><img src="https://avatars.githubusercontent.com/u/31412314?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vetlix</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Vetlix" title="Code">πŸ’»</a></td>
75
+ <td align="center"><a href="https://github.com/ethamitc"><img src="https://avatars.githubusercontent.com/u/27776796?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ethan Mitchell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ethamitc" title="Documentation">πŸ“–</a></td>
76
+ <td align="center"><a href="https://github.com/noftaly"><img src="https://avatars.githubusercontent.com/u/34779161?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Elliot</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=noftaly" title="Code">πŸ’»</a></td>
77
+ <td align="center"><a href="https://jurien.dev"><img src="https://avatars.githubusercontent.com/u/5418114?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jurien Hamaker</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=jurienhamaker" title="Code">πŸ’»</a></td>
78
+ </tr>
79
+ <tr>
80
+ <td align="center"><a href="https://fanoulis.dev/"><img src="https://avatars.githubusercontent.com/u/38255093?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Charalampos Fanoulis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=cfanoulis" title="Documentation">πŸ“–</a></td>
81
+ <td align="center"><a href="https://github.com/apps/dependabot"><img src="https://avatars.githubusercontent.com/in/29110?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dependabot[bot]</b></sub></a><br /><a href="#maintenance-dependabot[bot]" title="Maintenance">🚧</a></td>
82
+ <td align="center"><a href="https://kaname.netlify.app/"><img src="https://avatars.githubusercontent.com/u/56084970?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kaname</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kaname-png" title="Code">πŸ’»</a></td>
83
+ <td align="center"><a href="https://github.com/nandhagk"><img src="https://avatars.githubusercontent.com/u/62976649?v=4?s=100" width="100px;" alt=""/><br /><sub><b>nandhagk</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/issues?q=author%3Anandhagk" title="Bug reports">πŸ›</a></td>
84
+ <td align="center"><a href="https://megatank58.me/"><img src="https://avatars.githubusercontent.com/u/51410502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>megatank58</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=megatank58" title="Code">πŸ’»</a></td>
85
+ <td align="center"><a href="https://github.com/UndiedGamer"><img src="https://avatars.githubusercontent.com/u/84702365?v=4?s=100" width="100px;" alt=""/><br /><sub><b>UndiedGamer</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=UndiedGamer" title="Code">πŸ’»</a></td>
86
+ <td align="center"><a href="https://github.com/Lioness100"><img src="https://avatars.githubusercontent.com/u/65814829?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lioness100</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Documentation">πŸ“–</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Code">πŸ’»</a></td>
87
+ </tr>
88
+ <tr>
89
+ <td align="center"><a href="https://gitlab.com/DavidPH/"><img src="https://avatars.githubusercontent.com/u/44669930?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=DavidPHH" title="Code">πŸ’»</a></td>
90
+ <td align="center"><a href="https://github.com/apps/renovate"><img src="https://avatars.githubusercontent.com/in/2740?v=4?s=100" width="100px;" alt=""/><br /><sub><b>renovate[bot]</b></sub></a><br /><a href="#maintenance-renovate[bot]" title="Maintenance">🚧</a></td>
91
+ <td align="center"><a href="https://renovate.whitesourcesoftware.com/"><img src="https://avatars.githubusercontent.com/u/25180681?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WhiteSource Renovate</b></sub></a><br /><a href="#maintenance-renovate-bot" title="Maintenance">🚧</a></td>
92
+ <td align="center"><a href="https://fc5570.me/"><img src="https://avatars.githubusercontent.com/u/68158483?v=4?s=100" width="100px;" alt=""/><br /><sub><b>FC</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=FC5570" title="Code">πŸ’»</a></td>
93
+ <td align="center"><a href="https://github.com/Tokipudi"><img src="https://avatars.githubusercontent.com/u/29551076?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JΓ©rΓ©my de Saint Denis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Tokipudi" title="Code">πŸ’»</a></td>
94
+ <td align="center"><a href="https://github.com/ItsMrCube"><img src="https://avatars.githubusercontent.com/u/25201357?v=4?s=100" width="100px;" alt=""/><br /><sub><b>MrCube</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ItsMrCube" title="Code">πŸ’»</a></td>
95
+ <td align="center"><a href="https://github.com/bitomic"><img src="https://avatars.githubusercontent.com/u/35199700?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bitomic</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=bitomic" title="Code">πŸ’»</a></td>
96
+ </tr>
97
+ <tr>
98
+ <td align="center"><a href="https://c43721.dev/"><img src="https://avatars.githubusercontent.com/u/55610086?v=4?s=100" width="100px;" alt=""/><br /><sub><b>c43721</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=c43721" title="Code">πŸ’»</a></td>
99
+ <td align="center"><a href="https://commandtechno.com/"><img src="https://avatars.githubusercontent.com/u/68407783?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Commandtechno</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Commandtechno" title="Code">πŸ’»</a></td>
100
+ <td align="center"><a href="https://github.com/dhruv-kaushikk"><img src="https://avatars.githubusercontent.com/u/73697546?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=dhruv-kaushikk" title="Code">πŸ’»</a></td>
101
+ <td align="center"><a href="https://axis.moe/"><img src="https://avatars.githubusercontent.com/u/54381371?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=axisiscool" title="Code">πŸ’»</a></td>
102
+ <td align="center"><a href="https://github.com/imranbarbhuiya"><img src="https://avatars.githubusercontent.com/u/74945038?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Parbez</b></sub></a><br /><a href="#maintenance-imranbarbhuiya" title="Maintenance">🚧</a></td>
103
+ <td align="center"><a href="https://github.com/NotKaskus"><img src="https://avatars.githubusercontent.com/u/75168528?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Paul Andrew</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=NotKaskus" title="Documentation">πŸ“–</a></td>
104
+ <td align="center"><a href="https://linktr.ee/mzato0001"><img src="https://avatars.githubusercontent.com/u/62367547?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mzato</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Mzato0001" title="Code">πŸ’»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AMzato0001" title="Bug reports">πŸ›</a></td>
105
+ </tr>
106
+ <tr>
107
+ <td align="center"><a href="https://github.com/MajesticString"><img src="https://avatars.githubusercontent.com/u/66224939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harry Allen</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=MajesticString" title="Documentation">πŸ“–</a></td>
108
+ <td align="center"><a href="https://github.com/EvolutionX-10"><img src="https://avatars.githubusercontent.com/u/85353424?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Evo</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=EvolutionX-10" title="Code">πŸ’»</a></td>
109
+ <td align="center"><a href="https://enes.ovh/"><img src="https://avatars.githubusercontent.com/u/61084101?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Enes GenΓ§</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=enxg" title="Code">πŸ’»</a></td>
110
+ <td align="center"><a href="https://github.com/muchnameless"><img src="https://avatars.githubusercontent.com/u/12682826?v=4?s=100" width="100px;" alt=""/><br /><sub><b>muchnameless</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=muchnameless" title="Code">πŸ’»</a></td>
111
+ </tr>
112
+ </table>
113
+
114
+ <!-- markdownlint-restore -->
115
+ <!-- prettier-ignore-end -->
116
+
117
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
118
+
119
+ This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Manages timers so that this application can be cleanly exited
3
+ */
4
+ declare class TimerManager extends null {
5
+ /**
6
+ * A set of timeouts to clear on destroy
7
+ */
8
+ private static storedTimeouts;
9
+ /**
10
+ * A set of intervals to clear on destroy
11
+ */
12
+ private static storedIntervals;
13
+ /**
14
+ * Creates a timeout gets cleared when destroyed
15
+ * @param fn callback function
16
+ * @param delay amount of time before running the callback
17
+ * @param args additional arguments to pass back to the callback
18
+ */
19
+ static setTimeout<A = unknown>(fn: (...args: A[]) => void, delay: number, ...args: A[]): NodeJS.Timeout;
20
+ /**
21
+ * Clears a timeout created through this class
22
+ * @param timeout The timeout to clear
23
+ */
24
+ static clearTimeout(timeout: NodeJS.Timeout): void;
25
+ /**
26
+ * Creates an interval gets cleared when destroyed
27
+ * @param fn callback function
28
+ * @param delay amount of time before running the callback
29
+ * @param args additional arguments to pass back to the callback
30
+ */
31
+ static setInterval<A = unknown>(fn: (...args: A[]) => void, delay: number, ...args: A[]): NodeJS.Timeout;
32
+ /**
33
+ * Clears an internal created through this class
34
+ * @param interval The interval to clear
35
+ */
36
+ static clearInterval(interval: NodeJS.Timeout): void;
37
+ /**
38
+ * Clears running timeouts and intervals created through this class so NodeJS can gracefully exit
39
+ */
40
+ static destroy(): void;
41
+ }
42
+
43
+ export { TimerManager };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var SapphireTimerManager = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __publicField = (obj, key, value) => {
23
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
24
+ return value;
25
+ };
26
+
27
+ // src/index.ts
28
+ var src_exports = {};
29
+ __export(src_exports, {
30
+ TimerManager: () => TimerManager
31
+ });
32
+
33
+ // src/lib/TimerManager.ts
34
+ var TimerManager = class extends null {
35
+ static setTimeout(fn, delay, ...args) {
36
+ const timeout = setTimeout(() => {
37
+ this.storedTimeouts.delete(timeout);
38
+ fn(...args);
39
+ }, delay);
40
+ this.storedTimeouts.add(timeout);
41
+ return timeout;
42
+ }
43
+ static clearTimeout(timeout) {
44
+ clearTimeout(timeout);
45
+ this.storedTimeouts.delete(timeout);
46
+ }
47
+ static setInterval(fn, delay, ...args) {
48
+ const interval = setInterval(fn, delay, ...args);
49
+ this.storedIntervals.add(interval);
50
+ return interval;
51
+ }
52
+ static clearInterval(interval) {
53
+ clearInterval(interval);
54
+ this.storedIntervals.delete(interval);
55
+ }
56
+ static destroy() {
57
+ for (const i of this.storedTimeouts)
58
+ clearTimeout(i);
59
+ for (const i of this.storedIntervals)
60
+ clearInterval(i);
61
+ this.storedTimeouts.clear();
62
+ this.storedIntervals.clear();
63
+ }
64
+ };
65
+ __name(TimerManager, "TimerManager");
66
+ __publicField(TimerManager, "storedTimeouts", /* @__PURE__ */ new Set());
67
+ __publicField(TimerManager, "storedIntervals", /* @__PURE__ */ new Set());
68
+ return __toCommonJS(src_exports);
69
+ })();
70
+ //# sourceMappingURL=index.global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/TimerManager.ts"],"sourcesContent":["export * from './lib/TimerManager';\n","/**\n * Manages timers so that this application can be cleanly exited\n */\nexport class TimerManager extends null {\n\t/**\n\t * A set of timeouts to clear on destroy\n\t */\n\tprivate static storedTimeouts = new Set<NodeJS.Timeout>();\n\n\t/**\n\t * A set of intervals to clear on destroy\n\t */\n\tprivate static storedIntervals = new Set<NodeJS.Timeout>();\n\n\t/**\n\t * Creates a timeout gets cleared when destroyed\n\t * @param fn callback function\n\t * @param delay amount of time before running the callback\n\t * @param args additional arguments to pass back to the callback\n\t */\n\tpublic static setTimeout<A = unknown>(fn: (...args: A[]) => void, delay: number, ...args: A[]): NodeJS.Timeout {\n\t\tconst timeout = setTimeout(() => {\n\t\t\tthis.storedTimeouts.delete(timeout);\n\t\t\tfn(...args);\n\t\t}, delay);\n\t\tthis.storedTimeouts.add(timeout);\n\t\treturn timeout;\n\t}\n\n\t/**\n\t * Clears a timeout created through this class\n\t * @param timeout The timeout to clear\n\t */\n\tpublic static clearTimeout(timeout: NodeJS.Timeout): void {\n\t\tclearTimeout(timeout);\n\t\tthis.storedTimeouts.delete(timeout);\n\t}\n\n\t/**\n\t * Creates an interval gets cleared when destroyed\n\t * @param fn callback function\n\t * @param delay amount of time before running the callback\n\t * @param args additional arguments to pass back to the callback\n\t */\n\tpublic static setInterval<A = unknown>(fn: (...args: A[]) => void, delay: number, ...args: A[]): NodeJS.Timeout {\n\t\tconst interval = setInterval(fn, delay, ...args);\n\t\tthis.storedIntervals.add(interval);\n\t\treturn interval;\n\t}\n\n\t/**\n\t * Clears an internal created through this class\n\t * @param interval The interval to clear\n\t */\n\tpublic static clearInterval(interval: NodeJS.Timeout): void {\n\t\tclearInterval(interval);\n\t\tthis.storedIntervals.delete(interval);\n\t}\n\n\t/**\n\t * Clears running timeouts and intervals created through this class so NodeJS can gracefully exit\n\t */\n\tpublic static destroy(): void {\n\t\tfor (const i of this.storedTimeouts) clearTimeout(i);\n\t\tfor (const i of this.storedIntervals) clearInterval(i);\n\t\tthis.storedTimeouts.clear();\n\t\tthis.storedIntervals.clear();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;;;ACGO,MAAM,eAAN,cAA2B,KAAK;AAAA,IAiBtC,OAAc,WAAwB,IAA4B,UAAkB,MAA2B;AAC9G,YAAM,UAAU,WAAW,MAAM;AAChC,aAAK,eAAe,OAAO,OAAO;AAClC,WAAG,GAAG,IAAI;AAAA,MACX,GAAG,KAAK;AACR,WAAK,eAAe,IAAI,OAAO;AAC/B,aAAO;AAAA,IACR;AAAA,IAMA,OAAc,aAAa,SAA+B;AACzD,mBAAa,OAAO;AACpB,WAAK,eAAe,OAAO,OAAO;AAAA,IACnC;AAAA,IAQA,OAAc,YAAyB,IAA4B,UAAkB,MAA2B;AAC/G,YAAM,WAAW,YAAY,IAAI,OAAO,GAAG,IAAI;AAC/C,WAAK,gBAAgB,IAAI,QAAQ;AACjC,aAAO;AAAA,IACR;AAAA,IAMA,OAAc,cAAc,UAAgC;AAC3D,oBAAc,QAAQ;AACtB,WAAK,gBAAgB,OAAO,QAAQ;AAAA,IACrC;AAAA,IAKA,OAAc,UAAgB;AAC7B,iBAAW,KAAK,KAAK;AAAgB,qBAAa,CAAC;AACnD,iBAAW,KAAK,KAAK;AAAiB,sBAAc,CAAC;AACrD,WAAK,eAAe,MAAM;AAC1B,WAAK,gBAAgB,MAAM;AAAA,IAC5B;AAAA,EACD;AAjEa;AAIZ,gBAJY,cAIG,kBAAiB,oBAAI,IAAoB;AAKxD,gBATY,cASG,mBAAkB,oBAAI,IAAoB;","names":[]}
package/dist/index.js ADDED
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+ var __publicField = (obj, key, value) => {
23
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
24
+ return value;
25
+ };
26
+
27
+ // src/index.ts
28
+ var src_exports = {};
29
+ __export(src_exports, {
30
+ TimerManager: () => TimerManager
31
+ });
32
+ module.exports = __toCommonJS(src_exports);
33
+
34
+ // src/lib/TimerManager.ts
35
+ var TimerManager = class extends null {
36
+ static setTimeout(fn, delay, ...args) {
37
+ const timeout = setTimeout(() => {
38
+ this.storedTimeouts.delete(timeout);
39
+ fn(...args);
40
+ }, delay);
41
+ this.storedTimeouts.add(timeout);
42
+ return timeout;
43
+ }
44
+ static clearTimeout(timeout) {
45
+ clearTimeout(timeout);
46
+ this.storedTimeouts.delete(timeout);
47
+ }
48
+ static setInterval(fn, delay, ...args) {
49
+ const interval = setInterval(fn, delay, ...args);
50
+ this.storedIntervals.add(interval);
51
+ return interval;
52
+ }
53
+ static clearInterval(interval) {
54
+ clearInterval(interval);
55
+ this.storedIntervals.delete(interval);
56
+ }
57
+ static destroy() {
58
+ for (const i of this.storedTimeouts)
59
+ clearTimeout(i);
60
+ for (const i of this.storedIntervals)
61
+ clearInterval(i);
62
+ this.storedTimeouts.clear();
63
+ this.storedIntervals.clear();
64
+ }
65
+ };
66
+ __name(TimerManager, "TimerManager");
67
+ __publicField(TimerManager, "storedTimeouts", /* @__PURE__ */ new Set());
68
+ __publicField(TimerManager, "storedIntervals", /* @__PURE__ */ new Set());
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ TimerManager
72
+ });
73
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/TimerManager.ts"],"sourcesContent":["export * from './lib/TimerManager';\n","/**\n * Manages timers so that this application can be cleanly exited\n */\nexport class TimerManager extends null {\n\t/**\n\t * A set of timeouts to clear on destroy\n\t */\n\tprivate static storedTimeouts = new Set<NodeJS.Timeout>();\n\n\t/**\n\t * A set of intervals to clear on destroy\n\t */\n\tprivate static storedIntervals = new Set<NodeJS.Timeout>();\n\n\t/**\n\t * Creates a timeout gets cleared when destroyed\n\t * @param fn callback function\n\t * @param delay amount of time before running the callback\n\t * @param args additional arguments to pass back to the callback\n\t */\n\tpublic static setTimeout<A = unknown>(fn: (...args: A[]) => void, delay: number, ...args: A[]): NodeJS.Timeout {\n\t\tconst timeout = setTimeout(() => {\n\t\t\tthis.storedTimeouts.delete(timeout);\n\t\t\tfn(...args);\n\t\t}, delay);\n\t\tthis.storedTimeouts.add(timeout);\n\t\treturn timeout;\n\t}\n\n\t/**\n\t * Clears a timeout created through this class\n\t * @param timeout The timeout to clear\n\t */\n\tpublic static clearTimeout(timeout: NodeJS.Timeout): void {\n\t\tclearTimeout(timeout);\n\t\tthis.storedTimeouts.delete(timeout);\n\t}\n\n\t/**\n\t * Creates an interval gets cleared when destroyed\n\t * @param fn callback function\n\t * @param delay amount of time before running the callback\n\t * @param args additional arguments to pass back to the callback\n\t */\n\tpublic static setInterval<A = unknown>(fn: (...args: A[]) => void, delay: number, ...args: A[]): NodeJS.Timeout {\n\t\tconst interval = setInterval(fn, delay, ...args);\n\t\tthis.storedIntervals.add(interval);\n\t\treturn interval;\n\t}\n\n\t/**\n\t * Clears an internal created through this class\n\t * @param interval The interval to clear\n\t */\n\tpublic static clearInterval(interval: NodeJS.Timeout): void {\n\t\tclearInterval(interval);\n\t\tthis.storedIntervals.delete(interval);\n\t}\n\n\t/**\n\t * Clears running timeouts and intervals created through this class so NodeJS can gracefully exit\n\t */\n\tpublic static destroy(): void {\n\t\tfor (const i of this.storedTimeouts) clearTimeout(i);\n\t\tfor (const i of this.storedIntervals) clearInterval(i);\n\t\tthis.storedTimeouts.clear();\n\t\tthis.storedIntervals.clear();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,eAAN,cAA2B,KAAK;AAAA,EAiBtC,OAAc,WAAwB,IAA4B,UAAkB,MAA2B;AAC9G,UAAM,UAAU,WAAW,MAAM;AAChC,WAAK,eAAe,OAAO,OAAO;AAClC,SAAG,GAAG,IAAI;AAAA,IACX,GAAG,KAAK;AACR,SAAK,eAAe,IAAI,OAAO;AAC/B,WAAO;AAAA,EACR;AAAA,EAMA,OAAc,aAAa,SAA+B;AACzD,iBAAa,OAAO;AACpB,SAAK,eAAe,OAAO,OAAO;AAAA,EACnC;AAAA,EAQA,OAAc,YAAyB,IAA4B,UAAkB,MAA2B;AAC/G,UAAM,WAAW,YAAY,IAAI,OAAO,GAAG,IAAI;AAC/C,SAAK,gBAAgB,IAAI,QAAQ;AACjC,WAAO;AAAA,EACR;AAAA,EAMA,OAAc,cAAc,UAAgC;AAC3D,kBAAc,QAAQ;AACtB,SAAK,gBAAgB,OAAO,QAAQ;AAAA,EACrC;AAAA,EAKA,OAAc,UAAgB;AAC7B,eAAW,KAAK,KAAK;AAAgB,mBAAa,CAAC;AACnD,eAAW,KAAK,KAAK;AAAiB,oBAAc,CAAC;AACrD,SAAK,eAAe,MAAM;AAC1B,SAAK,gBAAgB,MAAM;AAAA,EAC5B;AACD;AAjEa;AAIZ,cAJY,cAIG,kBAAiB,oBAAI,IAAoB;AAKxD,cATY,cASG,mBAAkB,oBAAI,IAAoB;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,47 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __publicField = (obj, key, value) => {
5
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ return value;
7
+ };
8
+
9
+ // src/lib/TimerManager.ts
10
+ var TimerManager = class extends null {
11
+ static setTimeout(fn, delay, ...args) {
12
+ const timeout = setTimeout(() => {
13
+ this.storedTimeouts.delete(timeout);
14
+ fn(...args);
15
+ }, delay);
16
+ this.storedTimeouts.add(timeout);
17
+ return timeout;
18
+ }
19
+ static clearTimeout(timeout) {
20
+ clearTimeout(timeout);
21
+ this.storedTimeouts.delete(timeout);
22
+ }
23
+ static setInterval(fn, delay, ...args) {
24
+ const interval = setInterval(fn, delay, ...args);
25
+ this.storedIntervals.add(interval);
26
+ return interval;
27
+ }
28
+ static clearInterval(interval) {
29
+ clearInterval(interval);
30
+ this.storedIntervals.delete(interval);
31
+ }
32
+ static destroy() {
33
+ for (const i of this.storedTimeouts)
34
+ clearTimeout(i);
35
+ for (const i of this.storedIntervals)
36
+ clearInterval(i);
37
+ this.storedTimeouts.clear();
38
+ this.storedIntervals.clear();
39
+ }
40
+ };
41
+ __name(TimerManager, "TimerManager");
42
+ __publicField(TimerManager, "storedTimeouts", /* @__PURE__ */ new Set());
43
+ __publicField(TimerManager, "storedIntervals", /* @__PURE__ */ new Set());
44
+ export {
45
+ TimerManager
46
+ };
47
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/TimerManager.ts"],"sourcesContent":["/**\n * Manages timers so that this application can be cleanly exited\n */\nexport class TimerManager extends null {\n\t/**\n\t * A set of timeouts to clear on destroy\n\t */\n\tprivate static storedTimeouts = new Set<NodeJS.Timeout>();\n\n\t/**\n\t * A set of intervals to clear on destroy\n\t */\n\tprivate static storedIntervals = new Set<NodeJS.Timeout>();\n\n\t/**\n\t * Creates a timeout gets cleared when destroyed\n\t * @param fn callback function\n\t * @param delay amount of time before running the callback\n\t * @param args additional arguments to pass back to the callback\n\t */\n\tpublic static setTimeout<A = unknown>(fn: (...args: A[]) => void, delay: number, ...args: A[]): NodeJS.Timeout {\n\t\tconst timeout = setTimeout(() => {\n\t\t\tthis.storedTimeouts.delete(timeout);\n\t\t\tfn(...args);\n\t\t}, delay);\n\t\tthis.storedTimeouts.add(timeout);\n\t\treturn timeout;\n\t}\n\n\t/**\n\t * Clears a timeout created through this class\n\t * @param timeout The timeout to clear\n\t */\n\tpublic static clearTimeout(timeout: NodeJS.Timeout): void {\n\t\tclearTimeout(timeout);\n\t\tthis.storedTimeouts.delete(timeout);\n\t}\n\n\t/**\n\t * Creates an interval gets cleared when destroyed\n\t * @param fn callback function\n\t * @param delay amount of time before running the callback\n\t * @param args additional arguments to pass back to the callback\n\t */\n\tpublic static setInterval<A = unknown>(fn: (...args: A[]) => void, delay: number, ...args: A[]): NodeJS.Timeout {\n\t\tconst interval = setInterval(fn, delay, ...args);\n\t\tthis.storedIntervals.add(interval);\n\t\treturn interval;\n\t}\n\n\t/**\n\t * Clears an internal created through this class\n\t * @param interval The interval to clear\n\t */\n\tpublic static clearInterval(interval: NodeJS.Timeout): void {\n\t\tclearInterval(interval);\n\t\tthis.storedIntervals.delete(interval);\n\t}\n\n\t/**\n\t * Clears running timeouts and intervals created through this class so NodeJS can gracefully exit\n\t */\n\tpublic static destroy(): void {\n\t\tfor (const i of this.storedTimeouts) clearTimeout(i);\n\t\tfor (const i of this.storedIntervals) clearInterval(i);\n\t\tthis.storedTimeouts.clear();\n\t\tthis.storedIntervals.clear();\n\t}\n}\n"],"mappings":";;;;;;;;;AAGO,IAAM,eAAN,cAA2B,KAAK;AAAA,EAiBtC,OAAc,WAAwB,IAA4B,UAAkB,MAA2B;AAC9G,UAAM,UAAU,WAAW,MAAM;AAChC,WAAK,eAAe,OAAO,OAAO;AAClC,SAAG,GAAG,IAAI;AAAA,IACX,GAAG,KAAK;AACR,SAAK,eAAe,IAAI,OAAO;AAC/B,WAAO;AAAA,EACR;AAAA,EAMA,OAAc,aAAa,SAA+B;AACzD,iBAAa,OAAO;AACpB,SAAK,eAAe,OAAO,OAAO;AAAA,EACnC;AAAA,EAQA,OAAc,YAAyB,IAA4B,UAAkB,MAA2B;AAC/G,UAAM,WAAW,YAAY,IAAI,OAAO,GAAG,IAAI;AAC/C,SAAK,gBAAgB,IAAI,QAAQ;AACjC,WAAO;AAAA,EACR;AAAA,EAMA,OAAc,cAAc,UAAgC;AAC3D,kBAAc,QAAQ;AACtB,SAAK,gBAAgB,OAAO,QAAQ;AAAA,EACrC;AAAA,EAKA,OAAc,UAAgB;AAC7B,eAAW,KAAK,KAAK;AAAgB,mBAAa,CAAC;AACnD,eAAW,KAAK,KAAK;AAAiB,oBAAc,CAAC;AACrD,SAAK,eAAe,MAAM;AAC1B,SAAK,gBAAgB,MAAM;AAAA,EAC5B;AACD;AAjEa;AAIZ,cAJY,cAIG,kBAAiB,oBAAI,IAAoB;AAKxD,cATY,cASG,mBAAkB,oBAAI,IAAoB;","names":[]}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@sapphire/timer-manager",
3
+ "version": "1.0.1-next.574299a.0",
4
+ "description": "A timer manager utility library for JavaScript.",
5
+ "author": "@sapphire",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "module": "dist/index.mjs",
9
+ "browser": "dist/index.global.js",
10
+ "unpkg": "dist/index.global.js",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
+ },
17
+ "sideEffects": false,
18
+ "homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/timer-manager",
19
+ "scripts": {
20
+ "test": "vitest run",
21
+ "lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
22
+ "build": "tsup",
23
+ "docs": "typedoc-json-parser",
24
+ "prepack": "yarn build",
25
+ "bump": "cliff-jumper",
26
+ "check-update": "cliff-jumper --dry-run"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/sapphiredev/utilities.git",
31
+ "directory": "packages/timer-manager"
32
+ },
33
+ "files": [
34
+ "dist/**/*.js*",
35
+ "dist/**/*.mjs*",
36
+ "dist/**/*.d*"
37
+ ],
38
+ "engines": {
39
+ "node": ">=v14.0.0",
40
+ "npm": ">=7.0.0"
41
+ },
42
+ "keywords": [
43
+ "@sapphire/timer-manager",
44
+ "timer",
45
+ "bot",
46
+ "typescript",
47
+ "ts",
48
+ "yarn",
49
+ "discord",
50
+ "sapphire",
51
+ "standalone"
52
+ ],
53
+ "bugs": {
54
+ "url": "https://github.com/sapphiredev/utilities/issues"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "devDependencies": {
60
+ "@favware/cliff-jumper": "^1.8.7",
61
+ "@vitest/coverage-c8": "^0.23.4",
62
+ "tsup": "^6.2.3",
63
+ "typedoc": "^0.23.14",
64
+ "typedoc-json-parser": "^4.0.0",
65
+ "typescript": "^4.8.3",
66
+ "vitest": "^0.23.4"
67
+ }
68
+ }