npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

self-timer

v1.6.2

Published

light-weight callback runner.

Downloads

632

Readme

self-timer.js

logo

Overview

The self-timer.js is a light-weight callback runner library for javascript .

Documentation

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()

Installing

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>

Available Methods

.on( )

  • Sunday(), Monday(), Tuesday(), Wednesday(), Thursday(), Friday() Saturday()
  • Weekday(), Weekend(), Selects()
  • Annual(), DatesBetween(), DatesContain()

.at( )

  • Between(), Unless()
  • Min(), MinBetween(), MinSelects()
  • Hour(), HoursBetween(), HourSelects()

.in( )

( supported methods-chaining on selftimer.js )

  • Day(), Days(), DaysBetween()
  • Month(), MonthsBetween()
  • Year()

.is()

  • True(), False()
  • Language(), Lang()
  • LanguageSelects(), LangSelects()
  • LanguageExcepts(), LangExcepts()
  • Mobile

.timer()

  • After()

.check() (* only available for callback )

  • With()
  • Done()

Basic Usage

self-timer.js have 2 types and 3 diffrents of files. You may choose them in right scene.

  • callback style [ selftimer.js ( .min.js ) ]
  • promise style [ selftimer-promise.js ( .min.js ) ]
  • promise style with Polyfill [ selftimer-promise-polyfill.js ( .min.js ) ]

Note: selftimer-promise-polyfill is including taylorhakes/promise-polyfill. very thanks!

Callback

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!');
  });

Promise

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!");
    })

License

MIT