
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
self-timer
Advanced tools
The self-timer.js is a light-weight callback runner library for javascript .
The name of self-timer.js is originated from 'self-timer', which is a device on a camera. You may run your callback at the timing when you want to execute as if self-timer .
For instance, run some function if today is weekdays ( Monday to Friday ), self-timer.js is able to write simplify .
var st = new SelfTimer(new Date());
st.on()
.Weekdays(function() {
// callback
console.log("this method run on Monday to Friday!");
});
If you using server-side template ( exp: nunjucks, EJS.. and so. ). You can easy to switch template seasonally with self-timer.js.
{% if st.in().MonthSelects([3, 4, 5]) %}
<!-- spring -->
<link rel="stylesheet" type="text/css" href="spring.css">
{% elif st.in().MonthSelects([6, 7, 8]) %}
<!-- summer -->
<link rel="stylesheet" type="text/css" href="summer.css">
...
{% endif %}
Another one, output 'hello world' at 9 am to 5 pm, on Monday and Friday, between November to December. 2016.
var st = new SelfTimer(new Date());
// Between Nov to Dec in 2016
st.in(true)
.Year(2016)
.MonthsSelects([11, 12], function() {
// Monday and Friday
st.on()
.Selects(['Mon', 'Fri'], function() {
// Between 9 am to 17 pm
st.at()
.HoursBetween(9, 17, function() {
// callback
console.log("hello world!");
}); // ! at().HoursBetween()
}); // ! on().Selects()
}); // ! in().Year.MonthsBetween()
Using npm:
npm install self-timer --save
Using yarn:
yarn add self-timer
Using CDN:
<!-- callback -->
<script src="https://unpkg.com/self-timer/dist/selftimer.min.js"></script>
<!-- promise -->
<script src="https://unpkg.com/self-timer/dist/selftimer-promise.min.js"></script>
<!-- promise but including polyfill -->
<script src="https://unpkg.com/self-timer/dist/selftimer-promise-polyfill.min.js"></script>
.on( )
.at( )
.in( )
( supported methods-chaining on selftimer.js )
.is()
.timer()
self-timer.js have 2 types and 3 diffrents of files. You may choose them in right scene.
Note: selftimer-promise-polyfill is including taylorhakes/promise-polyfill. very thanks!
Web-Browser
<!-- callback -->
<script src="./self-timer/dist/selftimer.min.js"></script>
<script>
var st = new SelfTimer(new Date());
// run on Weekend ( * Saturday and Sunday )
st.on()
.Weekend(function(){
alert("it's Weekend.");
});
</script>
ES6 style & CommonJS
/* callback */
import SelfTimer from 'self-timer';
/* CommonJS */
// const SelfTimer = require('self-timer');
const st = new SelfTimer(new Date());
st.on()
.Sunday(() => {
console.log('run on Sunday!');
});
Web-Browser
<!-- Promise ( Browser ) -->
<script src="./self-timer/dist/selftimer-promise-polyfill.min.js"></script>
<!-- <script src="./self-timer/dist/selftimer-promise.min.js"></script> -->
<script>
var st = new SelfTimer(new Date());
// run on Weekend ( * Saturday and Sunday )
st.on()
.Weekend()
.then(function() {
alert("it's Weekend.");
});
// use 'catch' method
st.on(true)
.Weekend()
.then(function() {
alert("it's weekend.")
})
.catch(function(){
alert("it's not weekend!")
});
</script>
ES6 && CommonJS
/* Promise ( Babel OR Webpack ) */
import SelfTimer from 'self-timer/dist/selftimer-promise-polyfill.min';
/* CommonJS */
// const SelfTimer = require('self-timer/dist/selftimer-promise.min');
// if you use babel-polyfill
// import SelfTimer from 'self-timer/dist/selftimer-promise.min';
const st = new SelfTimer(new Date());
st.on()
.Sunday()
.then(() => {
console.log('run on Sunday!');
});
// use 'catch' method
st.on(true)
.Sunday()
.then(() => {
console.log("run on Sunday!");
})
.catch(() => {
console.log("run on if not Sunday!");
})
MIT
version 1.5.2 [ 2017/06/12 ]
fixed is.Mobile
method
FAQs
light-weight callback runner.
The npm package self-timer receives a total of 88 weekly downloads. As such, self-timer popularity was classified as not popular.
We found that self-timer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.