The JavaScript blog.


libraries modules timers api

Parrot, Flush Timeouts

Posted on .


Parrot (GitHub: sailorjs/parrotjs, License: MIT, Bower: parrotjs) by Kiko Beats is a library for wrapping API calls to your server. You can register different environments, which makes it easy to switch between development and production. You can also register URLs with different protocols, so it's possible to make WebSocket or Ajax requests.

It has a fluent API, so you can chain calls. If you wanted to register your production and development servers, then you'd call endpoint.add:

  .add(name: 'development', url: 'http://localhost:3000')
  .add(name: 'production', url: 'http://example.com')

Specific API URLs can be added as well:

  .add(name: 'signup', path: 'user', method: 'post')
  .add(name: 'login', path: 'user/login', method: 'post');

Making an Ajax request to the signup route would just be parrot.ajax('signup', function(err, res) {.

This seems preferable to some client-side HTTP APIs. The author intended it to be used with Sails.js, but you could use it with other frameworks as well.


I've noticed a few libraries recently that aim to improve the JavaScript timer API. Alex Lawrence sent in flush-timeout (GitHub: efacilitation/flush-timeouts, License: MIT, Bower: flush-timeouts, npm: flush-timeouts), a module for overriding setTimeout.

Here's a quick example:


var i = 0;

function demo() {  
  console.log('i:', i);

setTimeout(demo, 500);  
setTimeout(demo, 1000);  
setTimeout(demo, 1500);



This will cause demo to immediately run three times, and then print Done. If you removed global.flushTimeouts then it would execute based on the delays passed to setTimeout.

flush-timeouts might be useful when you're trying to queue up tasks with setTimeout but have additional logic that determines if it's safe to run all the tasks at once. Or perhaps you've got tests for code that depends on setTimeout and don't want to wait. The author has supplied tests and build scripts so you can pick it apart to see how it works.


jquery forms timers date-pickers

jQuery Roundup: pickadate.js, jQuery Interdependencies, Timer.js

Posted on .

Note: You can send your plugins and articles in for review through our contact form or @dailyjs.



pickadate.js (GitHub: amsul / pickadate.js, License: MIT) by Amsul is a date picker that works with type="date" or regular text fields, supports various types of date formatting options, and is easy to theme.

The pickadate.js documentation explains how to use and configure the plugin. Basic usage is just $('.datepicker').datepicker(), given a suitable form field.

jQuery Interdependencies

jQuery Interdependencies (GitHub: miohtama / jquery-interdependencies, License: MIT) by Mikko Ohtamaa is a plugin for expressing relationships between form fields. Rule sets can be created that relate the value of a field to the presence of another field. The simplest example of this would be selecting "Other", and then filling out a value in a text field.

It works with all standard HTML inputs, and can handle nested decision trees. There's also some detailed documentation, jQuery Interdependencies documentation and an introductory blog post that covers the basics.


Florian Schäfer sent in his forked version of jQuery Chrono, Timer.js. It's a periodic timer API for browsers and Node, with some convenience methods and time string expression parsing:

timer.every('2 seconds', function () {});  
timer.after('5 seconds', function () {});  

He also sent in Lambda.js which is a spin-off from Oliver Steele's functional-javascript library. String expressions are used to concisely represent small functions, or lambdas:

lambda('x -> x + 1')(1); // => 2  
lambda('x y -> x + 2*y')(1, 2); // => 5  
lambda('x, y -> x + 2*y')(1, 2); // => 5  


jquery jqueryui cookies timers

jQuery Roundup: cookieConsent, Timing, Tagit

Posted on .

Note: You can send your plugins and articles in for review through our contact form or @dailyjs.


The EU doesn't understand cookies

jquery.cookieConsent (License: MIT) by Tom Ashworth is a drop-in plugin for satisfying new EU policies regarding cookies. By running $.cookieConsent(), this plugin will display a banner. Once the banner is clicked, a cookie called cookieConsent will be set so the banner won't need to annoy the visitor again.

The irony of setting a cookie to hide a message informing users about the use of cookies is amusing, but that's not Tom's fault so much as the nature of the beast.


Timing (GitHub: creativecouple / jquery-timing, License: MIT) by Peter Liske is a wrapper around setTimeout and other timer functions. It has a chainable API, so it's easy to create complex scenarios without too much code:



Tagit (GitHub: hailwood / jQuery-Tagit, License: CC BY-SA 3.0) by Matthew Hailwood uses jQuery UI's Autocomplete to present an alternative way of entering lists. Features include:

  • Automatically adding partially typed tags if the control loses focus
  • Friendly behaviour when deleting tags
  • Sortable items using drag and drop

The sortable version only requires a single option to work:

$(selector).tagit({ tagSource: ['one', 'two', 'three'], sortable: 'handle' });

It's quite easy to theme this plugin, and the author has kindly bundled quite a few CSS files.