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

fcronjs

v2.0.1

Published

Package for manage function call timetable

Downloads

3

Readme

fcronjs

Package for manage function call timetable.

WARNING:

Since version 2.0.1 the contract for debounce and throttle methods has been changed. New contract is compatible for old throttle's contract but incompatible for debounce's contract in previous versions.

Content

GitHub.

Progect on GitHub.

Install.

npm install fcronjs --save

Usage.

Import fcronjs form package:

  import fcronjs from 'fcronjs';

or add script fcron.js from web/fcron.js in branch master and add itinto your HTML:

  <script src="./fcron.js"></script>

and use:

debounce

  import { debounce } from 'fcronjs';

or

  var debounce = fcronjs.debounce;

Method debounce creates Hi Ordered Function which sets minimal period between calls. It has two arguments:

  • {Function} func - original function.

  • {Object|number} [secondArgument] - in case Object - configurin object, in other case - [config#delay = 100].

    Configuring object has 3 parameters:

    • {number} [config#delay = 100] - minimal number of milliseconds to be waited between calls.
    • {boolean} [config#immediate = false] - when immediate = true function calls immediatly if it is possible, in other case it cals after delay ms.
    • {Object} [config#context] - context object of function. If context was set it can not be changed or removed.

For examlpe:

  import { debounce } from 'fcronjs';

  const f = debounce(console.log, {delay: 1000, immediate: false, context: console});

  const timeouts = [0, 10, 100, 1000, 1010, 2000, 3000, 3500, 3550, 4200];

  timeouts.forEach(x => setTimeout(f, x, x));

In output very likely will be 0, 1010, 3000, and 4200. And 10, 100, 1000, 2000, 3500 likely to be ignored.

throttle

  import { throttle } from 'fcronjs';

or

  var throttle = fcronjs.throttle;

Method throttle creates Hi Ordered Function which sets minimal period between calls and execute last call every time at the end.

  • {Function} func - original function.

  • {Object|number} [secondArgument] - in case Object - configurin object, in other case - [config#delay = 100].

    Configuring object has 3 parameters:

    • {number} [config#delay = 100] - minimal number of milliseconds to be waited between calls.
    • {boolean} [config#immediate = false] - when immediate = true function calls immediatly if it is possible, in other case it cals after delay ms.

For examlpe:

  import { throttle } from 'fcronjs';

  const f = throttle(console.log, 1000);

  const timeouts = [0, 10, 100, 1000, 1010, 2000, 3000, 3500, 3550, 10000, 10001];

  timeouts.forEach(x => setTimeout(f, x, x));

In output very likely will be 0, 1000, 1010 (as a last), 2000, 3000, and 3550 (as a last), 10000, and 10001 (as a last). And 10, 100, 3500 likely to be ignored.

waiter

  import { waiter } from 'fcronjs';

or

  var waiter = fcronjs.waiter;

Method waiter creates Hi Ordered Function which at call waits some time befor call original function, and in case of second call before function called, it stops waiting without calling function.

  • {Function} func - original function.
  • {number} [delay = 100] - number of milliseconds must be waited before original function call.

For examlpe:

  import { waiter } from 'fcronjs';

  const DELAY = 1000;
  const f = waiter(console.log, DELAY);

  f('Executing function must be called'); // will be executed after 1 second

  setTimeout(() => {
    f('Executing function must be ignored'); // Will never be executed

    setTimeout(() => {
      f(); // Canceling call after 500 ms.
    }, DELAY / 2);
  }, 5 * DELAY);

Support.

Supported browsers IE9+.

License

MIT Copyright (c) 2017 Kuznetsov Leonid.