{"id":13398033,"url":"https://github.com/SeverinDK/moment-timer","last_synced_at":"2025-03-14T00:32:52.584Z","repository":{"id":54283740,"uuid":"69824199","full_name":"SeverinDK/moment-timer","owner":"SeverinDK","description":"Timer plugin for Moment.js that allows creation of setInterval and setTimeout-like timers.","archived":true,"fork":false,"pushed_at":"2024-04-04T12:19:37.000Z","size":335,"stargazers_count":110,"open_issues_count":3,"forks_count":33,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-18T23:20:06.055Z","etag":null,"topics":["duration","interval","javascript-timer","moment","moment-timer","setinterval","settimeout","timeout","timer"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/SeverinDK.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-02T21:51:35.000Z","updated_at":"2024-10-18T13:59:22.000Z","dependencies_parsed_at":"2024-06-18T15:37:28.307Z","dependency_job_id":"a8630640-796d-4c1f-a0b6-3fee9653a9cb","html_url":"https://github.com/SeverinDK/moment-timer","commit_stats":{"total_commits":63,"total_committers":10,"mean_commits":6.3,"dds":0.2698412698412699,"last_synced_commit":"79bfe3b9e3f043a257823093875a5e30dabbabf4"},"previous_names":["severindk/moment-timers"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeverinDK%2Fmoment-timer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeverinDK%2Fmoment-timer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeverinDK%2Fmoment-timer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeverinDK%2Fmoment-timer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SeverinDK","download_url":"https://codeload.github.com/SeverinDK/moment-timer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243505165,"owners_count":20301565,"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","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":["duration","interval","javascript-timer","moment","moment-timer","setinterval","settimeout","timeout","timer"],"created_at":"2024-07-30T18:02:02.976Z","updated_at":"2025-03-14T00:32:52.034Z","avatar_url":"https://github.com/SeverinDK.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# moment-timer\n\n[![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![MIT License][license-image]][license-url]\n\n---\n\n## No Longer Maintained\n\nAs of 2024-04-04, this project, a plugin for moment.js, is no longer being actively maintained. The moment.js library itself has also ceased active maintenance. We strongly recommend users begin migrating to more actively supported libraries for future projects and maintenance needs.\n\nIf you're currently using this plugin, here's what you need to know:\n\n* No New Features or Bug Fixes: The project will not receive updates, new features, or bug fixes.\n* Read-Only: The repository has been archived, making it read-only. You can still fork it, but contributions, issues, and pull requests will not be accepted.\n\nThank you to all the contributors, users, and supporters who made this project possible over the years. Your support and contributions were invaluable, and we hope the project served your needs well during its time of activity.\n\n---\n\n## Synopsis\nThis is a Moment.js plugin that allows the use of timers, which offer much more control than the native JavaScript timers. It's basically a rewrite of JavaScripts own setInterval and setTimeout. For an example, see the example folder or read the Usage section below.\n\n---\n\n## Installation\n\n### Npm\n```\nnpm install moment-timer\n```\n\n### Bower\n```\nbower install moment-timer\n```\n\n### CDN\n```\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/moment-timer/lib/moment-timer.js\"\u003e\u003c/script\u003e\n```\n\n### Browser\n```\n\u003cscript src=\"path/to/moment-timer.js\"\u003e\u003c/script\u003e\n```\nWhen using this plugin in the browser, be sure to include moment.js on your page first.\n\n---\n\n## Attributes\n\n### (bool) start\n```js\nnew moment.duration(1000).timer({ start: true }, callback);\n```\nSetting this attribute to true will cause the timer to start once instantiated.\n\n---\n\n### (bool) loop\n```js\nnew moment.duration(1000).timer({ loop: true }, callback);\n```\nSetting this attribute to true will cause the timer to loop/restart once a duration is complete.\n\n---\n\n### (int | moment.duration) wait\n```js\nnew moment.duration(1000).timer({ wait: 5000 }, callback);\n```\n```js\nnew moment.duration(1000).timer({ wait: moment.duration(5, 'seconds') }, callback);\n```\nSetting this attribute will cause the timer to wait for a specified amount of time before starting it's duration. This is kind of an extra first duration. Imagine a timer that runs every second. Setting the wait attribute to 5000 / 5 seconds, means it waits that long and then starts acting like a normal timer would. Notice that this attribute accepts both int and moment.duration .\n\n---\n\n### (bool) executeAfterWait\n```js\nnew moment.duration(1000).timer({ wait: 5000, executeAfterWait: true }, callback);\n```\nSetting this attribute to true will cause the callback function to be called after the wait duration has ended. This is a way to make sure the callback is executed even before the timer starts.\n\n---\n\n## Functions\n### .start()\n```js\nlet timer = new moment.duration(1000).timer(callback);\ntimer.start();\n```\nThis function will cause the timer to start. It can be used if the start attribute has not been set or if the timer has been stopped.\n\n---\n\n### .stop()\n```js\nlet timer = new moment.duration(1000).timer({ start: true }, callback);\ntimer.stop();\n```\nThis function will cause the timer to stop. It can be used if timer has been started to halt it.\n\n---\n\n### .duration(int | moment.duration)\n```js\nlet timer = new moment.duration(1000).timer(callback);\ntimer.duration(5000);\ntimer.duration(moment.duration(5, \"seconds\");\n```\nThis function can be used to change the duration the timer was instantiated with.\n\n---\n\n### .getDuration()\n```js\nlet timer = new moment.duration(1000).timer(callback);\ntimer.getDuration();\n```\nThis function will return the current duration of a timer. In this case it will return 1000.\n\n---\n\n### .getRemainingDuration()\n```js\nlet timer = new moment.duration(1000).timer(callback);\ntimer.getRemainingDuration();\n```\nThis function will return the remaining duration of a timers cycle. In this case, imagine that the timer has been running for 500ms and we call .getRemainingDuration() on it, in this example it will return 500, since half of the cycle has completed.\n\n---\n\n### .isStopped()\n\n```js\nlet timer = new moment.duration(1000).timer(callback);\ntimer.start();\ntimer.isStopped();  // false\ntimer.stop();\ntimer.isStopped();  // true\n```\nThis function can be used to see if the timer has been stopped by the .stop() function.\n\n---\n\n### .isStarted()\n\n```js\nlet timer = new moment.duration(1000).timer(callback);\ntimer.start();\ntimer.isStarted();  // true\ntimer.stop();\ntimer.isStarted();  // false\n```\nThis function can be used to see if the timer has been started by the .start() function. If this function is called on a timer that has reached the end of it's duration and does not loop, it will also return false as if the timer has not yet been started.\n\n---\n\nFeel free to [open a new issue](https://github.com/SeverinDK/moment-timer/issues/new) or [create a pull request](https://github.com/SeverinDK/moment-timer/pulls) if you can think of other useful attributes or functions.\n\n---\n\n## Changelog\n#### v1.3.1\nAdded nodejs example and increased minimum version of moment. See https://github.com/SeverinDK/moment-timer/issues/26\n#### v1.3.0\nFixed issue where .stop() would not stop the timer. See https://github.com/SeverinDK/moment-timer/issues/20\n#### v1.2.3\n[Relaxed moment dependency.](https://github.com/SeverinDK/moment-timer/pull/13)\n#### v1.2.2\nRemoved debug console.log\n#### v1.2.1\nUpdated readme with better documentation and added a new isStarted function.\n#### v1.2.0\nAdded module loading!\n#### v1.1.5\nAdded getDuration and executeAfterWait attribute.\n#### v1.1.4\nAdded isStopped function.\n#### v1.1.3:\n...\n#### v1.1.2:\nFixed stop function. It still had an old unused paused variable instead of the new stopped variable. Fixing this will ensure that stopping and starting the timer will not cause any problems.\n#### v1.1.1:\nCleaned up some things, fixed a remainingDuration bug and added an internal clearTimer function.\n#### v1.1.0:\nChanged setDuration to duration and added actual moment.duration support to it.\nDeprecated error message on setDuration will be removed in next release.\n#### v1.0.0:\nInitial Release.\n\n---\n\n## Contributing\n\nYou are always welcome to contribute to this repository. Create your own branch, make the changes you wish to see and create a pull request that we can have a look at. If the changes make sense and the quality of code is good enough, then it will be merged into the master branch so other people can use it.\n\nA full list of contributers for moment-timer.js can be found [here.](https://github.com/SeverinDK/moment-timer/graphs/contributors)\n\n---\n\n## License\n\nMoment-timer.js is freely distributable under the terms of the [MIT license](https://github.com/SeverinDK/moment-timer/blob/master/LICENSE).\n\n---\n\n[npm-url]: https://npmjs.org/package/moment-timer\n[npm-version-image]: http://img.shields.io/npm/v/moment-timer.svg?style=flat\n[npm-downloads-image]: http://img.shields.io/npm/dm/moment-timer.svg?style=flat\n[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat\n[license-url]: LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSeverinDK%2Fmoment-timer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSeverinDK%2Fmoment-timer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSeverinDK%2Fmoment-timer/lists"}