https://github.com/shystruk/setintervaljs
⏰ start and clear interval without setting a variable, clear interval anywhere you want
https://github.com/shystruk/setintervaljs
clearinterval interval javascript setinterval
Last synced: 29 days ago
JSON representation
⏰ start and clear interval without setting a variable, clear interval anywhere you want
- Host: GitHub
- URL: https://github.com/shystruk/setintervaljs
- Owner: shystruk
- License: mit
- Created: 2017-11-29T14:51:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T14:32:24.000Z (about 2 years ago)
- Last Synced: 2025-04-21T05:43:32.298Z (about 1 month ago)
- Topics: clearinterval, interval, javascript, setinterval
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/set-interval
- Size: 738 KB
- Stars: 33
- Watchers: 2
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# SetIntervalJS [](https://twitter.com/intent/tweet?hashtags=javascript&original_referer=https%3A%2F%2Fpublish.twitter.com%2F&ref_src=twsrc%5Etfw&text=No%20more%20variable%20needed%20for%20clearInterval()%20%F0%9F%91%8C%F0%9F%98%80&tw_p=tweetbutton&url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Fset-interval&via=shystrukk) #
[](https://opensource.org/licenses/mit-license.php) [](https://travis-ci.org/shystruk/SetIntervalJS) [](https://badge.fury.io/js/set-interval) [](https://snyk.io/test/github/shystruk/SetIntervalJS?targetFile=package.json)SetIntervalJS is a constructor which hide inside reference to setInterval() for cleaner usage. It helps to make your code cleaner and there is no need to have more variables for clearInterval() and you can clear interval anywhere you want👌.
## Getting SetIntervalJS ##
#### npm
`npm install --save set-interval`#### yarn
`yarn add set-interval --save`## Examples ##
```javascript
SetInterval.start(function, milliseconds, key_string)
```### Basic example ###
```javascript
import SetInterval from 'set-interval'SetInterval.start(callback, 1000, 'test')
SetInterval.clear('test')
```### Multiple instances ###
```javascript
// -> ./start.js
import SetInterval from 'set-interval'SetInterval.start(callback, 1000, 'test')
SetInterval.start(callback_2, 1000, 'test_2')
SetInterval.start(callback_3, 1000, 'test_3')// -> ./clear.js
import SetInterval from 'set-interval'SetInterval.clear('test')
SetInterval.clear('test_2')
SetInterval.clear('test_3')
```## API ##
### SetInterval.start(callback, milliseconds, key_string) ####### callback ####
Type: `function`
Function that gets called in each milliseconds interval#### milliseconds ####
Type: `number`
Interval time in which callback function gets called#### key_string ####
Type: `string`
Key name for which interval will be referenced### SetInterval.clear(key_string) ###
#### key_string ####
Type: `string`
Key name which was passed to .start method## Contributing
Any contributions you make **are greatly appreciated**.
Please read the [Contributions Guidelines](CONTRIBUTING.md) before submitting a PR.
## License
MIT © [Vasyl Stokolosa](https://about.me/shystruk)