sst.js
Simple Set(Timeout || Interval) for Javascript.
sst.js
is very easy to write setTimeout
and setInterval
process for Javascript.
sst(1, "min").once(function() {
});
setTimeout(function(){
}, 60000);
sst(2, "s")
.immediate(() => {
console.log("run, immediately");
})
.once(() => {
console.log("just a time");
})
.times(4, () => {
console.log("run, 4 times");
})
.repeat(() => {
console.log("run, per 2 seconds");
});
Working with Browser and Node.js
Installation
npm install sstjs --save
yarn add sstjs
import sst.js
const sst = require('sstjs')
import sst from 'sstjs';
<script src="https://unpkg.com/sstjs/dist/sst.min.js"></script>
<script src="dist/sst.min.js"></script>
Methods
constructor(num, unit)
The constructor, you can set a time with human readable.
sst(200, 'ms')
sst(2, "sec")
sst(2, "min")
.once(callback)
The .once
method is equivalent to setTimeout
.
sst(2, "sec")
.once(function() {
});
.times(num, callback)
The .times
method is equivalent to setTimeout
. but iterate callback with NUM times, you defined.
sst(2, "sec")
.times(4, function () {
});
.after(beforeCallback, afterCallback)
The .after
method is equivalent to setTimeout
. but run afterCallback (**second arguments**)
after exexuted beforeCallback (first argument)
.
sst(2, "sec")
.after(
function() {
},
function() {
}
);
.repeat(callback)
The .repeat
method is equivalent to setInterval
.
sst(2, "sec")
.repeat(function () {
});
.immediate(callback)
The .immediate
method is immediate function.
sst(2, "sec")
.immediate(function () {
})
.repeat(function () {
});
LICENCE
MIT