{"id":23758460,"url":"https://github.com/blaumeise20/date-timeout-interval","last_synced_at":"2025-09-05T04:34:09.993Z","repository":{"id":55104122,"uuid":"328218456","full_name":"blaumeise20/date-timeout-interval","owner":"blaumeise20","description":"A simple npm package for timing. https://www.npmjs.com/package/date-timeout-interval","archived":false,"fork":false,"pushed_at":"2021-02-05T14:52:58.000Z","size":278,"stargazers_count":15,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-05T23:05:50.226Z","etag":null,"topics":["date","interval","javascript","npm","pause","timeout","timer"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blaumeise20.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-09T18:18:12.000Z","updated_at":"2023-08-05T21:50:28.000Z","dependencies_parsed_at":"2022-08-14T12:01:18.433Z","dependency_job_id":null,"html_url":"https://github.com/blaumeise20/date-timeout-interval","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/blaumeise20/date-timeout-interval","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blaumeise20%2Fdate-timeout-interval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blaumeise20%2Fdate-timeout-interval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blaumeise20%2Fdate-timeout-interval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blaumeise20%2Fdate-timeout-interval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blaumeise20","download_url":"https://codeload.github.com/blaumeise20/date-timeout-interval/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blaumeise20%2Fdate-timeout-interval/sbom","scorecard":{"id":242888,"data":{"date":"2025-08-11","repo":{"name":"github.com/blaumeise20/date-timeout-interval","commit":"c637b00b75247c1c605c205c6fa7b5f465787f2c"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.7,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/node.js.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/blaumeise20/date-timeout-interval/node.js.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/blaumeise20/date-timeout-interval/node.js.yml/main?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENCE:0","Info: FSF or OSI recognized license: MIT License: LICENCE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"26 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T06:57:47.710Z","repository_id":55104122,"created_at":"2025-08-17T06:57:47.710Z","updated_at":"2025-08-17T06:57:47.710Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273713399,"owners_count":25154609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["date","interval","javascript","npm","pause","timeout","timer"],"created_at":"2024-12-31T19:54:37.346Z","updated_at":"2025-09-05T04:34:04.962Z","avatar_url":"https://github.com/blaumeise20.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Timeout and Interval\n\n![Node.js CI](https://github.com/blaumeise20/date-timeout-interval/workflows/Node.js%20CI/badge.svg?branch=main)\n![version](https://img.shields.io/badge/version-1.3.0-success?style=plastic)\n\nImplementation of setTimeout and setInterval with pause.\n\n**The test coverage of this package is currently NOT GOOD, I would love to hear your feedback!! Feel free to [open an issue](https://github.com/blaumeise20/date-timeout-interval/issues/new)!**\n\n## Instalation\n\nRun `npm install --save date-timeout-interval`\n\n\n## Usage\nImport the library to your script like this:\n```ts\nconst { Timeout, Interval } = require(\"date-timeout-interval\"); // JavaScript\nimport { Timeout, Interval } from \"date-timeout-interval\"; // TypeScript\n```\nIf you want global classes, you can do the following:\n```ts\nrequire(\"date-timeout-interval/global\"); // JavaScript\nimport \"date-timeout-interval/global\"; // TypeScript\n```\nThis will add `Timeout` and `Interval` to `Date`.\n\n## Timeout Documentation\n\nThe Timeout class is basically a wrapper for the vanilla JavaScript `setTimeout` function. It has a great [API](#api-reference).\n\nThe first step is always creating the instance of `Timeout`:\n```ts\nimport { Timeout } from \"date-timeout-interval\";\n\nconst timeout = new Timeout(() =\u003e { /* executed function */ }, 1000);\n```\nIn the following scripts the import statement will be omitted, but don't forget to import it in your project!\nIf you want the timeout to start after creating it, you pass a third parameter to the constructor, set it to `true`. Something like this:\n```ts\nconst timeout = new Timeout(() =\u003e { /* executed function */ }, 1000, true);\n```\nYou can use timeout.restart as a helper function for auto complete lists. It will reset the timer to zero and start it again. The callback will fire if the user doesn't enter some text for 200 ms.\n```ts\nimport { Timeout } from \"date-timeout-interval\";\n\nconst text = document.getElementById(\"myText\");\nconst timeout = new Timeout(() =\u003e {\n    // do something...\n}, 200);\n\ntext.oninput = () =\u003e {\n    timeout.restart();\n};\n```\nThe pause method is self-explaining. In the following script the callback will fire after 5 seconds. The timeout is set to 3 seconds, but after one second has passed, the timeout will be paused for 2 seconds, then the remaining 2 seconds will still be waited, which makes a total of 5 seconds. Note the restart using `start`, not `restart` mentioned before. You can use this for message banners that will disappear after a short time, but when the user hovers over them, the countdown will be paused.\n```ts\nconst timeout = new Timeout(() =\u003e { console.log(\"Fired\") }, 3000, true);\nsetTimeout(timeout.pause, 1000);\nsetTimeout(timeout.start, 3000);\n```\nOf course there is also a `stop` method, which does nothing else than `clearTimeout` with JavaScript timeouts does. The callback will never be executed, but when using the [async](#asyncTimeout) version it will reject the timeout.\n```ts\nconst timeout = new Timeout(() =\u003e { console.log(\"Will never print :-)\") }, 3000, true);\nsetTimeout(timeout.stop, 1000);\n```\nWhen having event listeners which should only work for a little time (only an example), the `state` property is really useful. It has an enum value, representing the current state of the timeout. This example will check if the timeout is not over. Note omitting the callback, it is not necessary.\n```ts\nconst timeout = new Timeout(10000, true); // will have state TimerState.Running for 10 seconds\neventEmitter.on(\"someEvent\", () =\u003e {\n    if (timeout.state != TimerState.Running) return; // you have to import TimerState to use it here!!\n    // 10 seconds have not passed yet, do something\n});\n```\nThis also shows the usefulness of the `start` method called after the timeout is over. You could simply call the method in another event handler and make a button on a website, which when clicked, allows some other interaction on the site for 10 seconds. \u003cbr /\u003e\n\u003ca name=\"asyncTimeout\"\u003e\u003c/a\u003eAnother thing is async timeout. You can omit the callback in the timeout constructor and await the timeout somewhere else, making a very useful `sleep` function:\n```ts\nasync function yourFunction() {\n    //do something\n    console.log(\"hello\");\n    await new Timeout(3000, true);\n    console.log(\"goodbye\");\n}\n```\nWhen the timeout is stopped (canceled) before it finished, await will throw an error. If you define a global timeout, await it somewhere, and maybe stop it somewhere else, always make sure to try/catch it:\n```ts\ntry {\n    await new Timeout(3000, true);\n}\ncatch (e) { console.log(e); }\n```\n\n## Interval Documentation\n\nThere is currently no descriptional documentation for `Interval`, please take a look at the [API Reference for `Interval`](#intervalApi).\n\n\n## API Reference\n\n### `new Timeout(callback: () =\u003e void, timeMS: number, autoStart: boolean = false)`\n`callback: () =\u003e void` - Function to execute when time is over. `Timeout` instance will be applied as `this`.\u003cbr /\u003e\n`timeMS: number` - Time in milliseconds, after which the callback should fire.\n`autoStart: boolean` - If the timer should automatically start. This will call `start` internally.\n\n* `start(): this`\n\n  Starts the timer. If the timer is currently paused, it will resume the timer. If the timer is already done, it will reset it and start as normal.\n\n* `start(timeMS: number): this`\n\n  Starts the timer with the given time. **Only works, if the timer is not running or paused!**\n\n* `stop(): this`\n\n  Stops the timer and resets it to 0. Acts like `clearTimeout`.\n\n* `pause(): this`\n\n  Pauses the timer without reseting it. This is the main functionality of this class.\n\n* `restart(): this`\n\n  Restarts the timer from zero, without firing any callback. Useful for autocomplete lists.\n\n* `await timeout`\n\n  The Timeout class implements the awaitable pattern, so you can await the timeout. It will throw an error if the timeout is stopped before finishing.\n\n* `state: 0 | 1 | 2 | 3`\n\n  Defines the current state of the timer.\n  | State | Enum name | Description |\n  |:-----:| --------- | ----------- |\n  | 0     | Reset     | The timer is currently reset. This state occurs when creating the class without auto-start or after `stop` is called. |\n  | 1     | Running   | The timer is running. It can only be triggered by start, or by using auto-start while creating the class. |\n  | 2     | Paused    | The timer has been paused by calling pause. |\n  | 3     | Done      | The timer has ended and fired the callback. |\n\n* `currentTime: number`\n\n  The milliseconds the timer is currently set to. **Not the time left!**\n\n* `timeLeft: number`\n\n  This will return the time left for the timer to end. **Warning: This will call a getter which will calculate the time, don't use this too often.**\n\n### \u003ca name=\"intervalApi\"\u003e\u003c/a\u003e `new Interval(callback: () =\u003e void, timeMS: number, autoStart)`\n`callback` - Function to execute in specific intervals. `Interval` instance will be applied as `this`.\u003cbr /\u003e\n`timeMS` - Interval time in milliseconds.\n`autoStart: boolean` - If the timer should automatically start. This will call `start` internally.\n\n* `start(): this`\n\n  Starts the interval. If the interval is currently paused, it will resume the interval.\n\n* `start(timeMS: number): this`\n\n  Starts the interval with the given time. **Only works, when the interval is reset!**\n\n* `stop(): this`\n\n  Stops the interval and resets it to 0. Acts like `clearInterval`.\n\n* `pause(): this`\n\n  Pauses the interval without reseting it. This will also remember the time left to the next call, so if you resume it again, it will continue at the position it stopped.\n\n* `state: 0 | 1 | 2`\n\n  Defines the current state of the interval. These are the same as with the timeout, but there is no \"end\" state, because the interval will never end.\n  | State | Enum name | Description |\n  |:-----:| --------- | ----------- |\n  | 0     | Reset     | The interval is currently reset. This state occurs when creating the class without auto-start or after `stop` is called. |\n  | 1     | Running   | The interval is running. It can only be triggered by start, or by using auto-start while creating the class. |\n  | 2     | Paused    | The interval has been paused by calling pause. |\n  Interval doesn't have a `Done` state, because it will run until stopped (or paused).\n\n* `currentTime: number`\n\n  The milliseconds the interval is currently set to. **Not the time left until next execution!**\n\n* `timeLeft: number`\n\n  This will return the time left for the next execution to happen. **Warning: This will call a getter which will calculate the time, don't use this too often.**\n\n## enum `TimerState`\n* `TimerState.Reset`\n* `TimerState.Running`\n* `TimerState.Paused`\n* `TimerState.Done`\n\n# Licence\nThis project is licenced under the MIT licence. Read it [here](LICENCE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblaumeise20%2Fdate-timeout-interval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblaumeise20%2Fdate-timeout-interval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblaumeise20%2Fdate-timeout-interval/lists"}